diff --git a/src/postorius/tests/fixtures/vcr_cassettes/list_members.yaml b/src/postorius/tests/fixtures/vcr_cassettes/list_members.yaml new file mode 100644 index 0000000..d68a881 --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/list_members.yaml @@ -0,0 +1,136 @@ +interactions: +- request: + body: mail_host=example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode 'Duplicate email host: example.com'} + headers: + content-length: ['33'] + content-type: [application/json; charset=utf-8] + status: {code: 400, message: Bad Request} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"base_url": "http://example.com", "description": + null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "mail_host": + "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com", + "url_host": "example.com"}'} + headers: + content-length: ['233'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"base_url": "http://example.com", "description": + null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "mail_host": + "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com", + "url_host": "example.com"}'} + headers: + content-length: ['233'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: fqdn_listname=foo%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/lists/foo.example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode DELETE + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +- request: + body: mail_host=example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/domains + response: + body: {string: !!python/unicode 'Duplicate email host: example.com'} + headers: + content-length: ['33'] + content-type: [application/json; charset=utf-8] + status: {code: 400, message: Bad Request} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"base_url": "http://example.com", "description": + null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "mail_host": + "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com", + "url_host": "example.com"}'} + headers: + content-length: ['233'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/domains/example.com + response: + body: {string: !!python/unicode '{"base_url": "http://example.com", "description": + null, "http_etag": "\"e736411818ff1815ca83575e0958c38c5188f0a4\"", "mail_host": + "example.com", "self_link": "http://localhost:9001/3.0/domains/example.com", + "url_host": "example.com"}'} + headers: + content-length: ['233'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: fqdn_listname=foo%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/lists + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/lists/foo.example.com'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode DELETE + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + status: {code: 204, message: No Content} +version: 1 diff --git a/src/postorius/tests/fixtures/vcr_cassettes/list_members_search_members.yaml b/src/postorius/tests/fixtures/vcr_cassettes/list_members_search_members.yaml new file mode 100644 index 0000000..5adbe5e --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/list_members_search_members.yaml @@ -0,0 +1,181 @@ +interactions: +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: display_name=None&list_id=foo.example.com&pre_approved=True&pre_confirmed=True&pre_verified=True&subscriber=member-1%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/19'] + status: {code: 201, message: Created} +- request: + body: display_name=None&list_id=foo.example.com&pre_approved=True&pre_confirmed=True&pre_verified=True&subscriber=member-2%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/20'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"4d9bc85dd33a55faefff3ccbbf04ab14a6889a98\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 2, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/find?count=1&list_id=foo.example.com&page=1&role=member&subscriber=%2Aexample.com%2A + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"46788223fde9c9dff2d2ceecd6b131690a911740\"", "list_id": "foo.example.com", + "member_id": 19, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/19", "user": "http://localhost:9001/3.0/users/7"}], + "http_etag": "\"03a7a0eae1852d442b4383f883d0354c5962c091\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['491'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/find?count=25&list_id=foo.example.com&page=1&role=member&subscriber=%2Aexample.com%2A + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"46788223fde9c9dff2d2ceecd6b131690a911740\"", "list_id": "foo.example.com", + "member_id": 19, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/19", "user": "http://localhost:9001/3.0/users/7"}, + {"address": "http://localhost:9001/3.0/addresses/member-2@example.com", "delivery_mode": + "regular", "email": "member-2@example.com", "http_etag": "\"3d6051eb54c33307d09bc1c0a48cf84ba59911a7\"", + "list_id": "foo.example.com", "member_id": 20, "moderation_action": "defer", + "role": "member", "self_link": "http://localhost:9001/3.0/members/20", "user": + "http://localhost:9001/3.0/users/8"}], "http_etag": "\"4a3251103c14034604c8a92fe625d775f87a8f4a\"", + "start": 0, "total_size": 2}'} + headers: + content-length: ['879'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/19 + response: + body: {string: !!python/unicode '{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"46788223fde9c9dff2d2ceecd6b131690a911740\"", "list_id": "foo.example.com", + "member_id": 19, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/19", "user": "http://localhost:9001/3.0/users/7"}'} + headers: + content-length: ['386'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/20 + response: + body: {string: !!python/unicode '{"address": "http://localhost:9001/3.0/addresses/member-2@example.com", + "delivery_mode": "regular", "email": "member-2@example.com", "http_etag": + "\"3d6051eb54c33307d09bc1c0a48cf84ba59911a7\"", "list_id": "foo.example.com", + "member_id": 20, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/20", "user": "http://localhost:9001/3.0/users/8"}'} + headers: + content-length: ['386'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"4d9bc85dd33a55faefff3ccbbf04ab14a6889a98\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 2, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/find?count=1&list_id=foo.example.com&page=1&role=member&subscriber=%2Amember-1%2A + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"46788223fde9c9dff2d2ceecd6b131690a911740\"", "list_id": "foo.example.com", + "member_id": 19, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/19", "user": "http://localhost:9001/3.0/users/7"}], + "http_etag": "\"08b2888a537f05315b4c2f7c4f06ff5ff2874577\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['491'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/find?count=25&list_id=foo.example.com&page=1&role=member&subscriber=%2Amember-1%2A + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"46788223fde9c9dff2d2ceecd6b131690a911740\"", "list_id": "foo.example.com", + "member_id": 19, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/19", "user": "http://localhost:9001/3.0/users/7"}], + "http_etag": "\"08b2888a537f05315b4c2f7c4f06ff5ff2874577\"", "start": 0, "total_size": + 1}'} + headers: + content-length: ['491'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +version: 1 diff --git a/src/postorius/tests/fixtures/vcr_cassettes/list_members_show_members_page.yaml b/src/postorius/tests/fixtures/vcr_cassettes/list_members_show_members_page.yaml new file mode 100644 index 0000000..eaf05aa --- /dev/null +++ b/src/postorius/tests/fixtures/vcr_cassettes/list_members_show_members_page.yaml @@ -0,0 +1,130 @@ +interactions: +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo.example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"698a819bbb6b902096a8c5543cc7fac2328960d5\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 0, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: display_name=None&list_id=foo.example.com&pre_approved=True&pre_confirmed=True&pre_verified=True&subscriber=member-1%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/21'] + status: {code: 201, message: Created} +- request: + body: display_name=None&list_id=foo.example.com&pre_approved=True&pre_confirmed=True&pre_verified=True&subscriber=member-2%40example.com + headers: + accept-encoding: ['gzip, deflate'] + !!python/unicode content-type: [!!python/unicode application/x-www-form-urlencoded] + method: !!python/unicode POST + uri: http://localhost:9001/3.0/members + response: + body: {string: !!python/unicode ''} + headers: + content-length: ['0'] + location: ['http://localhost:9001/3.0/members/22'] + status: {code: 201, message: Created} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo@example.com + response: + body: {string: !!python/unicode '{"display_name": "Foo", "fqdn_listname": "foo@example.com", + "http_etag": "\"4d9bc85dd33a55faefff3ccbbf04ab14a6889a98\"", "list_id": "foo.example.com", + "list_name": "foo", "mail_host": "example.com", "member_count": 2, "self_link": + "http://localhost:9001/3.0/lists/foo.example.com", "volume": 1}'} + headers: + content-length: ['294'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=1&page=1 + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"c6a73a9e50906134dcc81d2f753889516afd10ed\"", "list_id": "foo.example.com", + "member_id": 21, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/21", "user": "http://localhost:9001/3.0/users/7"}], + "http_etag": "\"d57151c55186a47ce642e684793dc46c6d5627e2\"", "start": 0, "total_size": + 2}'} + headers: + content-length: ['491'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/lists/foo@example.com/roster/member?count=25&page=1 + response: + body: {string: !!python/unicode '{"entries": [{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"c6a73a9e50906134dcc81d2f753889516afd10ed\"", "list_id": "foo.example.com", + "member_id": 21, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/21", "user": "http://localhost:9001/3.0/users/7"}, + {"address": "http://localhost:9001/3.0/addresses/member-2@example.com", "delivery_mode": + "regular", "email": "member-2@example.com", "http_etag": "\"b184a3d2fb8d63ee8b632a4de49fc255aa1c809a\"", + "list_id": "foo.example.com", "member_id": 22, "moderation_action": "defer", + "role": "member", "self_link": "http://localhost:9001/3.0/members/22", "user": + "http://localhost:9001/3.0/users/8"}], "http_etag": "\"cac1c6fdd3d8b2b20e34c1e507fa789cfdefd7ce\"", + "start": 0, "total_size": 2}'} + headers: + content-length: ['879'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/21 + response: + body: {string: !!python/unicode '{"address": "http://localhost:9001/3.0/addresses/member-1@example.com", + "delivery_mode": "regular", "email": "member-1@example.com", "http_etag": + "\"c6a73a9e50906134dcc81d2f753889516afd10ed\"", "list_id": "foo.example.com", + "member_id": 21, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/21", "user": "http://localhost:9001/3.0/users/7"}'} + headers: + content-length: ['386'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +- request: + body: null + headers: + accept-encoding: ['gzip, deflate'] + method: !!python/unicode GET + uri: http://localhost:9001/3.0/members/22 + response: + body: {string: !!python/unicode '{"address": "http://localhost:9001/3.0/addresses/member-2@example.com", + "delivery_mode": "regular", "email": "member-2@example.com", "http_etag": + "\"b184a3d2fb8d63ee8b632a4de49fc255aa1c809a\"", "list_id": "foo.example.com", + "member_id": 22, "moderation_action": "defer", "role": "member", "self_link": + "http://localhost:9001/3.0/members/22", "user": "http://localhost:9001/3.0/users/8"}'} + headers: + content-length: ['386'] + content-type: [application/json; charset=utf-8] + status: {code: 200, message: OK} +version: 1 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 3a8fc0a..73bfbfe 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -230,3 +230,63 @@ @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) + + +class ListMembersTest(TestCase): + """Test the list members page. + """ + + @MM_VCR.use_cassette('list_members.yaml') + def setUp(self): + try: + self.domain = get_client().create_domain('example.com') + except HTTPError: + self.domain = get_client().get_domain('example.com') + try: + self.foo_list = self.domain.create_list('foo') + except HTTPError: + self.foo_list = get_client().get_list('foo.example.com') + self.superuser = User.objects.create_superuser( + 'testsu', 'su@example.com', 'testpass') + + @MM_VCR.use_cassette('list_members.yaml') + def tearDown(self): + self.foo_list.delete() + self.superuser.delete() + + @MM_VCR.use_cassette('list_members_show_members_page.yaml') + def test_show_members_page(self): + self.client.login(username='testsu', password='testpass') + member_1 = self.foo_list.subscribe('member-1@example.com', + pre_verified=True, pre_confirmed=True, pre_approved=True) + member_2 = self.foo_list.subscribe('member-2@example.com', + pre_verified=True, pre_confirmed=True, pre_approved=True) + response = self.client.get(reverse( + 'list_members', args=['foo@example.com', 'subscriber'])) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['members']), 2) + self.assertEqual(response.context['members'].paginator.count, 2) + self.assertContains(response, member_1.email) + self.assertContains(response, member_2.email) + + @MM_VCR.use_cassette('list_members_search_members.yaml') + def test_search_members_1(self): + self.client.login(username='testsu', password='testpass') + member_1 = self.foo_list.subscribe('member-1@example.com', + pre_verified=True, pre_confirmed=True, pre_approved=True) + member_2 = self.foo_list.subscribe('member-2@example.com', + pre_verified=True, pre_confirmed=True, pre_approved=True) + response = self.client.get(reverse( + 'list_members', args=['foo@example.com', 'subscriber']), + {'q': 'example.com'}) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['members']), 2) + self.assertContains(response, member_1.email) + self.assertContains(response, member_2.email) + response = self.client.get(reverse( + 'list_members', args=['foo@example.com', 'subscriber']), + {'q': 'member-1'}) + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context['members']), 1) + self.assertContains(response, member_1.email) + self.assertNotContains(response, member_2.email)