Exemplo n.º 1
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)
Exemplo n.º 2
0
 def test_basic(self):
     """A form should validate when given a title, a status, a request, and a jurisdiction."""
     form = forms.FoiaMachineRequestForm({
         'title': self.title,
         'status': 'started',
         'request_language': self.request_language,
         'jurisdiction': self.jurisdiction.id
     })
     ok_(form.is_valid())
Exemplo n.º 3
0
 def test_agency(self):
     """The form should also accept an agency input."""
     form = forms.FoiaMachineRequestForm({
         'title': self.title,
         'status': 'started',
         'request_language': self.request_language,
         'jurisdiction': self.jurisdiction.id,
         'agency': self.agency.id,
     })
     ok_(form.is_valid())
Exemplo n.º 4
0
 def test_agency(self):
     """The form should also accept an agency input."""
     form = forms.FoiaMachineRequestForm({
         "title": self.title,
         "status": "started",
         "request_language": self.request_language,
         "jurisdiction": self.jurisdiction.id,
         "agency": self.agency.id,
     })
     ok_(form.is_valid())
Exemplo n.º 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())
Exemplo n.º 6
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())
Exemplo n.º 7
0
 def test_basic(self):
     """A form should validate when given a title, a status, a request, and a jurisdiction."""
     form = forms.FoiaMachineRequestForm({
         "title":
         self.title,
         "status":
         "started",
         "request_language":
         self.request_language,
         "jurisdiction":
         self.jurisdiction.id,
     })
     ok_(form.is_valid())
Exemplo n.º 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.')
Exemplo n.º 9
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.")
Exemplo n.º 10
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)