fixing tests
This commit is contained in:
parent
25482125a3
commit
c554d30291
|
@ -1,5 +1,6 @@
|
||||||
import itertools
|
import itertools
|
||||||
import json
|
import json
|
||||||
|
import jwt
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
|
@ -94,7 +95,7 @@ class Dummy:
|
||||||
for path in bar:
|
for path in bar:
|
||||||
with path.open() as f:
|
with path.open() as f:
|
||||||
snapshot = yaml.load(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':
|
if s.get('uuid', None) == 'ec23c11b-80b6-42cd-ac5c-73ba7acddbc4':
|
||||||
sample_pc = s['device']['id']
|
sample_pc = s['device']['id']
|
||||||
sample_pc_devicehub_id = s['device']['devicehubID']
|
sample_pc_devicehub_id = s['device']['devicehubID']
|
||||||
|
@ -206,3 +207,15 @@ class Dummy:
|
||||||
response_wrapper=self.app.response_class)
|
response_wrapper=self.app.response_class)
|
||||||
client.login()
|
client.login()
|
||||||
return client
|
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
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import ereuse_utils
|
||||||
from contextlib import redirect_stdout
|
from contextlib import redirect_stdout
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from decouple import config
|
||||||
|
|
||||||
import boltons.urlutils
|
import boltons.urlutils
|
||||||
import pytest
|
import pytest
|
||||||
|
@ -28,8 +29,8 @@ ENDT = datetime(year=2000, month=1, day=1, hour=2)
|
||||||
"""A dummy ending time to use in tests."""
|
"""A dummy ending time to use in tests."""
|
||||||
T = {'start_time': STARTT, 'end_time': ENDT}
|
T = {'start_time': STARTT, 'end_time': ENDT}
|
||||||
"""A dummy start_time/end_time to use as function keywords."""
|
"""A dummy start_time/end_time to use as function keywords."""
|
||||||
|
P = config('JWT_PASS', '')
|
||||||
|
|
||||||
P = '7KU4ZzsEfe'
|
|
||||||
|
|
||||||
class TestConfig(DevicehubConfig):
|
class TestConfig(DevicehubConfig):
|
||||||
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test'
|
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/dh_test'
|
||||||
|
@ -39,6 +40,7 @@ class TestConfig(DevicehubConfig):
|
||||||
TMP_LIVES = '/tmp/lives'
|
TMP_LIVES = '/tmp/lives'
|
||||||
EMAIL_ADMIN = 'foo@foo.com'
|
EMAIL_ADMIN = 'foo@foo.com'
|
||||||
PATH_DOCUMENTS_STORAGE = '/tmp/trade_documents'
|
PATH_DOCUMENTS_STORAGE = '/tmp/trade_documents'
|
||||||
|
JWT_PASS = config('JWT_PASS', '')
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope='session')
|
@pytest.fixture(scope='session')
|
||||||
|
|
|
@ -484,7 +484,7 @@ def test_live_without_hdd_3(user: UserClient, client: Client, app: Devicehub):
|
||||||
acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec3"
|
acer['uuid'] = "490fb8c0-81a1-42e9-95e0-5e7db7038ec3"
|
||||||
components = [a for a in acer['components'] if a['type'] != 'HardDrive']
|
components = [a for a in acer['components'] if a['type'] != 'HardDrive']
|
||||||
acer['components'] = components
|
acer['components'] = components
|
||||||
snapshot, _ = user.post(acer, res=models.Snapshot)
|
snapshot, _ = user.post(json_encode(acer), res=models.Snapshot)
|
||||||
device_id = snapshot['device']['id']
|
device_id = snapshot['device']['id']
|
||||||
db_device = Device.query.filter_by(id=device_id).one()
|
db_device = Device.query.filter_by(id=device_id).one()
|
||||||
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
post_request = {"transaction": "ccc", "name": "John", "endUsers": 1,
|
||||||
|
|
|
@ -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
|
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=(
|
||||||
|
|
Reference in New Issue