fixing tests snapshots

This commit is contained in:
Cayo Puigdefabregas 2021-07-05 12:31:43 +02:00
parent b8e9ed22f6
commit 56078dbd8a
2 changed files with 10 additions and 4 deletions

View File

@ -142,12 +142,16 @@ def auth_app_context(app: Devicehub):
def json_encode(dev: str) -> dict: def json_encode(dev: str) -> dict:
"""Encode json.""" """Encode json."""
return jwt.encode(dev, data = {"type": "Snapshot"}
data['data'] = jwt.encode(dev,
P, P,
algorithm="HS256", algorithm="HS256",
json_encoder=ereuse_utils.JSONEncoder json_encoder=ereuse_utils.JSONEncoder
) )
return data
def yaml2json(name: str) -> dict: def yaml2json(name: str) -> dict:
"""Opens and parses a YAML file from the ``files`` subdir.""" """Opens and parses a YAML file from the ``files`` subdir."""

View File

@ -112,7 +112,8 @@ def test_snapshot_post(user: UserClient):
@pytest.mark.mvp @pytest.mark.mvp
def test_same_device_tow_users(user: UserClient, user2: UserClient): def test_same_device_tow_users(user: UserClient, user2: UserClient):
"""Two users can up the same snapshot and the system save 2 computers""" """Two users can up the same snapshot and the system save 2 computers"""
user.post(yaml2json('basic.snapshot'), res=Snapshot) # import pdb; pdb.set_trace()
user.post(file('basic.snapshot'), res=Snapshot)
i, _ = user.get(res=m.Device) i, _ = user.get(res=m.Device)
pc = next(d for d in i['items'] if d['type'] == 'Desktop') pc = next(d for d in i['items'] if d['type'] == 'Desktop')
pc_id = pc['id'] pc_id = pc['id']
@ -408,6 +409,7 @@ def test_erase_privacy_standards_endtime_sort(user: UserClient):
This tests ensures that only the last erasure is picked up, as This tests ensures that only the last erasure is picked up, as
erasures have always custom endTime value set. erasures have always custom endTime value set.
""" """
# import pdb; pdb.set_trace()
s = yaml2json('erase-sectors.snapshot') s = yaml2json('erase-sectors.snapshot')
assert s['components'][0]['actions'][0]['endTime'] == '2018-06-01T09:12:06+02:00' assert s['components'][0]['actions'][0]['endTime'] == '2018-06-01T09:12:06+02:00'
snapshot = snapshot_and_check(user, s, action_types=( snapshot = snapshot_and_check(user, s, action_types=(
@ -465,7 +467,7 @@ def test_erase_privacy_standards_endtime_sort(user: UserClient):
# Let's try a second erasure with an error # Let's try a second erasure with an error
s['uuid'] = uuid4() s['uuid'] = uuid4()
s['components'][0]['actions'][0]['severity'] = 'Error' s['components'][0]['actions'][0]['severity'] = 'Error'
snapshot, _ = user.post(s, res=Snapshot) snapshot, _ = user.post(json_encode(s), res=Snapshot)
storage, _ = user.get(res=m.Device, item=storage['devicehubID']) storage, _ = user.get(res=m.Device, item=storage['devicehubID'])
assert storage['hid'] == 'solidstatedrive-c1mr-c1ml-c1s' assert storage['hid'] == 'solidstatedrive-c1mr-c1ml-c1s'
assert storage['privacy']['type'] == 'EraseSectors' assert storage['privacy']['type'] == 'EraseSectors'
@ -524,7 +526,7 @@ def snapshot_and_check(user: UserClient,
:return: The last resulting snapshot. :return: The last resulting snapshot.
""" """
snapshot, _ = user.post(res=Snapshot, data=input_snapshot) snapshot, _ = user.post(res=Snapshot, data=json_encode(input_snapshot))
assert all(e['type'] in action_types for e in snapshot['actions']) assert all(e['type'] in action_types for e in snapshot['actions'])
assert len(snapshot['actions']) == len(action_types) assert len(snapshot['actions']) == len(action_types)
# Ensure there is no Remove action after the first Add # Ensure there is no Remove action after the first Add