예제 #1
0
 def test_fee_rate(self):
     """
     Jurisdictions should report the rate at which requests have fees.
     State jurisdictions should include fee rates of local jurisdictions.
     """
     FOIARequestFactory(jurisdiction=self.state, status='ack', price=0)
     FOIARequestFactory(jurisdiction=self.local, status='ack', price=1.00)
     eq_(self.state.fee_rate(), 50.0)
     eq_(self.local.fee_rate(), 100.0)
예제 #2
0
 def test_requests(self):
     """Projects should keep a list of relevant FOIA requests."""
     request1 = FOIARequestFactory()
     request2 = FOIARequestFactory()
     self.project.requests.add(request1, request2)
     ok_(request1 in self.project.requests.all())
     ok_(request2 in self.project.requests.all())
     self.project.articles.clear()
     eq_(len(self.project.articles.all()), 0)
예제 #3
0
 def test_success_rate(self):
     """
     Jurisdictions should report their success rate: completed/filed.
     State jurisdictions should include success rates of local jurisdictions.
     """
     today = date.today()
     FOIARequestFactory(jurisdiction=self.state,
                        status='done',
                        date_done=today)
     FOIARequestFactory(jurisdiction=self.local, status='ack')
     eq_(self.state.success_rate(), 50.0)
     eq_(self.local.success_rate(), 0.0)
예제 #4
0
 def test_total_pages(self):
     """
     Jurisdictions should report the pages returned across their requests.
     State jurisdictions should include pages from their local jurisdictions.
     """
     page_count = 10
     local_foia = FOIARequestFactory(jurisdiction=self.local)
     state_foia = FOIARequestFactory(jurisdiction=self.state)
     local_foia.files.add(FOIAFileFactory(pages=page_count))
     state_foia.files.add(FOIAFileFactory(pages=page_count))
     eq_(self.local.total_pages(), page_count)
     eq_(self.state.total_pages(), 2 * page_count)
예제 #5
0
    def test_foia_followup(self):
        """Make sure the follow up date is set correctly"""
        # pylint: disable=protected-access
        foia = FOIARequestFactory(
            date_submitted=datetime.date.today(),
            status='processed',
            jurisdiction__level='s',
            jurisdiction__days=10,
        )
        FOIACommunicationFactory(
            foia=foia,
            response=True,
        )
        foia.followup()
        nose.tools.assert_in('I can expect', mail.outbox[-1].body)
        nose.tools.eq_(
            foia.date_followup,
            datetime.date.today() + datetime.timedelta(foia._followup_days()))

        nose.tools.eq_(foia._followup_days(), 15)

        num_days = 365
        foia.date_estimate = datetime.date.today() + datetime.timedelta(
            num_days)
        foia.followup()
        nose.tools.assert_in('I am still', mail.outbox[-1].body)
        nose.tools.eq_(foia._followup_days(), num_days)

        foia.date_estimate = datetime.date.today()
        foia.followup()
        nose.tools.assert_in('check on the status', mail.outbox[-1].body)
        nose.tools.eq_(foia._followup_days(), 15)
예제 #6
0
 def setUp(self):
     agency = AgencyFactory()
     self.owner = UserFactory()
     self.follower = UserFactory()
     self.request = FOIARequestFactory(user=self.owner, agency=agency)
     follow(self.follower, self.request)
     self.action = new_action(agency, 'completed', target=self.request)
예제 #7
0
    def test_normal(self):
        """Test a normal succesful response"""

        foia = FOIARequestFactory(status='ack')
        from_name = 'Smith, Bob'
        from_email = '*****@*****.**'
        from_ = '"%s" <%s>' % (from_name, from_email)
        to_ = ('%[email protected], "Doe, John" <*****@*****.**>' %
               foia.get_mail_id())
        subject = 'Test subject'
        text = 'Test normal.'
        signature = '-Charlie Jones'

        self.mailgun_route(from_, to_, subject, text, signature)
        foia.refresh_from_db()

        last_comm = foia.communications.last()
        nose.tools.eq_(last_comm.communication, '%s\n%s' % (text, signature))
        nose.tools.eq_(last_comm.subject, subject)
        nose.tools.eq_(last_comm.from_who, from_name)
        nose.tools.eq_(last_comm.priv_from_who, from_)
        nose.tools.eq_(last_comm.to_who, foia.user.get_full_name())
        nose.tools.eq_(last_comm.priv_to_who, to_)
        nose.tools.eq_(last_comm.response, True)
        nose.tools.eq_(last_comm.full_html, False)
        nose.tools.eq_(last_comm.delivered, 'email')
        nose.tools.ok_(last_comm.rawemail)
        nose.tools.eq_(last_comm.responsetask_set.count(), 1)
        nose.tools.eq_(foia.email, from_email)
        nose.tools.eq_(foia.other_emails, '*****@*****.**')
        nose.tools.eq_(foia.status, 'processed')
