def test_post_update_composer(self): """Test submitting a composer""" composer = FOIAComposerFactory( status='started', user__profile__num_requests=4, ) agency = AgencyFactory() data = { 'title': 'Title', 'requested_docs': 'ABC', 'agencies': agency.pk, 'action': 'submit', } request = self.request_factory.post( reverse('foia-draft', kwargs={ 'idx': composer.pk }), data, ) request.user = composer.user request = mock_middleware(request) response = UpdateComposer.as_view()(request, idx=composer.pk) eq_(response.status_code, 302) composer.refresh_from_db() ok_(composer.status, 'submitted')
def test_get_update_composer_revoke(self): """Get the update composer form for a recently submitted composer""" composer = FOIAComposerFactory(status="submitted", delayed_id="123", datetime_submitted=timezone.now()) request = self.request_factory.get( reverse("foia-draft", kwargs={"idx": composer.pk})) request.user = composer.user request = mock_middleware(request) response = UpdateComposer.as_view()(request, idx=composer.pk) eq_(response.status_code, 200) composer.refresh_from_db() eq_(composer.status, "started")
def test_agency_merge(self): """Test agency merging""" good_agency = AgencyFactory(status="approved", email=None, fax=None) bad_agency = AgencyFactory(status="approved", email=None, fax=None) appeal_agency = AgencyFactory(appeal_agency=bad_agency) foia = FOIARequestFactory(agency=bad_agency) composer = FOIAComposerFactory(agencies=[bad_agency]) user = UserFactory() email = EmailAddressFactory() AgencyEmailFactory(agency=good_agency, email=email, email_type="to") AgencyEmailFactory(agency=bad_agency, email=email, email_type="cc") fax1 = PhoneNumberFactory() fax2 = PhoneNumberFactory() AgencyPhoneFactory(agency=good_agency, phone=fax1, request_type="primary") AgencyPhoneFactory(agency=bad_agency, phone=fax2, request_type="primary") good_agency.merge(bad_agency, user) bad_agency.refresh_from_db() appeal_agency.refresh_from_db() foia.refresh_from_db() composer.refresh_from_db() eq_(bad_agency.status, "rejected") eq_(foia.agency, good_agency) eq_(composer.agencies.first(), good_agency) eq_(appeal_agency.appeal_agency, good_agency) # email that already exists is not copied over eq_(good_agency.emails.count(), 1) eq_(good_agency.agencyemail_set.first().email_type, "to") # phone number that doesnt exist is copied over eq_(good_agency.phones.count(), 2) # existing phone number is unaffected ok_( good_agency.agencyphone_set.filter( phone=fax1, request_type="primary" ).exists() ) # its type is set to none when copied over ok_( good_agency.agencyphone_set.filter(phone=fax2, request_type="none").exists() ) assert_in(good_agency.name, bad_agency.notes) assert_in(str(good_agency.pk), bad_agency.notes) assert_in(user.username, bad_agency.notes)
def test_return_requests(self): """Test return requests""" composer = FOIAComposerFactory( status="submitted", num_monthly_requests=2, num_reg_requests=3 ) composer.organization.number_requests = 100 composer.organization.monthly_requests = 50 composer.organization.save() composer._return_requests({"regular": 2, "monthly": 1}) composer.refresh_from_db() eq_(composer.num_reg_requests, 1) eq_(composer.num_monthly_requests, 1) eq_(composer.organization.number_requests, 102) eq_(composer.organization.monthly_requests, 51)
def test_autosave_good(self): """Test a succesful autosave""" composer = FOIAComposerFactory(status='started') request = self.request_factory.post( reverse('foia-autosave', kwargs={'idx': composer.pk}), { 'title': 'New Title', 'requested_docs': 'ABC', }, ) request.user = composer.user request = mock_middleware(request) response = autosave(request, idx=composer.pk) eq_(response.status_code, 200) composer.refresh_from_db() eq_(composer.title, 'New Title') eq_(composer.requested_docs, 'ABC')
def test_autosave_good(self): """Test a succesful autosave""" composer = FOIAComposerFactory(status="started") request = self.request_factory.post( reverse("foia-autosave", kwargs={"idx": composer.pk}), { "title": "New Title", "requested_docs": "ABC" }, ) request.user = composer.user request = mock_middleware(request) response = autosave(request, idx=composer.pk) eq_(response.status_code, 200) composer.refresh_from_db() eq_(composer.title, "New Title") eq_(composer.requested_docs, "ABC")
def test_post_update_composer(self): """Test submitting a composer""" composer = FOIAComposerFactory(status="started") agency = AgencyFactory() data = { "title": "Title", "requested_docs": "ABC", "agencies": agency.pk, "action": "submit", "stripe_pk": "STRIPE_PK", } request = self.request_factory.post( reverse("foia-draft", kwargs={"idx": composer.pk}), data) request.user = composer.user request = mock_middleware(request) response = UpdateComposer.as_view()(request, idx=composer.pk) eq_(response.status_code, 302) composer.refresh_from_db() ok_(composer.status, "submitted")