Switched to different datetime formatting in JSON.

We now use the same format as the Pillar API.
This commit is contained in:
2016-11-07 10:55:49 +01:00
parent fe2c36328a
commit ea33d69a8e
2 changed files with 4 additions and 2 deletions

View File

@@ -22,6 +22,8 @@ else:
string_type = basestring
text_type = unicode
JSON_DATE_FORMAT = '%a, %d %b %Y %H:%M:%S GMT'
class PillarJSONEncoder(json.JSONEncoder):
"""JSON encoder with support for Pillar resources."""
@@ -31,7 +33,7 @@ class PillarJSONEncoder(json.JSONEncoder):
from .resource import Resource
if isinstance(obj, datetime.datetime):
return obj.isoformat(' ')
return obj.strftime(JSON_DATE_FORMAT)
if isinstance(obj, Resource):
return obj.to_dict()

View File

@@ -68,7 +68,7 @@ class PillarUtilsTests(unittest.TestCase):
resource['datetime'] = datetime.datetime(2016, 3, 22, 12, 35, 16)
as_json = json.dumps(resource, cls=utils.PillarJSONEncoder, sort_keys=True)
self.assertEqual('{"datetime": "2016-03-22 12:35:16"}', as_json)
self.assertEqual('{"datetime": "Tue, 22 Mar 2016 12:35:16 GMT"}', as_json)
def test_sanitize_filename(self):