예제 #8
0
    def test_allowed_email(self):
        """Test allowed email function"""
        foia = FOIARequestFactory(
            email='*****@*****.**',
            other_emails='*****@*****.**',
            agency__email='*****@*****.**',
            agency__other_emails='*****@*****.**',
        )
        WhitelistDomain.objects.create(domain='whitehat.edu')

        allowed_emails = [
            '*****@*****.**',  # same domain
            '*****@*****.**',  # case insensitive
            '*****@*****.**',  # other email
            '*****@*****.**',  # agency email
            '*****@*****.**',  # any government tld
            '*****@*****.**',  # any government tld
            '*****@*****.**',  # white listed domain
        ]
        not_allowed_emails = [
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
            '*****@*****.**',
        ]
        for email in allowed_emails:
            nose.tools.ok_(_allowed_email(email, foia))
        for email in not_allowed_emails:
            nose.tools.assert_false(_allowed_email(email, foia))
        # non foia test - any agency email
        nose.tools.ok_(_allowed_email('*****@*****.**'))
예제 #9
0
    def test_bad_verify(self):
        """Test an improperly signed message"""

        foia = FOIARequestFactory(block_incoming=True)
        to_ = '*****@*****.**' % foia.get_mail_id()
        response = self.mailgun_route(to_=to_, sign=False)
        nose.tools.eq_(response.status_code, 403)
예제 #10
0
    def test_foia_submit_views(self):
        """Test submitting a FOIA request"""

        foia = FOIARequestFactory(
            status='started',
            user=User.objects.get(username='******'),
        )
        FOIACommunicationFactory(foia=foia)
        self.client.login(username='******', password='******')

        foia_data = {
            'title': foia.title,
            'request': 'updated request',
            'submit': 'Submit',
            'agency': foia.agency.pk,
            'combo-name': foia.agency.name,
        }
        kwargs = {
            'jurisdiction': foia.jurisdiction.slug,
            'jidx': foia.jurisdiction.pk,
            'idx': foia.pk,
            'slug': foia.slug,
        }
        draft = reverse('foia-draft', kwargs=kwargs)
        detail = reverse('foia-detail', kwargs=kwargs)
        post_allowed(self.client, draft, foia_data, detail)

        foia.refresh_from_db()
        nose.tools.ok_(foia.first_request().startswith('updated request'))
        nose.tools.eq_(foia.status, 'ack')
예제 #11
0
파일: tests.py 프로젝트: pjsier/muckrock
 def test_session_success(self):
     """Test a successful post to the session view"""
     foia = FOIARequestFactory()
     attachments = OutboundAttachmentFactory.create_batch(
         3,
         foia=foia,
         user=foia.user,
         sent=False,
     )
     OutboundAttachmentFactory.create_batch(
         3,
         foia=foia,
         user=foia.user,
         sent=True,
     )
     OutboundAttachmentFactory.create_batch(3)
     request_factory = RequestFactory()
     request = request_factory.get(
         reverse('fine-uploader-session'),
         {'foia_id': foia.pk},
     )
     request.user = foia.user
     response = views.session(request)
     eq_(response.status_code, 200)
     attm_data = json.loads(response.content)
     attm_data.sort(key=lambda f: f['uuid'])
     attachments.sort(key=lambda f: f.pk)
     for attm_datum, attm in zip(attm_data, attachments):
         eq_(attm_datum['name'], attm.name())
         eq_(attm_datum['uuid'], attm.pk)
         eq_(attm_datum['size'], attm.ffile.size)
         eq_(attm_datum['s3Key'], attm.ffile.name)
예제 #12
0
 def setUp(self):
     self.foia = FOIARequestFactory(status='payment')
     self.url = reverse('foia-crowdfund',
                        args=(self.foia.jurisdiction.slug,
                              self.foia.jurisdiction.id, self.foia.slug,
                              self.foia.id))
     self.request_factory = RequestFactory()
     self.view = crowdfund_request
