diff --git a/src/postorius/tests/mailman_api_tests/test_list_index.py b/src/postorius/tests/mailman_api_tests/test_list_index.py index d72cf17..3a18662 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_index.py +++ b/src/postorius/tests/mailman_api_tests/test_list_index.py @@ -17,7 +17,6 @@ import logging -from django.conf import settings from django.core.urlresolvers import reverse from django.test import Client, SimpleTestCase from django.test.utils import override_settings @@ -28,6 +27,8 @@ logger = logging.getLogger(__name__) +vcr_log = logging.getLogger('vcr') +vcr_log.setLevel(logging.WARNING) API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001', @@ -39,7 +40,7 @@ class ListIndexPageTest(SimpleTestCase): """Tests for the list index page.""" - @MM_VCR.use_cassette('test_list_index.yaml') + @MM_VCR.use_cassette('test_list_index/list_index_page/setup.yaml') def setUp(self): self.client = Client() try: @@ -48,12 +49,13 @@ self.domain = get_client().get_domain('example.com') self.foo_list = self.domain.create_list('foo') - @MM_VCR.use_cassette('test_list_index.yaml') + @MM_VCR.use_cassette('test_list_index/list_index_page/teardown.yaml') def tearDown(self): for mlist in get_client().lists: mlist.delete() - @MM_VCR.use_cassette('test_list_index.yaml') + @MM_VCR.use_cassette('test_list_index/list_index_page/' + 'list_index_contains_one_list.yaml') def test_list_index_contains_one_list(self): # The list index page should contain the response = self.client.get(reverse('list_index')) 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 f63223d..ca07aa4 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -27,6 +27,8 @@ logger = logging.getLogger(__name__) +vcr_log = logging.getLogger('vcr') +vcr_log.setLevel(logging.WARNING) API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001', @@ -35,87 +37,136 @@ @override_settings(**API_CREDENTIALS) -class ListMembersPageTest(SimpleTestCase): +class ListMembersAccessTest(SimpleTestCase): """Tests for the list members page. Tests permissions and creation of list owners and moderators. """ - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_access.yaml') def setUp(self): try: self.domain = get_client().create_domain('example.com') except HTTPError: self.domain = get_client().get_domain('example.com') - self.foo_list = self.domain.create_list('foo') - self.user = User.objects.create_user('testuser', 'test@example.com', - 'testpass') - self.superuser = User.objects.create_superuser('testsu', - 'su@example.com', - 'testpass') - self.owner = User.objects.create_user('testowner', 'owner@example.com', - 'testpass') - self.moderator = User.objects.create_user('testmoderator', - 'moderator@example.com', - 'testpass') + try: + self.foo_list = self.domain.create_list('foo') + except HTTPError: + self.foo_list = get_client().get_list('foo.example.com') + logger.warning(self.foo_list) + self.user = User.objects.create_user( + 'testuser', 'test@example.com', 'testpass') + self.superuser = User.objects.create_superuser( + 'testsu', 'su@example.com', 'testpass') + self.owner = User.objects.create_user( + 'testowner', 'owner@example.com', 'testpass') + self.moderator = User.objects.create_user( + 'testmoderator', 'moderator@example.com', 'testpass') self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_access.yaml') def tearDown(self): - for mlist in get_client().lists: - mlist.delete() + self.foo_list.delete() self.user.delete() self.superuser.delete() self.owner.delete() self.moderator.delete() - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_access.yaml') def test_page_not_accessible_if_not_logged_in(self): response = self.client.get(reverse('list_members', args=('foo@example.com', ))) self.assertEqual(response.status_code, 403) - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_access.yaml') def test_page_not_accessible_for_unprivileged_users(self): self.client.login(username='testuser', password='testpass') response = self.client.get(reverse('list_members', args=('foo@example.com', ))) self.assertEqual(response.status_code, 403) - @MM_VCR.use_cassette('test_list_members.yaml') - def test_page_not_accessible_for_moderator(self): + @MM_VCR.use_cassette('list_members_page.yaml') + def test_not_accessible_for_moderator(self): self.client.login(username='testmoderator', password='testpass') response = self.client.get(reverse('list_members', args=('foo@example.com', ))) self.assertEqual(response.status_code, 403) - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_page.yaml') def test_page_accessible_for_superuser(self): self.client.login(username='testsu', password='testpass') response = self.client.get(reverse('list_members', args=('foo@example.com', ))) self.assertEqual(response.status_code, 200) - @MM_VCR.use_cassette('test_list_members.yaml') + @MM_VCR.use_cassette('list_members_page.yaml') def test_page_accessible_for_owner(self): self.client.login(username='testowner', password='testpass') response = self.client.get(reverse('list_members', args=('foo@example.com', ))) self.assertEqual(response.status_code, 200) - @MM_VCR.use_cassette('test_list_members.yaml') - def test_add_owner(self): - self.client.login(username='testsu', password='testpass') - self.client.post(reverse('list_members', - args=('foo@example.com', )), - {'owner_email': 'newowner@example.com'}) + +@override_settings(**API_CREDENTIALS) +class AddOwnerTest(SimpleTestCase): + """Tests for the list members page. + + Tests creation of list owners. + """ + + @MM_VCR.use_cassette('test_list_members/add_owner_setup.yaml') + def setUp(self): + try: + self.domain = get_client().create_domain('example.com') + except HTTPError: + self.domain = get_client().get_domain('example.com') + self.foo_list = self.domain.create_list('foo') + self.su = User.objects.create_superuser( + 'su', 'su@example.com', 'pwd') + # login and post new owner data to url + self.client.login(username='su', password='pwd') + self.client.post( + reverse('list_members', args=('foo@example.com', )), + {'owner_email': 'newowner@example.com'}) + + @MM_VCR.use_cassette('test_list_members/add_owner_teardown.yaml') + def tearDown(self): + self.foo_list.delete() + self.su.delete() + + @MM_VCR.use_cassette('test_list_members/new_owner_added.yaml') + def test_new_owner_added(self): self.assertTrue(u'newowner@example.com' in self.foo_list.owners) - @MM_VCR.use_cassette('test_list_members.yaml') - def test_add_moderator(self): - self.client.login(username='testsu', password='testpass') - self.client.post(reverse('list_members', - args=('foo@example.com', )), - {'moderator_email': 'newmod@example.com'}) + +@override_settings(**API_CREDENTIALS) +class AddOwnerTest(SimpleTestCase): + """Tests for the list members page. + + Tests creation of moderators. + """ + + @MM_VCR.use_cassette('test_list_members/add_moderator_setup.yaml') + def setUp(self): + try: + self.domain = get_client().create_domain('example.com') + except HTTPError: + self.domain = get_client().get_domain('example.com') + self.foo_list = self.domain.create_list('foo') + self.su = User.objects.create_superuser( + 'su', 'su@example.com', 'pwd') + # login and post new moderator data to url + self.client.login(username='su', password='pwd') + self.client.post( + reverse('list_members', args=('foo@example.com', )), + {'moderator_email': 'newmod@example.com'}) + + @MM_VCR.use_cassette('test_list_members/add_moderator_teardown.yaml') + def tearDown(self): + self.foo_list.delete() + self.su.delete() + + @MM_VCR.use_cassette('test_list_members/new_moderator_added.yaml') + def test_new_moderator_added(self): self.assertTrue(u'newmod@example.com' in self.foo_list.moderators) 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 6f24f6b..584899a 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_new.py +++ b/src/postorius/tests/mailman_api_tests/test_list_new.py @@ -28,6 +28,8 @@ logger = logging.getLogger(__name__) +vcr_log = logging.getLogger('vcr') +vcr_log.setLevel(logging.WARNING) API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001', @@ -39,7 +41,7 @@ class ListCreationTest(SimpleTestCase): """Tests for the new list page.""" - @MM_VCR.use_cassette('test_list_new.yaml') + @MM_VCR.use_cassette('test_list_new/list_creation/setup.yaml') def setUp(self): self.user = User.objects.create_user('user', 'user@example.com', 'pwd') self.superuser = User.objects.create_superuser('su', 'su@example.com', @@ -49,7 +51,7 @@ except HTTPError: self.domain = get_client().get_domain('example.com') - @MM_VCR.use_cassette('test_list_new.yaml') + @MM_VCR.use_cassette('test_list_new/list_creation/teardown.yaml') def tearDown(self): self.user.delete() self.superuser.delete() @@ -63,7 +65,8 @@ response, '/postorius/accounts/login/?next=/postorius/lists/new/') - @MM_VCR.use_cassette('test_list_new.yaml') + @MM_VCR.use_cassette('test_list_new/list_creation/' + 'new_list_created_with_owner.yaml') def test_new_list_created_with_owner(self): self.client.login(username='su', password='pwd') post_data = {'listname': 'a_new_list', diff --git a/src/postorius/tests/mailman_api_tests/test_list_summary.py b/src/postorius/tests/mailman_api_tests/test_list_summary.py index 1c01277..0370957 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_summary.py +++ b/src/postorius/tests/mailman_api_tests/test_list_summary.py @@ -27,6 +27,8 @@ logger = logging.getLogger(__name__) +vcr_log = logging.getLogger('vcr') +vcr_log.setLevel(logging.WARNING) API_CREDENTIALS = {'MAILMAN_API_URL': 'http://localhost:9001', @@ -42,7 +44,7 @@ login status. """ - @MM_VCR.use_cassette('test_list_summary.yaml') + @MM_VCR.use_cassette('test_list_summary/list_summary_page/setup.yaml') def setUp(self): self.client = Client() try: @@ -51,12 +53,13 @@ domain = get_client().get_domain('example.com') self.foo_list = domain.create_list('foo') - @MM_VCR.use_cassette('test_list_summary.yaml') + @MM_VCR.use_cassette('test_list_summary/list_summary_page/teardown.yaml') def tearDown(self): for mlist in get_client().lists: mlist.delete() - @MM_VCR.use_cassette('test_list_summary.yaml') + @MM_VCR.use_cassette('test_list_summary/list_summary_page/' + 'list_summary_logged_out.yaml') def test_list_summary_logged_out(self): # Response must contain list obj but not the form. response = self.client.get(reverse('list_summary', @@ -67,7 +70,8 @@ self.assertTrue('

' in response.content) self.assertTrue('