more tests, better coverage
This commit is contained in:
parent
11a6c0177e
commit
ae9c2f29d0
@ -45,6 +45,7 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
|||||||
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
||||||
nameserver_update_key=NAMESERVER_UPDATE_KEY,
|
nameserver_update_key=NAMESERVER_UPDATE_KEY,
|
||||||
public=NAMESERVER_PUBLIC,
|
public=NAMESERVER_PUBLIC,
|
||||||
|
created_by=u,
|
||||||
)
|
)
|
||||||
# this is for querying:
|
# this is for querying:
|
||||||
d = Domain.objects.create(
|
d = Domain.objects.create(
|
||||||
@ -53,6 +54,7 @@ def db_init(db): # note: db is a predefined fixture and required here to have t
|
|||||||
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
nameserver_update_algorithm=NAMESERVER_UPDATE_ALGORITHM,
|
||||||
nameserver_update_key='invalid=', # we don't send updates there (and the real key is really secret)
|
nameserver_update_key='invalid=', # we don't send updates there (and the real key is really secret)
|
||||||
public=NAMESERVER_PUBLIC,
|
public=NAMESERVER_PUBLIC,
|
||||||
|
created_by=u2,
|
||||||
)
|
)
|
||||||
# a Host for api / session update tests
|
# a Host for api / session update tests
|
||||||
h = Host(subdomain='test', domain=d, created_by=u)
|
h = Host(subdomain='test', domain=d, created_by=u)
|
||||||
|
@ -69,6 +69,25 @@ def test_nic_update_authorized_myip(client):
|
|||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
# we don't care whether it is nochg or good, but should be the ip from myip=...:
|
# we don't care whether it is nochg or good, but should be the ip from myip=...:
|
||||||
assert response.content in ['good 4.3.2.1', 'nochg 4.3.2.1']
|
assert response.content in ['good 4.3.2.1', 'nochg 4.3.2.1']
|
||||||
|
response = client.get(reverse('nic_update') + '?myip=1.2.3.4',
|
||||||
|
HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET))
|
||||||
|
assert response.status_code == 200
|
||||||
|
# must be good (was different IP)
|
||||||
|
assert response.content == 'good 1.2.3.4'
|
||||||
|
response = client.get(reverse('nic_update') + '?myip=1.2.3.4',
|
||||||
|
HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET))
|
||||||
|
assert response.status_code == 200
|
||||||
|
# must be nochg (was same IP)
|
||||||
|
assert response.content == 'nochg 1.2.3.4'
|
||||||
|
|
||||||
|
|
||||||
|
def test_nic_update_authorized_badagent(client, settings):
|
||||||
|
settings.BAD_AGENTS = ['foo', 'bad_agent', 'bar', ]
|
||||||
|
response = client.get(reverse('nic_update'),
|
||||||
|
HTTP_AUTHORIZATION=make_basic_auth_header(TEST_HOST, TEST_SECRET),
|
||||||
|
HTTP_USER_AGENT='bad_agent')
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.content == 'badagent'
|
||||||
|
|
||||||
|
|
||||||
def test_nic_update_session_nosession(client):
|
def test_nic_update_session_nosession(client):
|
||||||
@ -76,16 +95,27 @@ def test_nic_update_session_nosession(client):
|
|||||||
assert response.status_code == 302 # redirects to login view
|
assert response.status_code == 302 # redirects to login view
|
||||||
|
|
||||||
|
|
||||||
def test_nic_update_session(client):
|
def test_nic_update_session_no_hostname(client):
|
||||||
client.login(username=USERNAME, password=PASSWORD)
|
client.login(username=USERNAME, password=PASSWORD)
|
||||||
response = client.get(reverse('nic_update_authorized'))
|
response = client.get(reverse('nic_update_authorized'))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.content == "nohost" # we did not tell which host
|
assert response.content == "nohost" # we did not tell which host
|
||||||
response = client.get(reverse('nic_update_authorized') + '?hostname=%s&myip=%s' % (TEST_HOST, '1.2.3.4'))
|
|
||||||
|
|
||||||
|
def test_nic_update_session(client):
|
||||||
|
client.login(username=USERNAME, password=PASSWORD)
|
||||||
|
response = client.get(reverse('nic_update_authorized') + '?hostname=%s' % (TEST_HOST, ))
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert response.content.startswith('good ') or response.content.startswith('nochg ')
|
assert response.content.startswith('good ') or response.content.startswith('nochg ')
|
||||||
|
|
||||||
|
|
||||||
|
def test_nic_update_session_myip(client):
|
||||||
|
client.login(username=USERNAME, password=PASSWORD)
|
||||||
|
response = client.get(reverse('nic_update_authorized') + '?hostname=%s&myip=%s' % (TEST_HOST, '1.2.3.4'))
|
||||||
|
assert response.status_code == 200
|
||||||
|
assert response.content.startswith('good 1.2.3.4') or response.content.startswith('nochg 1.2.3.4')
|
||||||
|
|
||||||
|
|
||||||
def test_nic_update_session_foreign_host(client):
|
def test_nic_update_session_foreign_host(client):
|
||||||
client.login(username=USERNAME, password=PASSWORD)
|
client.login(username=USERNAME, password=PASSWORD)
|
||||||
response = client.get(reverse('nic_update_authorized') + '?hostname=%s' % TEST_HOST2)
|
response = client.get(reverse('nic_update_authorized') + '?hostname=%s' % TEST_HOST2)
|
||||||
|
@ -76,6 +76,20 @@ class TestIntelligentDeleter(object):
|
|||||||
remove_records(host)
|
remove_records(host)
|
||||||
delete(host) # hmm, this doesn't raise NXDOMAIN!?
|
delete(host) # hmm, this doesn't raise NXDOMAIN!?
|
||||||
|
|
||||||
|
def test_delete_typed(self):
|
||||||
|
host, ip4, ip6 = TEST_HOST, '1.2.3.4', '::42'
|
||||||
|
# make sure the host is there
|
||||||
|
update_ns(host, 'A', ip4, action='add')
|
||||||
|
update_ns(host, 'AAAA', ip6, action='add')
|
||||||
|
delete(host, 'A')
|
||||||
|
# make sure it is gone
|
||||||
|
with pytest.raises(NoAnswer):
|
||||||
|
query_ns(host, 'A')
|
||||||
|
delete(host, 'AAAA')
|
||||||
|
# make sure it is gone
|
||||||
|
with pytest.raises(NXDOMAIN):
|
||||||
|
query_ns(host, 'AAAA')
|
||||||
|
|
||||||
|
|
||||||
class TestQuery(object):
|
class TestQuery(object):
|
||||||
def test_queries_ok(self):
|
def test_queries_ok(self):
|
||||||
|
55
nsupdate/main/_tests/test_main.py
Normal file
55
nsupdate/main/_tests/test_main.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
"""
|
||||||
|
Tests for main views module.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
|
||||||
|
|
||||||
|
USERNAME = 'test'
|
||||||
|
PASSWORD = 'pass'
|
||||||
|
|
||||||
|
|
||||||
|
def test_views_anon(client):
|
||||||
|
for view, kwargs, status_code in [
|
||||||
|
('home', dict(), 200),
|
||||||
|
('about', dict(), 200),
|
||||||
|
('legal', dict(), 200),
|
||||||
|
('robots', dict(), 200),
|
||||||
|
('status', dict(), 200), # TODO make this require a login
|
||||||
|
('overview', dict(), 302),
|
||||||
|
# stuff that requires a log in redirects to the login view:
|
||||||
|
('domain_overview', dict(), 302),
|
||||||
|
('host_view', dict(pk=1), 302),
|
||||||
|
('domain_view', dict(pk=1), 302),
|
||||||
|
('generate_secret_view', dict(pk=1), 302),
|
||||||
|
('generate_ns_secret_view', dict(pk=1), 302),
|
||||||
|
('delete_host', dict(pk=1), 302),
|
||||||
|
('delete_domain', dict(pk=1), 302),
|
||||||
|
]:
|
||||||
|
print view, kwargs, status_code
|
||||||
|
response = client.get(reverse(view, kwargs=kwargs))
|
||||||
|
assert response.status_code == status_code
|
||||||
|
|
||||||
|
|
||||||
|
def test_views_logged_in(client):
|
||||||
|
client.login(username=USERNAME, password=PASSWORD)
|
||||||
|
for view, kwargs, status_code in [
|
||||||
|
('home', dict(), 200),
|
||||||
|
('about', dict(), 200),
|
||||||
|
('legal', dict(), 200),
|
||||||
|
('robots', dict(), 200),
|
||||||
|
('status', dict(), 200),
|
||||||
|
('overview', dict(), 200),
|
||||||
|
('domain_overview', dict(), 200),
|
||||||
|
('host_view', dict(pk=1), 200),
|
||||||
|
('domain_view', dict(pk=1), 200),
|
||||||
|
('generate_secret_view', dict(pk=1), 200),
|
||||||
|
('generate_ns_secret_view', dict(pk=1), 200),
|
||||||
|
('delete_host', dict(pk=1), 200),
|
||||||
|
('delete_domain', dict(pk=1), 200),
|
||||||
|
]:
|
||||||
|
print view, kwargs, status_code
|
||||||
|
response = client.get(reverse(view, kwargs=kwargs))
|
||||||
|
assert response.status_code == status_code
|
@ -31,5 +31,5 @@ urlpatterns = patterns(
|
|||||||
url(r'^myip$', myip_view, name='myip'),
|
url(r'^myip$', myip_view, name='myip'),
|
||||||
url(r'^nic/update$', NicUpdateView.as_view(), name='nic_update'),
|
url(r'^nic/update$', NicUpdateView.as_view(), name='nic_update'),
|
||||||
# for bots
|
# for bots
|
||||||
url(r'^robots.txt$', RobotsTxtView.as_view()),
|
url(r'^robots.txt$', RobotsTxtView.as_view(), name='robots'),
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user