From 9a4a8ef9788395473460339792bd6aa3ec29bcdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ga=C3=ABtan=20Trellu?= Date: Mon, 10 Jun 2019 23:02:06 -0400 Subject: [PATCH] Fix date format to be compliant with UTC Currently the created_at and updated_at format is not compliant with UTC. "created_at": "2019-06-11 00:16:54", "updated_at": "2019-06-11 00:17:33", Should be: "created_at": "2019-06-11T00:16:54Z", "updated_at": "2019-06-11T00:17:33Z", Change-Id: I000c67a542b52602927fd802d2e347847f8dcc12 Story: 2005854 Task: 33647 --- qinling/db/sqlalchemy/model_base.py | 1 - qinling/tests/unit/api/controllers/v1/test_job.py | 9 +++++++-- qinling/utils/common.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/qinling/db/sqlalchemy/model_base.py b/qinling/db/sqlalchemy/model_base.py index e7f43809..b988d15f 100644 --- a/qinling/db/sqlalchemy/model_base.py +++ b/qinling/db/sqlalchemy/model_base.py @@ -85,7 +85,6 @@ class _QinlingModelBase(oslo_models.ModelBase, oslo_models.TimestampMixin): updated_at = getattr(self, 'updated_at') if updated_at: setattr(m, 'updated_at', updated_at.isoformat(' ')) - return m def __repr__(self): diff --git a/qinling/tests/unit/api/controllers/v1/test_job.py b/qinling/tests/unit/api/controllers/v1/test_job.py index 6f052bb4..c2ea6a5a 100644 --- a/qinling/tests/unit/api/controllers/v1/test_job.py +++ b/qinling/tests/unit/api/controllers/v1/test_job.py @@ -217,9 +217,12 @@ class TestJobController(base.APITest): count=10 ).id + next_hour_and_half = datetime.utcnow() + timedelta(hours=1.5) + next_two_hours = datetime.utcnow() + timedelta(hours=2) + req_body = { 'next_execution_time': str( - datetime.utcnow() + timedelta(hours=1.5) + next_hour_and_half.strftime('%Y-%m-%dT%H:%M:%SZ') ), 'pattern': '1 */1 * * *' } @@ -239,7 +242,9 @@ class TestJobController(base.APITest): req_body = { 'status': status.RUNNING, - 'next_execution_time': str(datetime.utcnow() + timedelta(hours=2)), + 'next_execution_time': str( + next_two_hours.strftime('%Y-%m-%dT%H:%M:%SZ') + ), } resp = self.app.put_json('/v1/jobs/%s' % job_id, req_body) diff --git a/qinling/utils/common.py b/qinling/utils/common.py index 1c09ca18..5eae1d1a 100644 --- a/qinling/utils/common.py +++ b/qinling/utils/common.py @@ -85,7 +85,7 @@ def datetime_to_str(dct, attr_name): """Convert datetime object in dict to string.""" if (dct.get(attr_name) is not None and not isinstance(dct.get(attr_name), six.string_types)): - dct[attr_name] = dct[attr_name].isoformat(' ') + dct[attr_name] = dct[attr_name].strftime('%Y-%m-%dT%H:%M:%SZ') def generate_unicode_uuid(dashed=True):