def test_serialize_empty_doc(self): schema = JobSchema() job_data = {} doc, errors = schema.dump(job_data) self.assertEqual(0, len(errors)) self.assertEqual({}, doc)
def test_serialize_timezone_naive(self): schema = JobSchema() job_data = { 'scheduleStart': datetime(2015, 10, 7, 13, 44, 53, 123456), 'scheduleEnd': datetime(2015, 10, 10, 4, 10, 3, 654321) } doc, errors = schema.dump(job_data) self.assertEqual(0, len(errors)) expected_data = { 'scheduleStart': '2015-10-07T13:44:53.123456+00:00', 'scheduleEnd': '2015-10-10T04:10:03.654321+00:00' } self.assertEqual(expected_data, doc)
def test_serialize_timezone_offsets(self): schema = JobSchema() job_data = { 'scheduleStart': datetime(2015, 10, 7, 13, 44, 53, 123456, timezone(timedelta(hours=10))), 'scheduleEnd': datetime(2015, 10, 10, 4, 10, 3, 654321, timezone(timedelta(hours=-6))), 'timezone': 'US/Eastern' } doc, errors = schema.dump(job_data) self.assertEqual(0, len(errors)) expected_data = { 'scheduleStart': '2015-10-07T13:44:53.123456+10:00', 'scheduleEnd': '2015-10-10T04:10:03.654321-06:00', 'timezone': 'US/Eastern' } self.assertEqual(expected_data, doc)
def test_serialize(self): schema = JobSchema() job_data = { 'id': 'idIsIgnored', 'taskDefinition': 'test-task', 'schedule': 'test-schedule', 'scheduleStart': datetime(2015, 10, 7, 13, 44, 53, 123456, timezone.utc), 'scheduleEnd': datetime(2015, 10, 10, 4, 10, 3, 654321, timezone.utc), 'timezone': 'UTC', 'taskCount': 12, 'suspended': True, 'trigger': { 'type': 'test-type' }, 'overrides': [{ 'containerName': 'test-container', 'environment': { 'foo': 'foo_value', 'bar': 'bar_value', 'baz': 'baz_value' } }] } doc, errors = schema.dump(job_data) self.assertEqual(0, len(errors)) expected_data = { 'taskDefinition': 'test-task', 'schedule': 'test-schedule', 'scheduleStart': '2015-10-07T13:44:53.123456+00:00', 'scheduleEnd': '2015-10-10T04:10:03.654321+00:00', 'timezone': 'UTC', 'taskCount': 12, 'suspended': True, 'trigger': { 'type': 'test-type' }, 'overrides': [{ 'containerName': 'test-container', 'environment': { 'foo': 'foo_value', 'bar': 'bar_value', 'baz': 'baz_value' } }] } self.assertEqual(expected_data, doc)