예제 #13
0
 def test_viewer_permission(self):
     """Viewers should be able to see the request if it is embargoed."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     viewer = UserFactory()
     normie = UserFactory()
     embargoed_foia.add_viewer(viewer)
     assert_true(embargoed_foia.viewable_by(viewer))
     assert_false(embargoed_foia.viewable_by(normie))
예제 #14
0
 def test_average_response_time(self):
     """
     Jurisdictions should report their average response time.
     State jurisdictions should include avg. response time of their local jurisdictions.
     """
     today = date.today()
     state_duration = 12
     local_duration = 6
     FOIARequestFactory(jurisdiction=self.state,
                        date_done=today,
                        date_submitted=today - timedelta(state_duration))
     FOIARequestFactory(jurisdiction=self.local,
                        date_done=today,
                        date_submitted=today - timedelta(local_duration))
     eq_(self.state.average_response_time(),
         (local_duration + state_duration) / 2)
     eq_(self.local.average_response_time(), local_duration)
예제 #15
0
 def test_viewer_permission(self):
     """Viewers should be able to see the request if it is embargoed."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     viewer = UserFactory()
     normie = UserFactory()
     embargoed_foia.add_viewer(viewer)
     nose.tools.assert_true(embargoed_foia.has_perm(viewer, 'view'))
     nose.tools.assert_false(embargoed_foia.has_perm(normie, 'view'))
예제 #16
0
 def test_promote_viewer(self):
     """Editors should be able to promote viewers to editors."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     viewer = UserFactory()
     embargoed_foia.add_viewer(viewer)
     assert_true(embargoed_foia.viewable_by(viewer))
     assert_false(embargoed_foia.editable_by(viewer))
     embargoed_foia.promote_viewer(viewer)
     assert_true(embargoed_foia.editable_by(viewer))
예제 #17
0
 def test_demote_editor(self):
     """Editors should be able to demote editors to viewers."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     editor = UserFactory()
     embargoed_foia.add_editor(editor)
     assert_true(embargoed_foia.viewable_by(editor))
     assert_true(embargoed_foia.editable_by(editor))
     embargoed_foia.demote_editor(editor)
     assert_false(embargoed_foia.editable_by(editor))
예제 #18
0
 def test_demote_editor(self):
     """Editors should be able to demote editors to viewers."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     editor = UserFactory()
     embargoed_foia.add_editor(editor)
     nose.tools.assert_true(embargoed_foia.has_perm(editor, 'view'))
     nose.tools.assert_true(embargoed_foia.has_perm(editor, 'change'))
     embargoed_foia.demote_editor(editor)
     nose.tools.assert_false(embargoed_foia.has_perm(editor, 'change'))
예제 #19
0
 def test_promote_viewer(self):
     """Editors should be able to promote viewers to editors."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     viewer = UserFactory()
     embargoed_foia.add_viewer(viewer)
     nose.tools.assert_true(embargoed_foia.has_perm(viewer, 'view'))
     nose.tools.assert_false(embargoed_foia.has_perm(viewer, 'change'))
     embargoed_foia.promote_viewer(viewer)
     nose.tools.assert_true(embargoed_foia.has_perm(viewer, 'change'))
예제 #20
0
 def test_access_key(self):
     """Editors should be able to generate a secure access key to view an embargoed request."""
     embargoed_foia = FOIARequestFactory(embargo=True)
     access_key = embargoed_foia.generate_access_key()
     assert_true(access_key == embargoed_foia.access_key,
         'The key in the URL should match the key saved to the request.')
     embargoed_foia.generate_access_key()
     assert_false(access_key == embargoed_foia.access_key,
         'After regenerating the link, the key should no longer match.')
예제 #21
0
 def setUp(self):
     self.endpoint = '/exemption/submit/'
     self.factory = APIRequestFactory()
     self.view = ExemptionViewSet.as_view({'post': 'submit'})
     self.user = UserFactory()
     self.foia = FOIARequestFactory(user=self.user)
     self.data = {
         'foia': self.foia.id,
         'language': 'Lorem ipsum',
     }
