make api tests also use a random hostname (but constant throughout the test session)
This commit is contained in:
parent
852e541778
commit
0203fdb856
13
conftest.py
13
conftest.py
@ -4,14 +4,16 @@ configuration for the (py.test based) tests
|
||||
|
||||
import pytest
|
||||
|
||||
from random import randint
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
# this is to create a Domain entries in the database, so they can be used for unit tests:
|
||||
BASEDOMAIN = "nsupdate.info"
|
||||
TESTDOMAIN = "tests." + BASEDOMAIN
|
||||
TEST_HOST = 'test.' + TESTDOMAIN # unit tests can update this host ONLY
|
||||
TEST_HOST = 'test%da.%s' % (randint(1, 1000000), TESTDOMAIN) # unit tests can update this host ONLY
|
||||
TEST_SECRET = "secret"
|
||||
TEST_HOST2 = 'test2.' + TESTDOMAIN
|
||||
TEST_HOST2 = 'test%db.%s' % (randint(1, 1000000), TESTDOMAIN)
|
||||
TEST_SECRET2 = "somethingelse"
|
||||
NAMESERVER_IP = "85.10.192.104"
|
||||
NAMESERVER_UPDATE_ALGORITHM = "HMAC_SHA512"
|
||||
@ -30,7 +32,6 @@ SECURE = False # SSL/SNI support on python 2.x sucks :(
|
||||
|
||||
from django.utils.translation import activate
|
||||
|
||||
from random import randint
|
||||
from nsupdate.main.dnstools import update_ns
|
||||
|
||||
|
||||
@ -84,9 +85,11 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
||||
created_by=u2,
|
||||
)
|
||||
# a Host for api / session update tests
|
||||
h = Host(subdomain='test', domain=dt, created_by=u)
|
||||
hostname = TEST_HOST.split('.', 1)[0]
|
||||
h = Host(subdomain=hostname, domain=dt, created_by=u)
|
||||
h.generate_secret(secret=TEST_SECRET)
|
||||
h2 = Host(subdomain='test2', domain=dt, created_by=u2)
|
||||
hostname2 = TEST_HOST2.split('.', 1)[0]
|
||||
h2 = Host(subdomain=hostname2, domain=dt, created_by=u2)
|
||||
h2.generate_secret(secret=TEST_SECRET2)
|
||||
|
||||
# "update other service" ddns_client feature
|
||||
|
@ -7,11 +7,7 @@ from django.core.urlresolvers import reverse
|
||||
from nsupdate.main.dnstools import query_ns
|
||||
from nsupdate.main.models import Domain
|
||||
|
||||
|
||||
TESTDOMAIN = "tests.nsupdate.info"
|
||||
TEST_HOST = "test." + TESTDOMAIN
|
||||
TEST_HOST2 = "test2." + TESTDOMAIN
|
||||
TEST_SECRET = "secret"
|
||||
from conftest import TESTDOMAIN, TEST_HOST, TEST_HOST2, TEST_SECRET, TEST_SECRET2
|
||||
|
||||
USERNAME = 'test'
|
||||
PASSWORD = 'pass'
|
||||
|
@ -2,6 +2,8 @@
|
||||
Tests for faults command.
|
||||
"""
|
||||
|
||||
from conftest import TEST_HOST
|
||||
|
||||
from django.core import management
|
||||
from nsupdate.main.models import Host
|
||||
|
||||
@ -9,7 +11,8 @@ from nsupdate.main.models import Host
|
||||
def test_faults_reset():
|
||||
# trigger execution of all code for coverage, test resetting
|
||||
# set flags and counters
|
||||
h = Host.objects.get(subdomain='test')
|
||||
hostname = TEST_HOST.split('.', 1)[0]
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
h.client_faults = 1
|
||||
h.server_faults = 1
|
||||
h.available = False
|
||||
@ -23,7 +26,7 @@ def test_faults_reset():
|
||||
reset_abuse=True, reset_abuse_blocked=True,
|
||||
reset_available=True)
|
||||
# check if the resetting worked
|
||||
h = Host.objects.get(subdomain='test')
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
assert h.client_faults == 0
|
||||
assert h.server_faults == 0
|
||||
assert h.available is True
|
||||
@ -32,26 +35,28 @@ def test_faults_reset():
|
||||
|
||||
|
||||
def test_faults_no_abuse():
|
||||
h = Host.objects.get(subdomain='test')
|
||||
hostname = TEST_HOST.split('.', 1)[0]
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
h.client_faults = 10 # below threshold
|
||||
h.abuse = False
|
||||
h.save()
|
||||
# flag abusive hosts
|
||||
management.call_command('faults', flag_abuse=23)
|
||||
# check if it did not get flagged
|
||||
h = Host.objects.get(subdomain='test')
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
assert h.client_faults == 10
|
||||
assert h.abuse is False
|
||||
|
||||
|
||||
def test_faults_abuse():
|
||||
h = Host.objects.get(subdomain='test')
|
||||
hostname = TEST_HOST.split('.', 1)[0]
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
h.client_faults = 42 # above threshold
|
||||
h.abuse = False
|
||||
h.save()
|
||||
# flag abusive hosts
|
||||
management.call_command('faults', flag_abuse=23)
|
||||
# check if it did get flagged
|
||||
h = Host.objects.get(subdomain='test')
|
||||
h = Host.objects.get(subdomain=hostname)
|
||||
assert h.client_faults == 0
|
||||
assert h.abuse is True
|
||||
|
Loading…
x
Reference in New Issue
Block a user