예제 #1
0
 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
     })
예제 #2
0
 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
     })
예제 #3
0
 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
     })
예제 #4
0
 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
     })
예제 #5
0
 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")
예제 #6
0
 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\\.")
예제 #7
0
 def test_update_does_not_auto_convert_camelcase_keys_into_snakecase(self):
     deadline = SimpleDeadline()
     with self.assertRaises(ValueError):
         deadline.update(**{'endedAt': '2020-02-04'})
예제 #8
0
 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})
예제 #9
0
 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'})
예제 #10
0
 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))
예제 #11
0
 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))
예제 #12
0
 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'})
예제 #13
0
 def test_initialize_triggers_transform(self):
     deadline = SimpleDeadline(ended_at='2021-06-30')
     self.assertEqual(deadline.ended_at, date(2021, 6, 30))