Skip to content

Commit 5ce46d2

Browse files
committed
Adding UTC to fetcher response
1 parent f0d9c84 commit 5ce46d2

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

api/datalake_api/fetcher.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations under
1313
# the License.
14+
from datetime import datetime, timezone
1415
from mimetypes import guess_type
1516
from datalake.common import Metadata
1617
from datalake.common.errors import NoSuchDatalakeFile
@@ -76,6 +77,20 @@ def get_file(self, file_id):
7677
key = self._get_s3_key(file_id)
7778
fd = key['Body']
7879
j = json.loads(key['Metadata']['datalake'])
80+
start_utc = j['start']
81+
end_utc = j['end']
82+
83+
if start_utc:
84+
start_utc = datetime.fromtimestamp(
85+
start_utc / 1000.0, tz=timezone.utc
86+
).isoformat()
87+
if end_utc:
88+
end_utc = datetime.fromtimestamp(
89+
end_utc / 1000.0, tz=timezone.utc
90+
).isoformat()
91+
j['start_UTC'] = start_utc
92+
j['end_UTC'] = end_utc
93+
7994
metadata = Metadata(j)
8095
return ArchiveFile(fd, metadata)
8196

api/tests/test_metadata.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
1212
# License for the specific language governing permissions and limitations under
1313
# the License.
14+
from datetime import datetime, timezone
1415
import pytest
1516
import simplejson as json
1617

@@ -32,7 +33,16 @@ def test_get_metadata(metadata_getter, s3_file_maker, random_metadata):
3233
res = metadata_getter('12345')
3334
assert res.status_code == 200
3435
assert res.content_type == 'application/json'
35-
assert json.loads(res.data) == random_metadata
36+
res_data = json.loads(res.data)
37+
for k, v in random_metadata.items():
38+
if k == 'start_UTC' or k == 'end_UTC':
39+
if v: # Null case
40+
expected_v_utc = datetime.fromtimestamp(
41+
v / 1000.0, tz=timezone.utc
42+
).isoformat()
43+
assert expected_v_utc == res_data[k]
44+
else:
45+
assert v == res_data[k]
3646

3747

3848
def test_no_such_metadata(s3_bucket_maker, metadata_getter):

0 commit comments

Comments
 (0)