diff --git a/src/postorius/tests/mailman_api_tests/test_domain_new.py b/src/postorius/tests/mailman_api_tests/test_domain_new.py index b8fb6a9..551b398 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_new.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_new.py @@ -22,6 +22,7 @@ from django.core.urlresolvers import reverse from django.shortcuts import resolve_url from django.test import Client, TestCase +from django.test.utils import override_settings try: from urllib2 import HTTPError @@ -55,12 +56,12 @@ except HTTPError: pass + @override_settings(ROOT_URLCONF='testing.urls') def test_permission_denied(self): self.client.login(username='user', password='pwd') response = self.client.get(reverse('domain_new')) - expected = 'http://testserver%s?next=%s' % ( - resolve_url(settings.LOGIN_URL), reverse('domain_new')) - self.assertEqual(response['location'], expected) + self.assertRedirects(response, '{}?next={}'.format(resolve_url(settings.LOGIN_URL), + reverse('domain_new'))) @MM_VCR.use_cassette('test_list_creation.yaml') def test_new_domain_created_with_owner(self): diff --git a/src/postorius/tests/mailman_api_tests/test_list_members.py b/src/postorius/tests/mailman_api_tests/test_list_members.py index 618de9b..5b332fd 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -22,6 +22,7 @@ from django.core.urlresolvers import reverse from django.utils.timezone import now from django.test import Client, TestCase +from django.test.utils import override_settings from six.moves.urllib_error import HTTPError from six.moves.urllib_parse import quote @@ -67,15 +68,13 @@ get_client().delete_domain('example.com') @MM_VCR.use_cassette('list_members_access.yaml') + @override_settings(ROOT_URLCONF='testing.urls') def test_page_not_accessible_if_not_logged_in(self): url = reverse('list_members', args=('foo@example.com', 'subscriber',)) response = self.client.get(url) if "%40" not in url: # Django < 1.8 url = quote(url) - expected_redirect = "http://testserver%s?next=%s" % ( - reverse(settings.LOGIN_URL), url) - self.assertEqual(response.status_code, 302) - self.assertEqual(response["location"], expected_redirect) + self.assertRedirects(response, '{}?next={}'.format(reverse(settings.LOGIN_URL), url)) @MM_VCR.use_cassette('list_members_access.yaml') def test_page_not_accessible_for_unprivileged_users(self): diff --git a/src/postorius/tests/mailman_api_tests/test_list_new.py b/src/postorius/tests/mailman_api_tests/test_list_new.py index 95b9943..c696a6c 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_new.py +++ b/src/postorius/tests/mailman_api_tests/test_list_new.py @@ -22,6 +22,7 @@ from django.core.urlresolvers import reverse from django.shortcuts import resolve_url from django.test import Client, TestCase +from django.test.utils import override_settings try: from urllib2 import HTTPError @@ -36,7 +37,6 @@ vcr_log = logging.getLogger('vcr') vcr_log.setLevel(logging.WARNING) - class ListCreationTest(TestCase): """Tests for the new list page.""" @@ -55,12 +55,12 @@ mlist.delete() get_client().delete_domain('example.com') + @override_settings(ROOT_URLCONF='testing.urls') def test_permission_denied(self): self.client.login(username='user', password='pwd') response = self.client.get(reverse('list_new')) - expected = 'http://testserver%s?next=%s' % ( - resolve_url(settings.LOGIN_URL), reverse('list_new')) - self.assertEqual(response['location'], expected) + self.assertRedirects(response, '{}?next={}'.format(resolve_url(settings.LOGIN_URL), + reverse('list_new'))) @MM_VCR.use_cassette('test_list_creation.yaml') def test_new_list_created_with_owner(self): diff --git a/testing/urls.py b/testing/urls.py new file mode 100644 index 0000000..b8aefdd --- /dev/null +++ b/testing/urls.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# Copyright (C) 1998-2012 by the Free Software Foundation, Inc. +# +# This file is part of Postorius. +# +# Postorius is free software: you can redistribute it and/or modify it under +# the terms of the GNU General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Postorius is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along with +# Postorius. If not, see . + +import postorius + +from django.conf.urls import include, url +from django.conf import settings + +urlpatterns = [ + url('', include('django_browserid.urls')), + url(r'', include('postorius.urls')), +]