class TestFOIARequestAppeal(TestCase): """A request should be able to send an appeal to the agency that receives them.""" def setUp(self): self.appeal_agency = AppealAgencyFactory() self.agency = AgencyFactory(status='approved', appeal_agency=self.appeal_agency) self.foia = FOIARequestFactory(agency=self.agency, status='rejected') def test_appeal(self): """Sending an appeal to the agency should require the message for the appeal, which is then turned into a communication to the correct agency. In this case, the correct agency is the same one that received the message.""" ok_(self.foia.has_perm(self.foia.user, 'appeal'), 'The request should be appealable.') ok_(self.agency and self.agency.status == 'approved', 'The agency should be approved.') ok_(self.appeal_agency.get_emails('appeal'), 'The appeal agency should accept email.') # Create the appeal message and submit it appeal_message = 'Lorem ipsum' appeal_comm = self.foia.appeal(appeal_message, self.foia.user) # Check that everything happened like we expected self.foia.refresh_from_db() appeal_comm.refresh_from_db() eq_(self.foia.email, self.appeal_agency.get_emails('appeal').first()) eq_(self.foia.status, 'appealing') eq_(appeal_comm.communication, appeal_message) eq_(appeal_comm.from_user, self.foia.user) eq_(appeal_comm.to_user, self.agency.get_user()) ok_(appeal_comm.emails.exists()) def test_mailed_appeal(self): """Sending an appeal to an agency via mail should set the request to 'submitted', create a snail mail task with the 'a' category, and set the appeal communication delivery method to 'mail'.""" # Make the appeal agency unreceptive to emails self.appeal_agency.emails.clear() # Create the appeal message and submit it appeal_message = 'Lorem ipsum' appeal_comm = self.foia.appeal(appeal_message, self.foia.user) # Check that everything happened like we expected self.foia.refresh_from_db() appeal_comm.refresh_from_db() eq_( self.foia.status, 'submitted', 'The status of the request should be updated. Actually: %s' % self.foia.status) eq_( appeal_comm.communication, appeal_message, 'The appeal message parameter should be used as the body of the communication.' ) eq_(appeal_comm.from_user, self.foia.user, 'The appeal should be addressed from the request owner.') eq_(appeal_comm.to_user, self.agency.get_user(), 'The appeal should be addressed to the agency.') task = SnailMailTask.objects.get(communication=appeal_comm) ok_(task, 'A snail mail task should be created.') eq_(task.category, 'a')
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)
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 }
def setUp(self): self.user = UserFactory() self.title = 'Test Request' self.request_language = 'Lorem ipsum' self.agency = AgencyFactory() self.jurisdiction = self.agency.jurisdiction self.foi = factories.FoiaMachineRequestFactory( user=self.user, title=self.title, request_language=self.request_language, jurisdiction=self.jurisdiction, )
def test_agency_location_default(self): """Creating a marker with an empty location should try to grab the FOIA agency location.""" location1 = self.map.center location2 = json.dumps({'type': 'Point', 'coordinates': [40.0, -40.0]}) # set the location of the agency self.foia.agency = AgencyFactory(location=location1) self.foia.agency.save() # create a new marker empty_marker = Marker.objects.create(map=self.map, foia=self.foia) filled_marker = Marker.objects.create(map=self.map, foia=self.foia, point=location2) eq_(empty_marker.point, location1, 'The location of the agency should be copied to the marker.') eq_( filled_marker.point, location2, 'The location of the marker should not change since it was provided at creation.' )
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.')
def test_foia_create(self, mock): """Test creating a FOIA through the API""" attachment_url = 'http://www.example.com/attachment.txt' mock.get( attachment_url, headers={'Content-Type': 'text/plain'}, text='Attachment content here', ) agency = AgencyFactory() password = '******' user = UserFactory.create( password=password, profile__num_requests=5, ) data = { 'jurisdiction': agency.jurisdiction.pk, 'agency': agency.pk, 'document_request': 'The document', 'title': 'Title', 'attachments': [attachment_url], } response = self.client.post( reverse('api-token-auth'), { 'username': user.username, 'password': password }, ) headers = { 'content-type': 'application/json', 'HTTP_AUTHORIZATION': 'Token %s' % response.json()['token'], } response = self.client.post(reverse('api-foia-list'), json.dumps(data), content_type='application/json', **headers) nose.tools.eq_(response.status_code, 201)
def setUp(self): self.appeal_agency = AppealAgencyFactory() self.agency = AgencyFactory(status='approved', appeal_agency=self.appeal_agency) self.foia = FOIARequestFactory(agency=self.agency, status='rejected')