Ejemplo n.º 1
0
 def test_clone_multi(self, mock_upload):
     """Should duplicate the communication to each request in the list."""
     first_foia = FOIARequestFactory()
     second_foia = FOIARequestFactory()
     third_foia = FOIARequestFactory()
     comm_count = FOIACommunication.objects.count()
     clones = self.comm.clone(
         [first_foia, second_foia, third_foia],
         self.user,
     )
     # + 3 communications
     eq_(
         FOIACommunication.objects.count(), comm_count + 3,
         'Should clone the request twice.'
     )
     ok_(
         clones[0].pk is not clones[1].pk is not clones[2].pk,
         'The returned list should contain unique communcation objects.'
     )
     # a move log should be generated for each cloned request
     for clone in clones:
         ok_(
             CommunicationMoveLog.objects.filter(
                 communication=clone,
                 foia=self.comm.foia,
                 user=self.user,
             ).exists()
         )
     mock_upload.assert_called()
Ejemplo n.º 2
0
 def setUp(self):
     self.foia1 = FOIARequestFactory()
     self.foia2 = FOIARequestFactory()
     self.comm = FOIACommunicationFactory(foia=self.foia1)
     self.file = FOIAFileFactory(comm=self.comm)
     eq_(self.comm.files.count(), 1)
     self.user = UserFactory()
Ejemplo n.º 3
0
 def test_composer_detail_multi_submitted(self):
     """Composer shows its own page if multiple foias"""
     foia = FOIARequestFactory(
         composer__status='submitted',
         composer__datetime_submitted=timezone.now(),
     )
     FOIARequestFactory(composer=foia.composer)
     composer = foia.composer
     request = self.request_factory.get(
         reverse(
             'foia-composer-detail',
             kwargs={
                 'slug': composer.slug,
                 'idx': composer.pk
             }
         )
     )
     request.user = UserFactory()
     request = mock_middleware(request)
     response = ComposerDetail.as_view()(
         request,
         slug=composer.slug,
         idx=composer.pk,
     )
     eq_(response.status_code, 200)
     eq_(response.template_name, ['foia/foiacomposer_detail.html'])
Ejemplo n.º 4
0
    def test_foia_viewable(self):
        """Test all the viewable and embargo functions"""

        user1 = UserFactory()
        user2 = UserFactory()

        foias = [
            FOIARequestFactory(
                composer__user=user1,
                status='done',
                embargo=False,
            ),
            FOIARequestFactory(
                composer__user=user1,
                status='done',
                embargo=True,
            ),
            FOIARequestFactory(
                composer__user=user1,
                status='done',
                embargo=True,
            ),
        ]
        foias[2].add_viewer(user2)

        # check manager get_viewable against view permission
        viewable_foias = FOIARequest.objects.get_viewable(user1)
        for foia in FOIARequest.objects.all():
            if foia in viewable_foias:
                nose.tools.assert_true(foia.has_perm(user1, 'view'))
            else:
                nose.tools.assert_false(foia.has_perm(user1, 'view'))

        viewable_foias = FOIARequest.objects.get_viewable(user2)
        for foia in FOIARequest.objects.all():
            if foia in viewable_foias:
                nose.tools.assert_true(foia.has_perm(user2, 'view'))
            else:
                nose.tools.assert_false(foia.has_perm(user2, 'view'))

        viewable_foias = FOIARequest.objects.get_public()
        for foia in FOIARequest.objects.all():
            if foia in viewable_foias:
                nose.tools.assert_true(foia.has_perm(AnonymousUser(), 'view'))
            else:
                nose.tools.assert_false(foia.has_perm(AnonymousUser(), 'view'))

        nose.tools.assert_true(foias[0].has_perm(user1, 'view'))
        nose.tools.assert_true(foias[1].has_perm(user1, 'view'))
        nose.tools.assert_true(foias[2].has_perm(user1, 'view'))

        nose.tools.assert_true(foias[0].has_perm(user2, 'view'))
        nose.tools.assert_false(foias[1].has_perm(user2, 'view'))
        nose.tools.assert_true(foias[2].has_perm(user2, 'view'))

        nose.tools.assert_true(foias[0].has_perm(AnonymousUser(), 'view'))
        nose.tools.assert_false(foias[1].has_perm(AnonymousUser(), 'view'))
        nose.tools.assert_false(foias[2].has_perm(AnonymousUser(), 'view'))
Ejemplo n.º 5
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(agency__jurisdiction=self.state, status="ack", price=0)
     FOIARequestFactory(agency__jurisdiction=self.local, status="ack", price=1.00)
     eq_(self.state.fee_rate(), 50.0)
     eq_(self.local.fee_rate(), 100.0)
