Example #1
0
 def test_list_jurisdiction_filter(self):
     """The list should be filterable by a jurisdiction."""
     massachusetts = StateJurisdictionFactory(name='Massachusetts', abbrev='MA')
     washington = StateJurisdictionFactory(name='Washington', abbrev='WA')
     exemption_ma = ExemptionFactory(jurisdiction=massachusetts)
     exemption_wa = ExemptionFactory(jurisdiction=washington)
     request = self.factory.get(self.endpoint, {'jurisdiction': massachusetts.pk})
     response = self.view(request)
     eq_(response.status_code, 200)
     ok_(ExemptionSerializer(exemption_ma).data in response.data['results'],
         'An exemption for the jurisdiction should be included in the list.')
     ok_(ExemptionSerializer(exemption_wa).data not in response.data['results'],
         'An exemption not for the jurisdiction should not be included in the list.')
Example #2
0
 def test_post(self):
     """Posting updated request info should update the request!"""
     new_jurisdiction = StateJurisdictionFactory()
     data = {
         'title': 'New Title',
         'status': 'done',
         'request_language': 'Foo bar baz!',
         'jurisdiction': new_jurisdiction.id
     }
     form = forms.FoiaMachineRequestForm(data, instance=self.foi)
     ok_(form.is_valid())
     response = http_post_response(
         self.url, self.view, data, self.foi.user, **self.kwargs
     )
     self.foi.refresh_from_db()
     # we have to update the slug, because the title changed
     self.kwargs['slug'] = self.foi.slug
     eq_(response.status_code, 302)
     eq_(
         response.url,
         reverse('foi-detail', host='foiamachine', kwargs=self.kwargs)
     )
     eq_(self.foi.title, data['title'])
     eq_(self.foi.status, data['status'])
     eq_(self.foi.request_language, data['request_language'])
     eq_(self.foi.jurisdiction, new_jurisdiction)
Example #3
0
 def test_template(self):
     """Get the default language for a given jurisdiction"""
     jurisdiction = StateJurisdictionFactory.create()
     request = self.factory.get(
         reverse("api-jurisdiction-template", kwargs={"pk": jurisdiction.pk})
     )
     response = self.view(request, pk=jurisdiction.pk)
     eq_(response.status_code, 200)
Example #4
0
 def test_agency_mismatch(self):
     """The form should not validate if the agency is from a different jurisdiction."""
     jurisdiction = StateJurisdictionFactory()
     form = forms.FoiaMachineRequestForm({
         'title': self.title,
         'status': 'started',
         'request_language': self.request_language,
         'jurisdiction': jurisdiction.id,
         'agency': self.agency.id,
     })
     ok_(not form.is_valid())
Example #5
0
 def test_agency_mismatch(self):
     """The form should not validate if the agency is from a different jurisdiction."""
     jurisdiction = StateJurisdictionFactory()
     form = forms.FoiaMachineRequestForm({
         "title": self.title,
         "status": "started",
         "request_language": self.request_language,
         "jurisdiction": jurisdiction.id,
         "agency": self.agency.id,
     })
     ok_(not form.is_valid())
Example #6
0
 def test_create(self):
     """Posting a valid creation form should create a request and redirect to it."""
     title = 'Test Request'
     request_language = 'Lorem ipsum'
     jurisdiction = StateJurisdictionFactory().id
     form = forms.FoiaMachineRequestForm({
         'title': title,
         'status': 'started',
         'request_language': request_language,
         'jurisdiction': jurisdiction
     })
     ok_(form.is_valid())
     response = http_post_response(self.url, self.view, form.data, self.user)
     eq_(response.status_code, 302, 'When successful the view should redirect to the request.')
     foi = models.FoiaMachineRequest.objects.first()
     eq_(response.url, foi.get_absolute_url())
     ok_(foi.communications.count() == 1, 'A communication should be created.')
 def test_flagged_object(self):
     """A flagged task should be able to return its object."""
     text = 'Lorem ipsum'
     user = UserFactory()
     foia = FOIARequestFactory()
     agency = AgencyFactory()
     jurisdiction = StateJurisdictionFactory()
     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)
Example #8
0
 def test_create(self):
     """Posting a valid creation form should create a request and redirect to it."""
     title = "Test Request"
     request_language = "Lorem ipsum"
     jurisdiction = StateJurisdictionFactory().id
     form = forms.FoiaMachineRequestForm({
         "title": title,
         "status": "started",
         "request_language": request_language,
         "jurisdiction": jurisdiction,
     })
     ok_(form.is_valid())
     response = http_post_response(self.url, self.view, form.data,
                                   self.user)
     eq_(
         response.status_code,
         302,
         "When successful the view should redirect to the request.",
     )
     foi = models.FoiaMachineRequest.objects.first()
     eq_(response.url, foi.get_absolute_url())
     ok_(foi.communications.count() == 1,
         "A communication should be created.")
Example #9
0
 def test_post(self):
     """Posting updated request info should update the request!"""
     new_jurisdiction = StateJurisdictionFactory()
     data = {
         "title": "New Title",
         "status": "done",
         "request_language": "Foo bar baz!",
         "jurisdiction": new_jurisdiction.id,
     }
     form = forms.FoiaMachineRequestForm(data, instance=self.foi)
     ok_(form.is_valid())
     response = http_post_response(self.url, self.view, data, self.foi.user,
                                   **self.kwargs)
     self.foi.refresh_from_db()
     # we have to update the slug, because the title changed
     self.kwargs["slug"] = self.foi.slug
     eq_(response.status_code, 302)
     eq_(response.url,
         reverse("foi-detail", host="foiamachine", kwargs=self.kwargs))
     eq_(self.foi.title, data["title"])
     eq_(self.foi.status, data["status"])
     eq_(self.foi.request_language, data["request_language"])
     eq_(self.foi.jurisdiction, new_jurisdiction)