def set_status(self, status): """Forward to form logic, for use in classify_status task""" # pylint: disable=import-outside-toplevel from muckrock.task.forms import ResponseTaskForm form = ResponseTaskForm(task=self) form.set_status(status, set_foia=True, comms=[self.communication])
class ResponseTaskTests(TestCase): """Test the ResponseTask class""" def setUp(self): agency = AgencyFactory() comm = FOIACommunicationFactory(response=True, foia__agency=agency) self.task = ResponseTask.objects.create(communication=comm) self.form = ResponseTaskForm() self.user = UserFactory() def test_get_absolute_url(self): eq_( self.task.get_absolute_url(), reverse('response-task', kwargs={ 'pk': self.task.pk }) ) def test_task_creates_successfully(self): ok_( self.task, 'Response tasks should creates successfully given a communication' ) def test_set_status_to_ack(self): self.form.set_status('ack', True, [self.task.communication]) eq_( self.task.communication.foia.datetime_done, None, 'The FOIA should not be set to done if the status does not indicate it is done.' ) eq_( self.task.communication.status, 'ack', 'The communication should be set to the proper status.' ) eq_( self.task.communication.foia.status, 'ack', 'The FOIA should be set to the proper status.' ) def test_set_status_to_done(self): self.form.set_status('done', True, [self.task.communication]) eq_( self.task.communication.foia.datetime_done is None, False, 'The FOIA should be set to done if the status indicates it is done.' ) eq_( self.task.communication.status, 'done', 'The communication should be set to the proper status.' ) eq_( self.task.communication.foia.status, 'done', 'The FOIA should be set to the proper status.' ) def test_set_comm_status_only(self): foia = self.task.communication.foia existing_status = foia.status self.form.set_status('done', False, [self.task.communication]) foia.refresh_from_db() eq_( foia.datetime_done is None, True, 'The FOIA should not be set to done because we are not settings its status.' ) eq_( foia.status, existing_status, 'The FOIA status should not be changed.' ) eq_( self.task.communication.status, 'done', 'The Communication status should be changed, however.' ) def test_set_tracking_id(self): new_tracking = u'dogs-r-cool' self.form.set_tracking_id(new_tracking, [self.task.communication]) self.task.refresh_from_db() eq_( self.task.communication.foia.current_tracking_id(), new_tracking, 'Should update the tracking number on the request.' ) def test_set_date_estimate(self): new_date = timezone.now() self.form.set_date_estimate(new_date, [self.task.communication]) eq_( self.task.communication.foia.date_estimate, new_date, 'Should update the estimated completion date on the request.' ) def test_set_price(self): price = 1.23 self.form.set_price(price, [self.task.communication]) eq_( self.task.communication.foia.price, price, 'Should update the price on the request.' ) def test_move(self): move_to_foia = FOIARequestFactory() self.form.move_communication( self.task.communication, [move_to_foia.pk], self.user ) eq_( self.task.communication.foia, move_to_foia, 'Should move the communication to a different request.' ) @raises(ValueError) def test_bad_status(self): """Should raise an error if given a nonexistant status.""" self.form.set_status('foo', True, [self.task.communication]) @raises(ValueError) def test_bad_tracking_number(self): """Should raise an error if not given a string.""" self.form.set_tracking_id(['foo'], [self.task.communication]) @raises(ValueError) def test_bad_move(self): """Should raise a value error if non-existant move destination.""" self.form.move_communication( self.task.communication, [111111], self.user ) @raises(ValueError) def test_bad_price(self): """Should raise an error if not given a value convertable to a float""" self.form.set_price('foo', [self.task.communication])
def set_status(self, status): """Forward to form logic, for use in classify_status task""" from muckrock.task.forms import ResponseTaskForm form = ResponseTaskForm() form.set_status(status, set_foia=True, comms=[self.communication])