Ejemplo n.º 6
0
    def test_get_viewable_partial_embargoed(self):
        """Test get viewable for a partially embargoed composer"""

        foia = FOIARequestFactory(composer__status="filed", embargo=True)
        FOIARequestFactory(composer=foia.composer, embargo=False)

        assert_true(FOIAComposer.objects.get_viewable(self.staff).exists())
        assert_true(FOIAComposer.objects.get_viewable(self.user).exists())
        assert_true(FOIAComposer.objects.get_viewable(self.anon).exists())
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
 def test_multi_clone(self):
     """Test cloning a multirequest"""
     foia = FOIARequestFactory(composer__status="filed", embargo=False)
     FOIARequestFactory(composer=foia.composer)
     form = BaseComposerForm(
         {"action": "save", "parent": foia.composer.pk, "tags": ""},
         user=foia.composer.user,
         request=None,
     )
     ok_(form.is_valid())
Ejemplo n.º 9
0
 def test_success_rate(self):
     """
     Jurisdictions should report their success rate: completed/filed.
     State jurisdictions should include success rates of local jurisdictions.
     """
     FOIARequestFactory(
         agency__jurisdiction=self.state, status="done", datetime_done=timezone.now()
     )
     FOIARequestFactory(agency__jurisdiction=self.local, status="ack")
     eq_(self.state.success_rate(), 50.0)
     eq_(self.local.success_rate(), 0.0)
Ejemplo n.º 10
0
 def test_move(self):
     """Should move the communication to the listed requests and create a
     ResponseTask for each new communication.
     """
     foia1 = FOIARequestFactory()
     foia2 = FOIARequestFactory()
     foia3 = FOIARequestFactory()
     count_response_tasks = ResponseTask.objects.count()
     self.task.move([foia1.pk, foia2.pk, foia3.pk], self.user)
     eq_(ResponseTask.objects.count(), count_response_tasks + 3,
         'Reponse tasks should be created for each communication moved.')
Ejemplo n.º 11
0
    def test_follow(self):
        """Test bulk following"""
        public_foia = FOIARequestFactory()
        private_foia = FOIARequestFactory(embargo=True)
        user = UserFactory()

        RequestList()._follow(
            FOIARequest.objects.filter(
                pk__in=[public_foia.pk, private_foia.pk]),
            user,
            {},
        )

        ok_(is_following(user, public_foia))
        assert_false(is_following(user, private_foia))
Ejemplo n.º 12
0
    def test_extend_embargo(self):
        """Test bulk embargo extending"""
        tomorrow = date.today() + timedelta(1)
        next_month = date.today() + timedelta(30)
        user = UserFactory(profile__acct_type='pro')
        other_foia = FOIARequestFactory()
        public_foia = FOIARequestFactory(
            composer__user=user,
            embargo=False,
            status='ack',
        )
        embargo_foia = FOIARequestFactory(
            composer__user=user,
            embargo=True,
            status='ack',
        )
        embargo_done_foia = FOIARequestFactory(
            composer__user=user,
            embargo=True,
            status='done',
            date_embargo=tomorrow,
        )

        MyRequestList()._extend_embargo(
            FOIARequest.objects.filter(
                pk__in=[
                    other_foia.pk,
                    public_foia.pk,
                    embargo_foia.pk,
                    embargo_done_foia.pk,
                ]
            ),
            user,
            {},
        )

        other_foia.refresh_from_db()
        public_foia.refresh_from_db()
        embargo_foia.refresh_from_db()
        embargo_done_foia.refresh_from_db()

        assert_false(other_foia.embargo)
        ok_(public_foia.embargo)
        assert_is_none(public_foia.date_embargo)
        ok_(embargo_foia.embargo)
        assert_is_none(embargo_foia.date_embargo)
        ok_(embargo_done_foia.embargo)
        eq_(embargo_done_foia.date_embargo, next_month)
Ejemplo n.º 13
0
 def setUp(self):
     self.endpoint = "/exemption/submit/"
     self.factory = APIRequestFactory()
     self.view = ExemptionViewSet.as_view({"post": "submit"})
     self.user = UserFactory()
     self.foia = FOIARequestFactory(composer__user=self.user)
     self.data = {"foia": self.foia.id, "language": "Lorem ipsum"}
Ejemplo n.º 14
0
 def test_clone_single(self, mock_upload):
     """Should duplicate the communication to the request."""
     other_foia = FOIARequestFactory()
     comm_count = FOIACommunication.objects.count()
     comm_pk = self.comm.pk
     clone_comm = self.comm.clone([other_foia], self.user)
     # + 1 communications
     eq_(
         FOIACommunication.objects.count(), comm_count + 1,
         'Should clone the request once.'
     )
     eq_(
         self.comm.pk, comm_pk,
         'The identity of the communication that calls clone should not change.'
     )
     # a move log should be generated for cloned request
     ok_(
         CommunicationMoveLog.objects.filter(
             communication=clone_comm[0],
             foia=self.comm.foia,
             user=self.user,
         ).exists()
     )
     # a move log should not be generated for the original request
     nose.tools.assert_false(
         CommunicationMoveLog.objects.filter(communication=self.comm,
                                             ).exists()
     )
     mock_upload.assert_called()