예제 #22
0
 def setUp(self):
     agency = AgencyFactory(appeal_agency=AppealAgencyFactory())
     self.foia = FOIARequestFactory(agency=agency)
     self.view = Detail.as_view()
     self.url = self.foia.get_absolute_url()
     self.kwargs = {
         'jurisdiction': self.foia.jurisdiction.slug,
         'jidx': self.foia.jurisdiction.id,
         'slug': self.foia.slug,
         'idx': self.foia.id
     }
예제 #23
0
 def setUp(self):
     self.factory = RequestFactory()
     self.foia = FOIARequestFactory()
     self.creator = self.foia.user
     self.editor = UserFactory()
     self.viewer = UserFactory()
     self.staff = UserFactory(is_staff=True)
     self.normie = UserFactory()
     self.foia.add_editor(self.editor)
     self.foia.add_viewer(self.viewer)
     self.foia.save()
예제 #24
0
 def test_idential_different_requests(self):
     """An identical action on a different request should not mark anything as read."""
     other_request = FOIARequestFactory(user=self.owner, agency=self.request.agency)
     other_action = new_action(self.request.agency, 'completed', target=other_request)
     unread_count = self.owner.notifications.get_unread().count()
     self.request.notify(self.action)
     eq_(self.owner.notifications.get_unread().count(), unread_count + 1,
         'The user should have one unread notification.')
     other_request.notify(other_action)
     eq_(self.owner.notifications.get_unread().count(), unread_count + 2,
         'The user should have two unread notifications.')
예제 #25
0
파일: tests.py 프로젝트: pjsier/muckrock
 def test_success_bad_data(self):
     """Test a post to the success view with missing data"""
     foia = FOIARequestFactory()
     request_factory = RequestFactory()
     request = request_factory.post(
         reverse('fine-uploader-success'),
         {'foia_id': foia.pk},
     )
     request.user = foia.user
     response = views.success(request)
     eq_(response.status_code, 400)
예제 #26
0
    def test_bad_strip(self):
        """Test an improperly stripped message"""

        foia = FOIARequestFactory()
        to_ = '*****@*****.**' % foia.get_mail_id()
        text = ''
        body = 'Here is the full body.'
        self.mailgun_route(to_=to_, text=text, body=body)

        last_comm = foia.communications.last()
        nose.tools.eq_(last_comm.communication, body)
예제 #27
0
파일: tests.py 프로젝트: pjsier/muckrock
 def test_success_bad_user(self):
     """Test a post to the success view with a bad user"""
     foia = FOIARequestFactory()
     request_factory = RequestFactory()
     request = request_factory.post(
         reverse('fine-uploader-success'),
         {
             'foia_id': foia.pk,
             'key': 'file_key'
         },
     )
     request.user = UserFactory()
     response = views.success(request)
     eq_(response.status_code, 403)
예제 #28
0
파일: tests.py 프로젝트: pjsier/muckrock
 def test_session_bad_user(self):
     """Test a post to the session view with a bad user"""
     foia = FOIARequestFactory()
     request_factory = RequestFactory()
     request = request_factory.get(
         reverse('fine-uploader-session'),
         {
             'foia_id': foia.pk,
             'name': 'file_name',
             'key': 'file_key'
         },
     )
     request.user = UserFactory()
     response = views.session(request)
     eq_(response.status_code, 403)
예제 #29
0
    def test_foia_viewable_org_share(self):
        """Test all the viewable and embargo functions"""
        org = OrganizationFactory()
        org.owner.profile.organization = org
        foia = FOIARequestFactory(
            embargo=True,
            user__profile__organization=org,
        )
        foias = FOIARequest.objects.get_viewable(org.owner)
        nose.tools.assert_not_in(foia, foias)

        foia.user.profile.org_share = True
        foia.user.profile.save()
        foias = FOIARequest.objects.get_viewable(org.owner)
        nose.tools.assert_in(foia, foias)
예제 #30
0
파일: tests.py 프로젝트: pjsier/muckrock
 def test_success_success(self):
     """Test a successful post to the success view"""
     foia = FOIARequestFactory()
     request_factory = RequestFactory()
     request = request_factory.post(
         reverse('fine-uploader-success'),
         {
             'foia_id': foia.pk,
             'key': 'file_key'
         },
     )
     request.user = foia.user
     response = views.success(request)
     eq_(response.status_code, 200)
     attachment = OutboundAttachment.objects.get(foia=foia)
     eq_(attachment.ffile.name, 'file_key')
     eq_(attachment.user, foia.user)
     assert_false(attachment.sent)