-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtest_metadata.py
More file actions
60 lines (51 loc) · 2.01 KB
/
test_metadata.py
File metadata and controls
60 lines (51 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Copyright 2016 Planet Labs, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
from datetime import datetime, timezone
from decimal import Decimal
import pytest
import simplejson as json
@pytest.fixture
def metadata_getter(client):
def getter(file_id):
uri = '/v0/archive/files/' + file_id + '/metadata'
return client.get(uri)
return getter
def test_get_metadata(metadata_getter, s3_file_maker, random_metadata):
random_metadata['id'] = '12345'
content = 'once upon a time'
s3_file_maker('datalake-test', '12345/data', content, random_metadata)
res = metadata_getter('12345')
assert res.status_code == 200
assert res.content_type == 'application/json'
res_data = json.loads(res.data)
for k, v in res_data.items():
if k == 'start_iso' or k == 'end_iso':
k_epoch = k.replace('_iso','')
v_epoch = res_data[k_epoch]
if v is None:
assert v == v_epoch
expected_v_iso = datetime.fromtimestamp(
v_epoch / 1000.0, tz=timezone.utc
).isoformat(timespec='milliseconds').replace('+00:00', 'Z')
assert v == expected_v_iso
else:
assert v == random_metadata[k]
def test_no_such_metadata(s3_bucket_maker, metadata_getter):
s3_bucket_maker('datalake-test')
res = metadata_getter('12345')
assert res.status_code == 404
response = json.loads(res.get_data())
assert 'code' in response
assert response['code'] == 'NoSuchFile'
assert 'message' in response