def test_get_list(self): """Test if list members are retreived correctly.""" from postorius.views import ListMembersView # test get_list view = ListMembersView() with patch('mailmanclient.Client.get_list') as mock: mock.return_value = self.mock_list the_list = view._get_list('*****@*****.**') self.assertEqual(the_list.members[0].address, '*****@*****.**') self.assertEqual(the_list.members[1].address, '*****@*****.**')
def test_dispatch(self): """Test if list members are retreived correctly.""" from postorius.views import ListMembersView # test get_list view = ListMembersView() with patch('mailmanclient.Client.get_list') as mock: mock.return_value = self.mock_list the_list = view._get_list('*****@*****.**') request = self.request_factory.get( '/lists/[email protected]/members/') request.user = User.objects.create_superuser('sux', '*****@*****.**', 'pwd') view.dispatch(request, fqdn_listname='*****@*****.**') self.assertEqual(self.mock_list, view.mailing_list)
def test_return_code_by_user(self): """Test response status code by user status. """ from postorius.views import ListMembersView with patch('mailmanclient.Client.get_list') as mock: mock.return_value = self.mock_list request = self.request_factory.get( '/lists/[email protected]/members/') # anonymous users should be redirected request.user = AnonymousUser() self.assertRaises(PermissionDenied, ListMembersView.as_view(), request, fqdn_listname='*****@*****.**') # logged in users should be redirected request.user = User.objects.create_user('les', '*****@*****.**', 'pwd') self.assertRaises(PermissionDenied, ListMembersView.as_view(), request, fqdn_listname='*****@*****.**') # superusers should get the page request.user = User.objects.create_superuser('su', '*****@*****.**', 'pwd') response = ListMembersView.as_view()( request, fqdn_listname='*****@*****.**') self.assertEqual(response.status_code, 200)