From c554d30291027752ef3ba16694265fcb91ecdbab Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 5 Jul 2021 15:04:44 +0200 Subject: [PATCH] fixing tests --- ereuse_devicehub/dummy/dummy.py | 15 ++++++++++++++- tests/conftest.py | 4 +++- tests/test_action.py | 2 +- tests/test_snapshot.py | 1 - 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index 183dbb9f..04fbdaf3 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -1,5 +1,6 @@ import itertools import json +import jwt from pathlib import Path from typing import Set @@ -94,7 +95,7 @@ class Dummy: for path in bar: with path.open() as f: snapshot = yaml.load(f) - s, _ = user1.post(res=m.Snapshot, data=snapshot) + s, _ = user1.post(res=m.Snapshot, data=self.json_encode(snapshot)) if s.get('uuid', None) == 'ec23c11b-80b6-42cd-ac5c-73ba7acddbc4': sample_pc = s['device']['id'] sample_pc_devicehub_id = s['device']['devicehubID'] @@ -206,3 +207,15 @@ class Dummy: response_wrapper=self.app.response_class) client.login() return client + + def json_encode(self, dev: str) -> dict: + """Encode json.""" + data = {"type": "Snapshot"} + data['data'] = jwt.encode(dev, + self.app.config['JWT_PASS'], + algorithm="HS256", + json_encoder=ereuse_utils.JSONEncoder + ) + + return data + diff --git a/tests/conftest.py b/tests/conftest.py index 147a907d..991374ba 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ import ereuse_utils from contextlib import redirect_stdout from datetime import datetime from pathlib import Path +from decouple import config import boltons.urlutils import pytest @@ -28,8 +29,8 @@ ENDT = datetime(year=2000, month=1, day=1, hour=2) """A dummy ending time to use in tests.""" T = {'start_time': STARTT, 'end_time': ENDT} """A dummy start_time/end_time to use as function keywords.""" +P = config('JWT_PASS', '') -P = '7KU4ZzsEfe' class TestConfig(DevicehubConfig): SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test' @@ -39,6 +40,7 @@ class TestConfig(DevicehubConfig): TMP_LIVES = '/tmp/lives' EMAIL_ADMIN = 'foo@foo.com' PATH_DOCUMENTS_STORAGE = '/tmp/trade_documents' + JWT_PASS = config('JWT_PASS', '') @pytest.fixture(scope='session') diff --git a/tests/test_action.py b/tests/test_action.py index 565f0d37..5c0af44f 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -484,7 +484,7 @@ def test_live_without_hdd_3(user: UserClient, client: Client, app: Devicehub): acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec3" components = [a for a in acer['components'] if a['type'] != 'HardDrive'] acer['components'] = components - snapshot, _ = user.post(acer, res=models.Snapshot) + snapshot, _ = user.post(json_encode(acer), res=models.Snapshot) device_id = snapshot['device']['id'] db_device = Device.query.filter_by(id=device_id).one() post_request = {"transaction": "ccc", "name": "John", "endUsers": 1, diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index dd05534a..94b8f04f 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -409,7 +409,6 @@ 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=(