def test_set_sets_back_value_to_none(self): deadline = SimpleDeadline() deadline.set(ended_at='2020-02-04').set(ended_at=None) self.assertEqual(deadline._data_dict, { 'ended_at': None, 'message': None })
def test_set_auto_convert_camelcase_keys_into_snakecase(self): deadline = SimpleDeadline() deadline.set(**{'endedAt': '2020-02-04'}) self.assertEqual(deadline._data_dict, { 'ended_at': date(2020, 2, 4), 'message': None })
def test_update_does_not_trigger_transform(self): deadline = SimpleDeadline() deadline.update(ended_at='2020-02-04') self.assertEqual(deadline._data_dict, { 'ended_at': '2020-02-04', 'message': None })
def test_set_triggers_transform(self): deadline = SimpleDeadline() deadline.set(ended_at='2020-02-04') self.assertEqual(deadline._data_dict, { 'ended_at': date.fromisoformat('2020-02-04'), 'message': None })
def test_date_raises_if_value_is_not_date(self): deadline = SimpleDeadline(ended_at=True) with self.assertRaises(ValidationException) as context: deadline.validate() self.assertEqual(len(context.exception.keypath_messages), 1) self.assertEqual(context.exception.keypath_messages['endedAt'], "value is not date")
def test_update_raises_if_given_key_is_not_allowed(self): deadline = SimpleDeadline() with self.assertRaises(ValueError) as context: deadline.update(**{'name': 'a', 'value': 'b'}) self.assertRegex( str(context.exception), "'(name|value)', '(value|name)' not allowed in " "SimpleDeadline\\.")
def test_update_does_not_auto_convert_camelcase_keys_into_snakecase(self): deadline = SimpleDeadline() with self.assertRaises(ValueError): deadline.update(**{'endedAt': '2020-02-04'})
def test_date_is_date_after_assigned(self): deadline = SimpleDeadline(ended_at=date(2020, 11, 20)) self.assertEqual(deadline._data_dict, {'ended_at': date(2020, 11, 20), 'message': None})
def test_date_is_datetime_str_when_tojson(self): deadline = SimpleDeadline(ended_at='2020-11-20T03:03:03.333Z') self.assertEqual(deadline.tojson(), {'endedAt': '2020-11-20T00:00:00.000Z'})
def test_datetime_converts_datetime_str_into_date(self): deadline = SimpleDeadline(ended_at='2020-11-20T03:03:03.333Z') self.assertEqual(deadline.ended_at, date(2020, 11, 20))
def test_date_converts_datetime_into_date(self): deadline = SimpleDeadline(ended_at=datetime(2020, 6, 30, 1, 1, 1)) self.assertEqual(deadline.ended_at, date(2020, 6, 30))
def test_tojson_auto_camelize_keys_by_default(self): deadline = SimpleDeadline(ended_at='2021-03-04') self.assertEqual(deadline.tojson(), {'endedAt': '2021-03-04T00:00:00.000Z'})
def test_initialize_triggers_transform(self): deadline = SimpleDeadline(ended_at='2021-06-30') self.assertEqual(deadline.ended_at, date(2021, 6, 30))