def test_pending_user(self): """Users should not be able to see pending projects""" self.project.private = False self.project.approved = False self.project.save() http_get_response(self.url, self.view, self.user, **self.kwargs)
def test_get_404(self): """The view should return 404 is the foia is not visible to the user.""" self.foia.embargo = True self.foia.save() user = UserFactory() ok_(not self.foia.has_perm(user, 'view')) http_get_response(self.url, self.view, user, **self.kwargs)
def test_auth_views(self, mock_stripe): """Test private views while logged in""" # pylint: disable=unused-argument response = http_get_response(reverse("acct-my-profile"), views.ProfileView.as_view(), self.user) eq_(response.status_code, 302, "Logged in user may view their own profile.") response = http_get_response(reverse("acct-settings"), views.ProfileSettings.as_view(), self.user) eq_(response.status_code, 200, "Logged in user may view their own settings.")
def test_owner(self): """Getting the share view should just redirect to the request detail view.""" response = http_get_response( self.url, self.view, self.foi.user, **self.kwargs ) eq_(response.status_code, 302) eq_(response.url, self.foi.get_absolute_url() + '#share')
def test_not_owner(self): """Users who are not the owner should be redirected to the FOI detail view.""" not_owner = UserFactory() response = http_get_response(self.url, self.view, not_owner, **self.kwargs) eq_(response.status_code, 302) eq_(response.url, self.comm.request.get_absolute_url())
def test_anonymous(self): """Logged out users should be redirected to the login view.""" response = http_get_response(self.url, self.view, **self.kwargs) eq_(response.status_code, 302) eq_(response.url, (reverse('login', host='foiamachine') + '?next=' + reverse('comm-delete', host='foiamachine', kwargs=self.kwargs)))
def test_get_ok(self): """The view should return 200 if the foia is viewable to the user.""" ok_(self.foia.has_perm(self.foia.user, 'view'), 'The user should be able to view the request') response = http_get_response(self.url, self.view, self.foia.user, **self.kwargs) eq_(response.status_code, 200, 'The view should return 200.')
def test_render_task_list(self): """The list should have rendered task widgets in its object_list context variable""" response = http_get_response( self.url, self.view, self.user, follow=True ) obj_list = response.context_data['object_list'] ok_(obj_list, 'Object list should not be empty.')
def test_not_staff_not_ok(self): response = http_get_response(self.url, self.view, UserFactory(), follow=True) eq_(response.status_code, 302) eq_(response.url, '/accounts/login/?next=%s' % self.url)
def test_public_views(self): """Test public views while not logged in""" response = http_get_response(reverse('acct-login'), login) eq_(response.status_code, 200) # account overview page response = http_get_response(reverse('accounts'), views.AccountsView.as_view()) eq_(response.status_code, 302) # profile page request_factory = RequestFactory() request = request_factory.get(self.user.profile.get_absolute_url()) request = mock_middleware(request) request.user = AnonymousUser() response = views.ProfileView.as_view()(request, username=self.user.username) eq_(response.status_code, 200)
def test_anonymous(self): """Logged out users cannot edit projects.""" response = http_get_response(self.url, self.view, AnonymousUser()) redirect_url = reverse('acct-login') + '?next=' + self.url eq_(response.status_code, 302, 'The user should be redirected.') eq_(response.url, redirect_url, 'The user should be redirected to the login page.')
def test_get(self): """Users should be able to GET the ProjectCrowdfundView.""" user = UserFactory(is_staff=True) response = http_get_response( self.url, self.view, user, slug=self.project.slug, pk=self.project.pk ) eq_(response.status_code, 200)
def test_unauthorized_get(self): """Logged out users trying to access the notifications view should be redirected to the login view.""" response = http_get_response(self.url, self.view) eq_(response.status_code, 302, 'The view should redirect.') ok_( reverse('acct-login') in response.url, 'Logged out users should be redirected to the login view.')
def test_public_user(self): """Users should be able to see public projects""" self.project.private = False self.project.approved = True self.project.save() response = http_get_response(self.url, self.view, self.user, **self.kwargs) eq_(response.status_code, 200)
def test_staff_ok(self): response = http_get_response(self.url, self.view, self.user, follow=True) eq_(response.status_code, 200, ('Should respond to staff requests for task list page with 200.' ' Actually responds with %d' % response.status_code))
def test_anonymous(self): """Anonymous users cannot delete projects.""" response = http_get_response(self.url, self.view, AnonymousUser(), **self.kwargs) redirect_url = reverse('acct-login') + '?next=' + self.url eq_(response.status_code, 302, 'The user should be redirected.') eq_(response.url, redirect_url, 'The user should be reidrected to the login screen.')
def test_unique_for_jurisdiction(self): """Two exemptions may have the same name, as long as they belong to different jurisdictions.""" another_jurisdiction = factories.StateJurisdictionFactory() ok_(self.exemption.jurisdiction is not another_jurisdiction) factories.ExemptionFactory(jurisdiction=another_jurisdiction) response = http_get_response(self.url, self.view, **self.kwargs) eq_(response.status_code, 200)
def test_anonymous(self): """Logged out users should be redirected to the login view.""" response = http_get_response(self.url, self.view, **self.kwargs) eq_(response.status_code, 302) eq_( response.url, (reverse("login", host="foiamachine") + "?next=" + reverse("comm-delete", host="foiamachine", kwargs=self.kwargs)), )
def test_basic(self): """Basic users should be able to GET the ProjectCreateView.""" user = UserFactory() response = http_get_response(self.url, self.view, user) eq_( response.status_code, 200, "Basic users should be able to GET the ProjectCreateView.", )
def test_unauthenticated(self): """Unauthenticated users should be redirected to the login screen.""" response = http_get_response(self.url, self.view) eq_(response.status_code, 302, "The view should redirect.") eq_( response.url, reverse("login", host="foiamachine") + "?next=" + self.url, "The redirect should point to the login view, with this as the next view.", )
def test_federal_exemptions(self): """An exemption at the federal level should return 200.""" fed = factories.FederalJurisdictionFactory() exemption = factories.ExemptionFactory(jurisdiction=fed) url = exemption.get_absolute_url() kwargs = exemption.jurisdiction.get_slugs() kwargs.update({"slug": exemption.slug, "pk": exemption.pk}) response = http_get_response(url, self.view, **kwargs) eq_(response.status_code, 200)
def test_ok(self): """The view should return a 200 OK status.""" exemption = factories.ExemptionFactory() url = exemption.get_absolute_url() kwargs = exemption.jurisdiction.get_slugs() kwargs.update({"slug": exemption.slug, "pk": exemption.pk}) response = http_get_response(url, self.view, **kwargs) eq_(response.status_code, 200)
def test_unauthenticated(self): """Unauthenticated users should be redirected to the login screen.""" response = http_get_response(self.url, self.view) eq_(response.status_code, 302, 'The view should redirect.') eq_( response.url, reverse('login', host='foiamachine') + '?next=' + self.url, 'The redirect should point to the login view, with this as the next view.' )
def test_get(self): """The view should provide a list of notifications for the user.""" response = http_get_response(self.url, self.view, self.user) eq_(response.status_code, 200, 'The view should return OK.') object_list = response.context_data['object_list'] ok_(self.unread_notification in object_list, 'The context should contain the unread notification.') ok_(self.read_notification not in object_list, 'The context should not contain the read notification.')
def test_state_exemptions(self): """An exemption at the state level should return 200.""" state = factories.StateJurisdictionFactory() exemption = factories.ExemptionFactory(jurisdiction=state) url = exemption.get_absolute_url() kwargs = exemption.jurisdiction.get_slugs() kwargs.update({'slug': exemption.slug, 'pk': exemption.pk}) response = http_get_response(url, self.view, **kwargs) eq_(response.status_code, 200)
def test_anonymous(self): """Logged out users should not be able to GET the ProjectCreateView.""" response = http_get_response(self.url, self.view, AnonymousUser()) eq_( response.status_code, 302, 'Anonymous users should not be able to GET the ProjectCreateView.') redirect_url = reverse('acct-login') + '?next=' + reverse( 'project-create') eq_(response.url, redirect_url, 'The user should be redirected to the login page.')
def test_pending_contributor(self): """Contributors should be able to see pending projects""" self.project.private = False self.project.approved = False self.project.save() response = http_get_response( self.url, self.view, self.contributor, **self.kwargs ) eq_(response.status_code, 200)
def test_login_required(self): """Only registered users may see the registration completion page.""" response = http_get_response( reverse('accounts-complete-registration'), views.RegistrationCompletionView.as_view()) eq_(response.status_code, 302, 'Logged out users should be redirected.') ok_( reverse('acct-login') in response.url, 'Logged out users should be redirected to the login view.')
def test_list(self): """The list should only contain approved agencies""" approved_agency = AgencyFactory() unapproved_agency = AgencyFactory(status='pending') response = http_get_response(reverse('agency-list'), AgencyList.as_view()) agency_list = response.context_data['object_list'] ok_(approved_agency in agency_list, 'Approved agencies should be listed.') ok_(unapproved_agency not in agency_list, 'Unapproved agencies should not be listed.')
def test_get_and_verify(self): """Getting the view with a verification key should verify the user's email.""" key = self.user.profile.generate_confirmation_key() response = http_get_response( reverse('accounts-complete-registration') + '?key=' + key, views.RegistrationCompletionView.as_view(), user=self.user) self.user.profile.refresh_from_db() eq_(response.status_code, 200, 'The view should respond 200 OK') ok_(self.user.profile.email_confirmed, 'The user\'s email address should be confirmed.')