From 56078dbd8a5cb7611289d9117f3183001e8dd219 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 5 Jul 2021 12:31:43 +0200 Subject: [PATCH] fixing tests snapshots --- tests/conftest.py | 6 +++++- tests/test_snapshot.py | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 6a7ce73d..147a907d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -142,12 +142,16 @@ def auth_app_context(app: Devicehub): def json_encode(dev: str) -> dict: """Encode json.""" - return jwt.encode(dev, + data = {"type": "Snapshot"} + data['data'] = jwt.encode(dev, P, algorithm="HS256", json_encoder=ereuse_utils.JSONEncoder ) + return data + + def yaml2json(name: str) -> dict: """Opens and parses a YAML file from the ``files`` subdir.""" diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 8049542f..dd05534a 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -112,7 +112,8 @@ def test_snapshot_post(user: UserClient): @pytest.mark.mvp def test_same_device_tow_users(user: UserClient, user2: UserClient): """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) pc = next(d for d in i['items'] if d['type'] == 'Desktop') 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 erasures have always custom endTime value set. """ + # import pdb; pdb.set_trace() s = yaml2json('erase-sectors.snapshot') assert s['components'][0]['actions'][0]['endTime'] == '2018-06-01T09:12:06+02:00' 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 s['uuid'] = uuid4() 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']) assert storage['hid'] == 'solidstatedrive-c1mr-c1ml-c1s' assert storage['privacy']['type'] == 'EraseSectors' @@ -524,7 +526,7 @@ def snapshot_and_check(user: UserClient, :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 len(snapshot['actions']) == len(action_types) # Ensure there is no Remove action after the first Add