Example #1
0
 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)
Example #2
0
 def test_auth_views(self):
     """Test private views while logged in"""
     response = http_get_response(reverse('acct-my-profile'), views.profile,
                                  self.user)
     eq_(response.status_code, 302,
         'Logged in user may view their own profile.')
     response = http_get_response(reverse('acct-settings'),
                                  views.profile_settings, self.user)
     eq_(response.status_code, 200,
         'Logged in user may view their own settings.')
Example #3
0
 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.profile,
                                  self.user)
     eq_(response.status_code, 302,
         'Logged in user may view their own profile.')
     response = http_get_response(reverse('acct-settings'),
                                  views.profile_settings, self.user)
     eq_(response.status_code, 200,
         'Logged in user may view their own settings.')
Example #4
0
 def test_not_staff_not_ok(self):
     response = http_get_response(self.url,
                                  self.view,
                                  factories.UserFactory(),
                                  follow=True)
     eq_(response.status_code, 302)
     eq_(response.url, '/accounts/login/?next=%s' % self.url)
Example #5
0
 def test_get_ok(self):
     """The view should return 200 if the foia is viewable to the user."""
     ok_(self.foia.viewable_by(self.foia.user),
         '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.')
Example #6
0
 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)))
Example #7
0
 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())
Example #8
0
 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.')
Example #9
0
 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)
Example #10
0
 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.')
Example #11
0
 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.')
Example #12
0
 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))
Example #13
0
 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.')
Example #14
0
 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.'
     )
Example #15
0
 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)
Example #16
0
 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.')
Example #17
0
 def test_list(self):
     """The list should only contain approved agencies"""
     # pylint: disable=no-self-use
     approved_agency = factories.AgencyFactory()
     unapproved_agency = factories.AgencyFactory(status='pending')
     response = http_get_response(reverse('agency-list'), agency.views.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.')
Example #18
0
 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,
         'Login page should be publicly visible.')
     # account overview page
     response = http_get_response(reverse('accounts'),
                                  views.AccountsView.as_view())
     eq_(response.status_code, 200,
         'Top level accounts page should be publicly visible.')
     # profile page
     request_factory = RequestFactory()
     request = request_factory.get(self.user.profile.get_absolute_url())
     request = mock_middleware(request)
     request.user = AnonymousUser()
     response = views.profile(request, self.user.username)
     eq_(response.status_code, 200,
         'User profiles should be publicly visible.')
Example #19
0
 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.')
Example #20
0
 def test_login_required(self):
     """Only registered users may see the registration completion page."""
     # pylint: disable=no-self-use
     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.')
Example #21
0
 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.')
Example #22
0
 def test_pending(self):
     """Projects that are pending review should reject access to the Publish view."""
     pending_project = factories.ProjectFactory(private=False,
                                                approved=False)
     pending_project.contributors.add(self.contributor)
     response = http_get_response(
         self.url, self.view, self.contributor, **{
             'slug': pending_project.slug,
             'pk': pending_project.pk
         })
     eq_(response.status_code, 302)
     eq_(response.url, pending_project.get_absolute_url(),
         'The user should be redirected to the project.')
Example #23
0
 def test_get_question(self):
     """Try getting the detail page for a Question with an unread notification."""
     question = QuestionFactory()
     view = QuestionDetail.as_view()
     # Create a notification for the question
     action = new_action(UserFactory(), 'answered', target=question)
     notification = notify(self.user, action)[0]
     ok_(not notification.read, 'The notification should be unread.')
     # Try getting the view as the user
     response = http_get_response(question.get_absolute_url(),
                                  view,
                                  self.user,
                                  pk=question.pk,
                                  slug=question.slug)
     eq_(response.status_code, 200, 'The view should respond 200 OK.')
     # Check that the notification has been read.
     notification.refresh_from_db()
     ok_(notification.read, 'The notification should be marked as read.')
Example #24
0
 def test_get_foia(self):
     """Try getting the detail page for a FOIA Request with an unread notification."""
     agency = AgencyFactory()
     foia = FOIARequestFactory(agency=agency)
     view = FOIARequestDetail.as_view()
     # Create a notification for the request
     action = new_action(agency, 'completed', target=foia)
     notification = notify(self.user, action)[0]
     ok_(not notification.read, 'The notification should be unread.')
     # Try getting the view as the user
     response = http_get_response(foia.get_absolute_url(),
                                  view,
                                  self.user,
                                  idx=foia.pk,
                                  slug=foia.slug,
                                  jidx=foia.jurisdiction.pk,
                                  jurisdiction=foia.jurisdiction.slug)
     eq_(response.status_code, 200, 'The view should response 200 OK.')
     # Check that the notification has been read.
     notification.refresh_from_db()
     ok_(notification.read, 'The notification should be marked as read.')
Example #25
0
 def test_unapproved_not_found(self):
     """An unapproved agency should return a 404 response."""
     self.agency.status = 'pending'
     self.agency.save()
     http_get_response(self.url, self.view, self.user, **self.kwargs)
Example #26
0
 def test_approved_ok(self):
     """An approved agency should return an 200 response."""
     response = http_get_response(self.url, self.view, self.user, **self.kwargs)
     eq_(response.status_code, 200)
Example #27
0
 def test_staff(self):
     """Staff users should be able to edit projects."""
     staff_user = factories.UserFactory(is_staff=True)
     response = http_get_response(self.url, self.view, staff_user,
                                  **self.kwargs)
     eq_(response.status_code, 200)
Example #28
0
 def test_basic(self):
     """Basic users should not be able to GET the ProjectCreateView."""
     user = factories.UserFactory()
     response = http_get_response(self.url, self.view, user)
     eq_(response.status_code, 200,
         'Basic users should be able to GET the ProjectCreateView.')
Example #29
0
 def test_get(self):
     """The view should render, of course!"""
     response = http_get_response(self.url, self.view, self.user,
                                  **self.kwargs)
     eq_(response.status_code, 200, 'The view should return 200.')
Example #30
0
 def test_basic(self):
     """Basic users should not be able to delete projects."""
     user = factories.UserFactory()
     http_get_response(self.url, self.view, user, **self.kwargs)