diff --git a/conftest.py b/conftest.py index 8be7a51..8f0aae3 100644 --- a/conftest.py +++ b/conftest.py @@ -6,14 +6,16 @@ import pytest from random import randint +from nsupdate.main.dnstools import FQDN + 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%da.%s' % (randint(1, 1000000), TESTDOMAIN) # unit tests can update this host ONLY +TEST_HOST = FQDN('test%da' % randint(1, 1000000), TESTDOMAIN) # unit tests can update this host ONLY TEST_SECRET = "secret" -TEST_HOST2 = 'test%db.%s' % (randint(1, 1000000), TESTDOMAIN) +TEST_HOST2 = FQDN('test%db' % randint(1, 1000000), TESTDOMAIN) TEST_SECRET2 = "somethingelse" NAMESERVER_IP = "85.10.192.104" NAMESERVER_UPDATE_ALGORITHM = "HMAC_SHA512" @@ -86,10 +88,10 @@ 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 - hostname = TEST_HOST.split('.', 1)[0] + hostname = TEST_HOST.host h = Host(name=hostname, domain=dt, created_by=u) h.generate_secret(secret=TEST_SECRET) - hostname2 = TEST_HOST2.split('.', 1)[0] + hostname2 = TEST_HOST2.host h2 = Host(name=hostname2, domain=dt, created_by=u2) h2.generate_secret(secret=TEST_SECRET2) diff --git a/nsupdate/api/_tests/test_api.py b/nsupdate/api/_tests/test_api.py index 8d908da..4fed75c 100644 --- a/nsupdate/api/_tests/test_api.py +++ b/nsupdate/api/_tests/test_api.py @@ -9,7 +9,7 @@ from django.core.urlresolvers import reverse from nsupdate.main.dnstools import query_ns, FQDN from nsupdate.main.models import Domain -from conftest import TESTDOMAIN, TEST_HOST, TEST_HOST2, TEST_SECRET, TEST_SECRET2 +from conftest import TESTDOMAIN, TEST_HOST, TEST_HOST_RELATED, TEST_HOST2, TEST_SECRET, TEST_SECRET2 USERNAME = 'test' PASSWORD = 'pass' diff --git a/nsupdate/management/commands/_tests/test_faults.py b/nsupdate/management/commands/_tests/test_faults.py index cc2c3df..f62dce8 100644 --- a/nsupdate/management/commands/_tests/test_faults.py +++ b/nsupdate/management/commands/_tests/test_faults.py @@ -11,7 +11,7 @@ from nsupdate.main.models import Host def test_faults_reset(): # trigger execution of all code for coverage, test resetting # set flags and counters - hostname = TEST_HOST.split('.', 1)[0] + hostname = TEST_HOST.host h = Host.objects.get(name=hostname) h.client_faults = 1 h.server_faults = 1 @@ -35,7 +35,7 @@ def test_faults_reset(): def test_faults_no_abuse(): - hostname = TEST_HOST.split('.', 1)[0] + hostname = TEST_HOST.host h = Host.objects.get(name=hostname) h.client_faults = 10 # below threshold h.abuse = False @@ -49,7 +49,7 @@ def test_faults_no_abuse(): def test_faults_abuse(): - hostname = TEST_HOST.split('.', 1)[0] + hostname = TEST_HOST.host h = Host.objects.get(name=hostname) h.client_faults = 42 # above threshold h.abuse = False