def test_move(self): """Should move the communication to the listed requests and create a ResponseTask for each new communication.""" foia1 = factories.FOIARequestFactory() foia2 = factories.FOIARequestFactory() foia3 = factories.FOIARequestFactory() count_response_tasks = task.models.ResponseTask.objects.count() self.task.move([foia1.pk, foia2.pk, foia3.pk]) eq_(task.models.ResponseTask.objects.count(), count_response_tasks + 3, 'Reponse tasks should be created for each communication moved.')
def test_clone_files(self): """Should duplicate all the files for each communication.""" first_foia = factories.FOIARequestFactory() second_foia = factories.FOIARequestFactory() third_foia = factories.FOIARequestFactory() file_count = self.comm.files.count() clones = self.comm.clone( [first_foia.pk, second_foia.pk, third_foia.pk]) for each_clone in clones: eq_(each_clone.files.count(), file_count, 'Each clone should have its own set of files.')
def test_clone_multi(self): """Should duplicate the communication to each request in the list.""" first_foia = factories.FOIARequestFactory() second_foia = factories.FOIARequestFactory() third_foia = factories.FOIARequestFactory() comm_count = FOIACommunication.objects.count() clones = self.comm.clone( [first_foia.pk, second_foia.pk, third_foia.pk]) # + 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.')
def setUp(self): user = factories.UserFactory() agency = factories.AgencyFactory(status='pending') self.foia = factories.FOIARequestFactory(user=user, agency=agency) self.comm = factories.FOIACommunicationFactory(foia=self.foia, response=True) # tasks that incorporate FOIAs are: # ResponseTask, SnailMailTask, FailedFaxTask, RejectedEmailTask, FlaggedTask, # StatusChangeTask, NewAgencyTask response_task = task.models.ResponseTask.objects.create( communication=self.comm) snail_mail_task = task.models.SnailMailTask.objects.create( category='a', communication=self.comm) failed_fax_task = task.models.FailedFaxTask.objects.create( communication=self.comm) rejected_email_task = task.models.RejectedEmailTask.objects.create( category='d', foia=self.foia) flagged_task = task.models.FlaggedTask.objects.create(user=user, text='Halp', foia=self.foia) status_change_task = task.models.StatusChangeTask.objects.create( user=user, old_status='ack', foia=self.foia) new_agency_task = task.models.NewAgencyTask.objects.create( user=user, agency=agency) self.tasks = [ response_task, snail_mail_task, failed_fax_task, rejected_email_task, flagged_task, status_change_task, new_agency_task ]
def test_request_fee_receipt(self, mock_send): """A receipt should be sent after request fee is paid.""" foia = factories.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)
def setUp(self): self.user = factories.UserFactory(profile__acct_type='pro') self.user.profile.organization = factories.OrganizationFactory( active=True) self.foia = factories.FOIARequestFactory(user=self.user) self.request_factory = RequestFactory() self.url = self.foia.get_absolute_url()
def test_approve(self, mock_submit): submitted_foia = factories.FOIARequestFactory(agency=self.agency, status='submitted') factories.FOIACommunicationFactory(foia=submitted_foia) drafted_foia = factories.FOIARequestFactory(agency=self.agency, status='started') factories.FOIACommunicationFactory(foia=drafted_foia) self.task.approve() eq_( self.task.agency.status, 'approved', 'Approving a new agency should actually, you know, approve the agency.' ) # since we have 1 draft and 1 nondraft FOIA, we should expect submit() to be called once eq_( mock_submit.call_count, 1, 'Approving a new agency should resubmit non-draft FOIAs associated with that agency.' )
def test_clone_missing_ffile(self): """ The clone operation should not crash when FOIAFile has a null ffile field. """ self.file.ffile = None self.file.save() ok_(not self.comm.files.all()[0].ffile) other_foia = factories.FOIARequestFactory() self.comm.clone([other_foia.pk])
def setUp(self): self.foia = factories.FOIARequestFactory() self.comm = factories.FOIACommunicationFactory( foia=self.foia, email__from_email=EmailAddress.objects.fetch( u'Test Email <*****@*****.**>'), ) self.file = factories.FOIAFileFactory(comm=self.comm) eq_(self.comm.files.count(), 1)
def test_get_absolute_url(self): text = 'Lorem ipsum' user = factories.UserFactory() foia = factories.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)
def test_for_object(self): """Notifications should be filterable by a single object.""" foia = factories.FOIARequestFactory() _action = new_action(factories.UserFactory(), 'submitted', target=foia) object_notification = factories.NotificationFactory(user=self.user, action=_action) object_notifications = Notification.objects.for_object(foia) ok_(object_notification in object_notifications, 'A notification for the object should be in the set returned.') ok_(self.notification not in object_notifications, 'A notification not including the object should not be in the set returned.')
def test_reject(self): replacement = factories.AgencyFactory() existing_foia = factories.FOIARequestFactory(agency=self.agency) self.task.reject(replacement) existing_foia.refresh_from_db() eq_(self.task.agency.status, 'rejected', 'Rejecting a new agency should leave it unapproved.') eq_( existing_foia.agency, replacement, 'The replacement agency should receive the rejected agency\'s requests.' )
def test_post_move_multiple(self): """Moving the response to multiple requests modify all the requests.""" other_foias = [ factories.FOIARequestFactory(), factories.FOIARequestFactory(), factories.FOIARequestFactory() ] move_to_ids = ', '.join([str(foia.id) for foia in other_foias]) change_status = 'done' change_tracking = 'DEADBEEF' data = { 'move': move_to_ids, 'status': change_status, 'tracking_number': change_tracking, 'task': self.task.pk } http_post_response(self.url, self.view, data, self.user) for foia in other_foias: foia.refresh_from_db() eq_(change_tracking, foia.tracking_id, 'Tracking should update for each request in move list.')
def test_clone_single(self): """Should duplicate the communication to the request.""" other_foia = factories.FOIARequestFactory() comm_count = FOIACommunication.objects.count() comm_pk = self.comm.pk self.comm.clone([other_foia.pk]) # + 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.' )
def test_post_move(self): """Moving the response should save it to a new request.""" other_foia = factories.FOIARequestFactory() starting_date = self.task.communication.date data = {'move': other_foia.id, 'status': 'done', 'task': self.task.pk} 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.date 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.')
def test_post_bad_email_update(self, mock_update): """An invalid email should be prevented from updating or resolving anything.""" bad_email = u'bad_email' foia = factories.FOIARequestFactory() post_data = { 'email': bad_email, 'foia': [foia.pk], 'update': 'truthy', 'resolve': 'truthy', 'task': self.task.pk } self.post_request(post_data) self.task.refresh_from_db() self.task.agency.refresh_from_db() ok_(not mock_update.called, 'The email should not be updated.') ok_(not self.task.resolved, 'The task should not resolve.') ok_(self.task.agency.stale, 'The agency should still be stale.')
def test_post_email_update(self, mock_update): """Should update email when given an email and a list of FOIA""" new_email = u'*****@*****.**' foia = factories.FOIARequestFactory() post_data = { 'email': new_email, 'foia': [foia.pk], 'update': 'truthy', 'resolve': 'truthy', 'task': self.task.pk } self.post_request(post_data) self.task.refresh_from_db() self.task.agency.refresh_from_db() ok_(mock_update.called, 'The email should be updated.') ok_(self.task.resolved, 'The task should resolve.') ok_(not self.task.agency.stale, 'The agency should no longer be stale.')
def test_flagged_object(self): """A flagged task should be able to return its object.""" text = 'Lorem ipsum' user = factories.UserFactory() foia = factories.FOIARequestFactory() agency = factories.AgencyFactory() jurisdiction = factories.JurisdictionFactory() flagged_foia_task = self.task.objects.create(user=user, foia=foia, text=text) flagged_agency_task = self.task.objects.create(user=user, agency=agency, text=text) flagged_jurisdiction_task = self.task.objects.create( user=user, jurisdiction=jurisdiction, text=text) eq_(flagged_foia_task.flagged_object(), foia) eq_(flagged_agency_task.flagged_object(), agency) eq_(flagged_jurisdiction_task.flagged_object(), jurisdiction)
def test_post_bad_foia(self, mock_update): """An invalid FOIA should not prevent the task from updating or resolving anything.""" new_email = u'*****@*****.**' foia = factories.FOIARequestFactory() bad_pk = 12345 post_data = { 'email': new_email, 'foia': [foia.pk, bad_pk], 'update': 'truthy', 'resolve': 'truthy', 'task': self.task.pk } self.post_request(post_data) self.task.refresh_from_db() self.task.agency.refresh_from_db() ok_(mock_update.called, 'The email should be updated.') ok_(self.task.resolved, 'The task should resolve.') ok_(not self.task.agency.stale, 'The agency should no longer be stale.')
def setUp(self): self.foia1 = factories.FOIARequestFactory() self.foia2 = factories.FOIARequestFactory() self.comm = factories.FOIACommunicationFactory(foia=self.foia1) self.file = factories.FOIAFileFactory(comm=self.comm) eq_(self.comm.files.count(), 1)
def setUp(self): self.creation_date = datetime.datetime.now() - datetime.timedelta(1) agency = factories.AgencyFactory() foia = factories.FOIARequestFactory(agency=agency) self.comm = factories.FOIACommunicationFactory(foia=foia, date=self.creation_date)
def test_move(self): move_to_foia = factories.FOIARequestFactory() self.task.move(move_to_foia.id) eq_(self.task.communication.foia, move_to_foia, 'Should move the communication to a different request.')
def setUp(self): self.foia = factories.FOIARequestFactory() self.comm = factories.FOIACommunicationFactory( foia=self.foia, priv_from_who=u'Test Email <*****@*****.**>') self.file = factories.FOIAFileFactory(comm=self.comm) eq_(self.comm.files.count(), 1)