Ejemplo n.º 15
0
 def test_multi_clone(self):
     """Test cloning a multirequest"""
     foia = FOIARequestFactory(
         composer__status='filed',
         embargo=False,
     )
     FOIARequestFactory(composer=foia.composer)
     form = BaseComposerForm(
         {
             'action': 'save',
             'parent': foia.composer.pk,
         },
         user=foia.composer.user,
         request=None,
     )
     ok_(form.is_valid())
Ejemplo n.º 16
0
    def setUp(self):
        """Set up tests"""

        mail.outbox = []

        self.foia = FOIARequestFactory(status="submitted", title="Test 1")
        UserFactory(username="******")
Ejemplo n.º 17
0
 def test_session_success(self):
     """Test a successful post to the session view"""
     foia = FOIARequestFactory()
     attachments = OutboundRequestAttachmentFactory.create_batch(
         3,
         foia=foia,
         user=foia.user,
         sent=False,
     )
     OutboundRequestAttachmentFactory.create_batch(
         3,
         foia=foia,
         user=foia.user,
         sent=True,
     )
     OutboundRequestAttachmentFactory.create_batch(3)
     request_factory = RequestFactory()
     request = request_factory.get(
         reverse('fine-uploader-session-request'),
         {'id': foia.pk},
     )
     request.user = foia.user
     response = views.session_request(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)
Ejemplo n.º 18
0
 def test_request_fee_receipt(self, mock_send):
     """A receipt should be sent after request fee is paid."""
     foia = FOIARequestFactory()
     mock_charge.metadata['action'] = 'request-fee'
     mock_charge.metadata['foia'] = foia.pk
     tasks.send_charge_receipt(mock_charge.id)
     mock_send.assert_called_with(fail_silently=False)
Ejemplo n.º 19
0
    def test_bad_verify(self):
        """Test an improperly signed message"""

        foia = FOIARequestFactory(block_incoming=True)
        to_ = foia.get_request_email()
        response = self.mailgun_route(to_=to_, sign=False)
        nose.tools.eq_(response.status_code, 403)
Ejemplo n.º 20
0
 def test_composer_detail_single_submitted(self):
     """Composer redirects to foia page if only a single request even
     if it hasn't been filed yet"""
     foia = FOIARequestFactory(
         composer__status='submitted',
         composer__datetime_submitted=timezone.now(),
     )
     composer = foia.composer
     request = self.request_factory.get(
         reverse(
             'foia-composer-detail',
             kwargs={
                 'slug': composer.slug,
                 'idx': composer.pk
             }
         )
     )
     request.user = UserFactory()
     request = mock_middleware(request)
     response = ComposerDetail.as_view()(
         request,
         slug=composer.slug,
         idx=composer.pk,
     )
     eq_(response.status_code, 302)
     eq_(response.url, foia.get_absolute_url())
Ejemplo n.º 21
0
    def setUp(self):
        """Set up tests"""

        mail.outbox = []

        self.foia = FOIARequestFactory(status='submitted', title='Test 1')
        UserFactory(username='******')
Ejemplo n.º 22
0
    def test_foia_followup(self):
        """Make sure the follow up date is set correctly"""
        # pylint: disable=protected-access
        foia = FOIARequestFactory(
            composer__datetime_submitted=timezone.now(),
            status='processed',
            agency__jurisdiction__level='s',
            agency__jurisdiction__law__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,
            date.today() + timedelta(foia._followup_days())
        )

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

        num_days = 365
        foia.date_estimate = date.today() + 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 = date.today()
        foia.followup()
        nose.tools.assert_in('check on the status', mail.outbox[-1].body)
        nose.tools.eq_(foia._followup_days(), 15)
Ejemplo n.º 23
0
 def test_post_move(self):
     """Moving the response should save it to a new request."""
     other_foia = FOIARequestFactory()
     starting_date = self.task.communication.datetime
     data = {
         "move": other_foia.id,
         "status": "done",
         "task": self.task.pk,
         "save": True,
     }
     http_post_response(self.url, self.view, data, self.user)
     self.task.refresh_from_db()
     self.task.communication.refresh_from_db()
     ending_date = self.task.communication.datetime
     eq_(
         self.task.communication.foia,
         other_foia,
         "The response should be moved to a different FOIA.",
     )
     ok_(self.task.resolved, "Moving the status should resolve the task")
     eq_(
         starting_date,
         ending_date,
         "Moving the communication should not change its date.",
     )
