def test_draft_effective_date_field_is_loaded_from_draft(self): scenario = self._create_scenario(draft_args=dict(effective_date=naive_date(u'2010-10-13'))) url = self._create_url(scenario) self._login_user() response = self.client.get(url, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') self.assertEqual(response.context[u'form'][u'effective_date'].value(), naive_date(u'2010-10-13'))
def test_draft_effective_date_field_is_saved_to_draft(self): scenario = self._create_scenario(draft_args=dict(effective_date=naive_date(u'2010-10-05'))) data = self._create_post_data(button=u'draft', effective_date=naive_date(u'2010-10-13')) url = self._create_url(scenario) self._login_user() response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') draft = ActionDraft.objects.get(pk=scenario.draft.pk) self.assertEqual(draft.effective_date, naive_date(u'2010-10-13'))
def test_effective_date_field_is_saved(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenario = self._create_scenario() timewarp.jump(local_datetime_from_local(u'2010-10-17 10:33:00')) data = self._create_post_data(branch=scenario.branch, effective_date=naive_date(u'2010-10-13')) url = self._create_url(scenario) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') action = action_set.get() self.assertEqual(action.effective_date, naive_date(u'2010-10-13'))
def test_date_output_format(self): with translation(u'en'): class Form(forms.Form): field = forms.DateField(localize=True) form = Form(initial=dict(field=naive_date(u'2006-10-25'))) self.assertHTMLEqual(str(form[u'field']), u'<input id="id_field" name="field" type="text" value="10/25/2006">')
def _test_deadline_missed_aux(self, **kwargs): inforequest = self._create_inforequest() branch = self._create_branch(inforequest=inforequest) action = self._create_action(branch=branch, effective_date=naive_date(u'2010-10-05'), **kwargs) timewarp.jump(local_datetime_from_local(u'2010-10-10 10:33:00')) with mock.patch(u'chcemvediet.apps.inforequests.models.action.workdays.between', side_effect=lambda a,b: (b-a).days): yield action
def test_post_with_valid_data_creates_action_instance(self): scenario = self._create_scenario(email_args=dict(subject=u'Subject', text=u'Content', processed=utc_datetime_from_local(u'2010-10-05 00:33:00'))) attachment1 = self._create_attachment(generic_object=scenario.email, name=u'filename.txt', content=u'content', content_type=u'text/plain') attachment2 = self._create_attachment(generic_object=scenario.email, name=u'filename.html', content=u'<p>content</p>', content_type=u'text/html') data = self._create_post_data(branch=scenario.branch) url = self._create_url(scenario) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') action = action_set.get() self.assertEqual(action.email, scenario.email) self.assertEqual(action.type, self.action_type) self.assertEqual(action.subject, u'Subject') self.assertEqual(action.content, u'Content') self.assertEqual(action.effective_date, naive_date(u'2010-10-05')) attachments = [(a.name, a.content, a.content_type) for a in action.attachment_set.all()] self.assertItemsEqual(attachments, [ (u'filename.txt', u'content', u'text/plain'), (u'filename.html', u'<p>content</p>', u'text/html'), ]) scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk) self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.OBLIGEE_ACTION)
def test_date_input_formats(self): with translation(u'sk'): self.assertFieldOutput(forms.DateField, valid={ u'25.10.2006': naive_date(u'2006-10-25'), u'25.10.06': naive_date(u'2006-10-25'), u'2006-10-25': naive_date(u'2006-10-25'), }, invalid={ u'10.25.2006': [u'Zadajte platný dátum.'], u'10.25.06': [u'Zadajte platný dátum.'], u'10/25/2006': [u'Zadajte platný dátum.'], u'10/25/06': [u'Zadajte platný dátum.'], u'25/10/2006': [u'Zadajte platný dátum.'], u'25/10/06': [u'Zadajte platný dátum.'], u'2006-25-10': [u'Zadajte platný dátum.'], }, field_kwargs=dict(localize=True), empty_value=None, )
def test_draft_effective_date_may_be_from_future(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenario = self._create_scenario() data = self._create_post_data(button=u'draft', effective_date=naive_date(u'2014-11-06')) url = self._create_url(scenario) self._login_user() response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') data = json.loads(response.content) self.assertEqual(data[u'result'], u'success')
def test_post_with_default_button_and_valid_data_creates_action_with_effective_date_today(self): timewarp.jump(local_datetime_from_local(u'2010-03-05 10:33:00')) scenario = self._create_scenario() data = self._create_post_data(branch=scenario.branch) url = self._create_url(scenario) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') action = action_set.get() self.assertEqual(action.effective_date, naive_date(u'2010-03-05'))
def test_effective_date_field_may_not_be_from_future(self): timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) scenario = self._create_scenario() data = self._create_post_data(branch=scenario.branch, effective_date=naive_date(u'2010-10-06')) url = self._create_url(scenario) self._login_user() response = self.client.post(url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') self.assertFormError(response, u'form', u'effective_date', 'May not be from future.') data = json.loads(response.content) self.assertEqual(data[u'result'], u'invalid')
def test_add_expiration_if_expired_method(self): tests = ( # Expected action type, branch, scenario (Action.TYPES.REQUEST, Action.TYPES.EXPIRATION, 0, []), (Action.TYPES.CLARIFICATION_RESPONSE, Action.TYPES.EXPIRATION, 0, [u'clarification_request', u'clarification_response']), (Action.TYPES.APPEAL, Action.TYPES.APPEAL_EXPIRATION, 0, [u'expiration', u'appeal']), (Action.TYPES.CONFIRMATION, Action.TYPES.EXPIRATION, 0, [u'confirmation']), (Action.TYPES.EXTENSION, Action.TYPES.EXPIRATION, 0, [u'extension']), (Action.TYPES.ADVANCEMENT, None, 0, [u'advancement']), (Action.TYPES.CLARIFICATION_REQUEST, None, 0, [u'clarification_request']), (Action.TYPES.DISCLOSURE, None, 0, [u'disclosure']), (Action.TYPES.REFUSAL, None, 0, [u'refusal']), (Action.TYPES.AFFIRMATION, None, 0, [u'refusal', u'appeal', u'affirmation']), (Action.TYPES.REVERSION, None, 0, [u'refusal', u'appeal', u'reversion']), (Action.TYPES.REMANDMENT, Action.TYPES.EXPIRATION, 0, [u'refusal', u'appeal', u'remandment']), (Action.TYPES.ADVANCED_REQUEST, Action.TYPES.EXPIRATION, 1, [u'advancement']), (Action.TYPES.EXPIRATION, None, 0, [u'expiration']), (Action.TYPES.APPEAL_EXPIRATION, None, 0, [u'refusal', u'appeal', u'appeal_expiration']), ) # Make sure we are testing all defined action types tested_action_types = set(a for a, _, _, _ in tests) defined_action_types = Action.TYPES._inverse.keys() self.assertItemsEqual(tested_action_types, defined_action_types) for action_type, expected_action_type, branch, scenario in tests: timewarp.jump(local_datetime_from_local(u'2010-07-05 10:33:00')) objs = self._create_inforequest_scenario(*scenario) branch = [o for o in flatten(objs) if isinstance(o, Branch)][branch] self.assertEqual(branch.last_action.type, action_type) original_last_action = branch.last_action # Deadline not expired yet with created_instances(Action.objects) as action_set: branch.add_expiration_if_expired() self.assertEqual(action_set.count(), 0) # Any deadline is expired now timewarp.jump(local_datetime_from_local(u'2010-10-05 10:33:00')) branch = Branch.objects.get(pk=branch.pk) with created_instances(Action.objects) as action_set: branch.add_expiration_if_expired() branch = Branch.objects.get(pk=branch.pk) if expected_action_type is None: self.assertEqual(action_set.count(), 0) self.assertEqual(branch.last_action, original_last_action) else: added_action = action_set.get() self.assertEqual(branch.last_action, added_action) self.assertEqual(added_action.type, expected_action_type) self.assertEqual(added_action.effective_date, naive_date(u'2010-10-05'))
def test_order_by_effective_date_query_method(self): dates = [ u'2014-10-04', u'2014-10-05', u'2014-10-06', # Several with the same date, to check secondary ordering u'2014-10-06', u'2014-10-06', u'2014-10-06', u'2014-10-06', u'2014-11-05', u'2015-10-05', ] random.shuffle(dates) inforequest = self._create_inforequest() branch = self._create_branch(inforequest=inforequest) actions = [] for date in dates: actions.append(self._create_action(branch=branch, effective_date=naive_date(date))) result = Action.objects.order_by_effective_date() self.assertEqual(list(result), sorted(actions, key=lambda a: (a.effective_date, a.pk)))
def test_post_with_valid_data_creates_action_instance(self): scenario = self._create_scenario(email_args=dict( subject=u'Subject', text=u'Content', processed=utc_datetime_from_local(u'2010-10-05 00:33:00'))) attachment1 = self._create_attachment(generic_object=scenario.email, name=u'filename.txt', content=u'content', content_type=u'text/plain') attachment2 = self._create_attachment(generic_object=scenario.email, name=u'filename.html', content=u'<p>content</p>', content_type=u'text/html') data = self._create_post_data(branch=scenario.branch) url = self._create_url(scenario) self._login_user() with created_instances(scenario.branch.action_set) as action_set: response = self.client.post( url, data, HTTP_X_REQUESTED_WITH=u'XMLHttpRequest') action = action_set.get() self.assertEqual(action.email, scenario.email) self.assertEqual(action.type, self.action_type) self.assertEqual(action.subject, u'Subject') self.assertEqual(action.content, u'Content') self.assertEqual(action.effective_date, naive_date(u'2010-10-05')) attachments = [(a.name, a.content, a.content_type) for a in action.attachment_set.all()] self.assertItemsEqual(attachments, [ (u'filename.txt', u'content', u'text/plain'), (u'filename.html', u'<p>content</p>', u'text/html'), ]) scenario.rel = InforequestEmail.objects.get(pk=scenario.rel.pk) self.assertEqual(scenario.rel.type, InforequestEmail.TYPES.OBLIGEE_ACTION)
def test_order_by_effective_date_query_method(self): dates = [ u'2014-10-04', u'2014-10-05', u'2014-10-06', # Several with the same date, to check secondary ordering u'2014-10-06', u'2014-10-06', u'2014-10-06', u'2014-10-06', u'2014-11-05', u'2015-10-05', ] random.shuffle(dates) inforequest = self._create_inforequest() branch = self._create_branch(inforequest=inforequest) actions = [] for date in dates: actions.append( self._create_action(branch=branch, effective_date=naive_date(date))) result = Action.objects.order_by_effective_date() self.assertEqual( list(result), sorted(actions, key=lambda a: (a.effective_date, a.pk)))
def test_number_of_workdays_in_2017(self): result = workdays.between(naive_date(u'2016-12-31'), naive_date(u'2017-12-31')) self.assertEqual(result, 247)
def test_effective_date_field(self): inforequest = self._create_inforequest() branch = self._create_branch(inforequest=inforequest) action = self._create_action(branch=branch, effective_date=naive_date(u'2010-10-05')) self.assertEqual(action.effective_date, naive_date(u'2010-10-05'))
def test_effective_date_field(self): inforequest = self._create_inforequest() draft = self._create_action_draft(inforequest=inforequest, effective_date=naive_date(u'2010-10-05')) self.assertEqual(draft.effective_date, naive_date(u'2010-10-05'))
def test_number_of_workdays_in_2017(self): result = workdays.between(naive_date(u"2016-12-31"), naive_date(u"2017-12-31")) self.assertEqual(result, 247)
def test_effective_date_field(self): inforequest = self._create_inforequest() draft = self._create_action_draft( inforequest=inforequest, effective_date=naive_date(u'2010-10-05')) self.assertEqual(draft.effective_date, naive_date(u'2010-10-05'))
def test_naive_date(self): value = naive_date(self._parse_dt(u'2014-08-15 03:45:00')) self._check_date(value, u'2014-08-15')