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
|
import pytest
|
||||||
|
|
||||||
|
from random import randint
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
# this is to create a Domain entries in the database, so they can be used for unit tests:
|
# this is to create a Domain entries in the database, so they can be used for unit tests:
|
||||||
BASEDOMAIN = "nsupdate.info"
|
BASEDOMAIN = "nsupdate.info"
|
||||||
TESTDOMAIN = "tests." + BASEDOMAIN
|
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_SECRET = "secret"
|
||||||
TEST_HOST2 = 'test2.' + TESTDOMAIN
|
TEST_HOST2 = 'test%db.%s' % (randint(1, 1000000), TESTDOMAIN)
|
||||||
TEST_SECRET2 = "somethingelse"
|
TEST_SECRET2 = "somethingelse"
|
||||||
NAMESERVER_IP = "85.10.192.104"
|
NAMESERVER_IP = "85.10.192.104"
|
||||||
NAMESERVER_UPDATE_ALGORITHM = "HMAC_SHA512"
|
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 django.utils.translation import activate
|
||||||
|
|
||||||
from random import randint
|
|
||||||
from nsupdate.main.dnstools import update_ns
|
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,
|
created_by=u2,
|
||||||
)
|
)
|
||||||
# a Host for api / session update tests
|
# 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)
|
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)
|
h2.generate_secret(secret=TEST_SECRET2)
|
||||||
|
|
||||||
# "update other service" ddns_client feature
|
# "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.dnstools import query_ns
|
||||||
from nsupdate.main.models import Domain
|
from nsupdate.main.models import Domain
|
||||||
|
|
||||||
|
from conftest import TESTDOMAIN, TEST_HOST, TEST_HOST2, TEST_SECRET, TEST_SECRET2
|
||||||
TESTDOMAIN = "tests.nsupdate.info"
|
|
||||||
TEST_HOST = "test." + TESTDOMAIN
|
|
||||||
TEST_HOST2 = "test2." + TESTDOMAIN
|
|
||||||
TEST_SECRET = "secret"
|
|
||||||
|
|
||||||
USERNAME = 'test'
|
USERNAME = 'test'
|
||||||
PASSWORD = 'pass'
|
PASSWORD = 'pass'
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
Tests for faults command.
|
Tests for faults command.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from conftest import TEST_HOST
|
||||||
|
|
||||||
from django.core import management
|
from django.core import management
|
||||||
from nsupdate.main.models import Host
|
from nsupdate.main.models import Host
|
||||||
|
|
||||||
@ -9,7 +11,8 @@ from nsupdate.main.models import Host
|
|||||||
def test_faults_reset():
|
def test_faults_reset():
|
||||||
# trigger execution of all code for coverage, test resetting
|
# trigger execution of all code for coverage, test resetting
|
||||||
# set flags and counters
|
# 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.client_faults = 1
|
||||||
h.server_faults = 1
|
h.server_faults = 1
|
||||||
h.available = False
|
h.available = False
|
||||||
@ -23,7 +26,7 @@ def test_faults_reset():
|
|||||||
reset_abuse=True, reset_abuse_blocked=True,
|
reset_abuse=True, reset_abuse_blocked=True,
|
||||||
reset_available=True)
|
reset_available=True)
|
||||||
# check if the resetting worked
|
# check if the resetting worked
|
||||||
h = Host.objects.get(subdomain='test')
|
h = Host.objects.get(subdomain=hostname)
|
||||||
assert h.client_faults == 0
|
assert h.client_faults == 0
|
||||||
assert h.server_faults == 0
|
assert h.server_faults == 0
|
||||||
assert h.available is True
|
assert h.available is True
|
||||||
@ -32,26 +35,28 @@ def test_faults_reset():
|
|||||||
|
|
||||||
|
|
||||||
def test_faults_no_abuse():
|
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.client_faults = 10 # below threshold
|
||||||
h.abuse = False
|
h.abuse = False
|
||||||
h.save()
|
h.save()
|
||||||
# flag abusive hosts
|
# flag abusive hosts
|
||||||
management.call_command('faults', flag_abuse=23)
|
management.call_command('faults', flag_abuse=23)
|
||||||
# check if it did not get flagged
|
# 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.client_faults == 10
|
||||||
assert h.abuse is False
|
assert h.abuse is False
|
||||||
|
|
||||||
|
|
||||||
def test_faults_abuse():
|
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.client_faults = 42 # above threshold
|
||||||
h.abuse = False
|
h.abuse = False
|
||||||
h.save()
|
h.save()
|
||||||
# flag abusive hosts
|
# flag abusive hosts
|
||||||
management.call_command('faults', flag_abuse=23)
|
management.call_command('faults', flag_abuse=23)
|
||||||
# check if it did get flagged
|
# 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.client_faults == 0
|
||||||
assert h.abuse is True
|
assert h.abuse is True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user