Ejemplo n.º 24
0
 def test_clone_files(self, mock_upload):
     """Should duplicate all the files for each communication."""
     first_foia = FOIARequestFactory()
     second_foia = FOIARequestFactory()
     third_foia = FOIARequestFactory()
     file_count = self.comm.files.count()
     clones = self.comm.clone(
         [first_foia, second_foia, third_foia],
         self.user,
     )
     for each_clone in clones:
         eq_(
             each_clone.files.count(), file_count,
             'Each clone should have its own set of files.'
         )
     mock_upload.assert_called()
Ejemplo n.º 25
0
    def test_foia_followup(self):
        """Make sure the follow up date is set correctly"""
        # pylint: disable=protected-access
        foia = FOIARequestFactory(
            composer__datetime_submitted=timezone.now(),
            status="processed",
            agency__jurisdiction__level="s",
            agency__jurisdiction__law__days=10,
        )
        FOIACommunicationFactory(foia=foia, response=True)
        foia.followup()
        self.run_commit_hooks()
        nose.tools.assert_in("I can expect", mail.outbox[-1].body)
        nose.tools.eq_(
            foia.date_followup,
            foia.communications.last().datetime.date() +
            timedelta(foia._followup_days()),
        )

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

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

        foia.date_estimate = date.today()
        foia.followup()
        self.run_commit_hooks()
        nose.tools.assert_in("check on the status", mail.outbox[-1].body)
        nose.tools.eq_(foia._followup_days(), 15)
Ejemplo n.º 26
0
 def test_foia_followup_estimated(self):
     """If request has an estimated date, returns number of days until the estimated date"""
     # pylint: disable=protected-access
     num_days = 365
     foia = FOIARequestFactory(date_estimate=date.today() +
                               timedelta(num_days))
     nose.tools.eq_(foia._followup_days(), num_days)
Ejemplo n.º 27
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_ = '%s, "Doe, John" <*****@*****.**>' % foia.get_request_email()
        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_user, foia.agency.get_user())
        nose.tools.eq_(last_comm.to_user, foia.user)
        nose.tools.eq_(last_comm.response, True)
        nose.tools.eq_(last_comm.full_html, False)
        nose.tools.ok_(last_comm.get_raw_email())
        nose.tools.eq_(last_comm.responsetask_set.count(), 1)
        nose.tools.eq_(foia.email, EmailAddress.objects.fetch(from_email))
        nose.tools.eq_(
            set(foia.cc_emails.all()),
            set(EmailAddress.objects.fetch_many("*****@*****.**")),
        )
        nose.tools.eq_(foia.status, "processed")
Ejemplo n.º 28
0
    def test_soft_delete(self):
        """Test the soft delete method"""
        foia = FOIARequestFactory(status="processed")
        FOIAFileFactory.create_batch(size=3, comm__foia=foia)
        user = UserFactory(is_superuser=True)

        nose.tools.eq_(foia.get_files().count(), 3)
        nose.tools.eq_(
            RawEmail.objects.filter(email__communication__foia=foia).count(),
            3)

        foia.soft_delete(user, "final message", "note")
        foia.refresh_from_db()
        self.run_commit_hooks()

        # final communication we send out is not cleared
        for comm in list(foia.communications.all())[:-1]:
            nose.tools.eq_(comm.communication, "")
        nose.tools.eq_(foia.get_files().count(), 0)
        # one raw email left on the final outgoing message
        nose.tools.eq_(
            RawEmail.objects.filter(email__communication__foia=foia).count(),
            1)
        nose.tools.eq_(foia.last_request().communication, "final message")
        nose.tools.eq_(foia.notes.first().note, "note")

        nose.tools.ok_(foia.deleted)
        nose.tools.ok_(foia.embargo)
        nose.tools.ok_(foia.permanent_embargo)
        nose.tools.eq_(foia.status, "abandoned")
Ejemplo n.º 29
0
 def test_get_absolute_url(self):
     text = 'Lorem ipsum'
     user = UserFactory()
     foia = FOIARequestFactory()
     flagged_task = self.task.objects.create(user=user, foia=foia, text=text)
     _url = reverse('flagged-task', kwargs={'pk': flagged_task.pk})
     eq_(flagged_task.get_absolute_url(), _url)
Ejemplo n.º 30
0
 def _test_approve(self, mock_submit):
     submitted_foia = FOIARequestFactory(agency=self.agency,
                                         status='submitted')
     FOIACommunicationFactory(foia=submitted_foia)
     self.task.approve()
     eq_(self.task.agency.status, 'approved')
     eq_(mock_submit.call_count, 1)