fixing tests

This commit is contained in:
Cayo Puigdefabregas 2021-07-05 15:04:44 +02:00
parent 25482125a3
commit c554d30291
4 changed files with 18 additions and 4 deletions

View File

@ -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

View File

@ -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')

View File

@ -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,

View File

@ -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=(