fixing tests and property url of device

This commit is contained in:
Cayo Puigdefabregas 2021-03-09 12:54:57 +01:00
parent b83563e0ea
commit 2b60af8b08
7 changed files with 16 additions and 17 deletions

View file

@ -236,7 +236,7 @@ class Device(Thing):
@property
def url(self) -> urlutils.URL:
"""The URL where to GET this device."""
return urlutils.URL(url_for_resource(Device, item_id=self.id))
return urlutils.URL(url_for_resource(Device, item_id=self.devicehub_id))
@property
def rate(self):

View file

@ -62,7 +62,7 @@ class TagDeviceView(View):
if not tag.device:
raise TagNotLinked(tag.id)
if not request.authorization:
return redirect(location=url_for_resource(Device, tag.device.id))
return redirect(location=url_for_resource(Device, tag.device.devicehub_id))
return app.resources[Device.t].schema.jsonify(tag.device)
# noinspection PyMethodOverriding
@ -93,7 +93,7 @@ def get_device_from_tag(id: str):
# todo this could be more efficient by Device.query... join with tag
device = Tag.query.filter_by(id=id).one().device
if not request.authorization:
return redirect(location=url_for_resource(Device, device.id))
return redirect(location=url_for_resource(Device, device.devicehub_id))
if device is None:
raise TagNotLinked(id)
return app.resources[Device.t].schema.jsonify(device)

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View file

@ -176,10 +176,10 @@ def test_device_query_filter_lots(user: UserClient):
@pytest.mark.mvp
def test_device_query(user: UserClient):
"""Checks result of inventory."""
user.post(conftest.file('basic.snapshot'), res=Snapshot)
snap, _ = user.post(conftest.file('basic.snapshot'), res=Snapshot)
i, _ = user.get(res=Device)
assert i['url'] == '/devices/'
assert i['items'][0]['url'] == '/devices/1'
assert i['items'][0]['url'] == '/devices/%s' % snap['device']['devicehubID']
pc = next(d for d in i['items'] if d['type'] == 'Desktop')
assert len(pc['actions']) == 4
assert len(pc['components']) == 3

View file

@ -199,7 +199,7 @@ def test_live_example2(user: UserClient, client: Client, app: Devicehub):
assert str(action_live[0].snapshot_uuid) == acer['uuid']
@pytest.mark.mvp
@pytest.mark.mvp
def test_export_basic_snapshot(user: UserClient):
"""Test export device information in a csv file."""
snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot)

View file

@ -63,7 +63,7 @@ def test_snapshot_model():
assert m.Desktop.query.one_or_none() is None
assert m.Device.query.one_or_none() is None
# Check properties
assert device.url == urlutils.URL('http://localhost/devices/1')
assert device.url == urlutils.URL('http://localhost/devices/%s' % device.devicehub_id)
@pytest.mark.mvp
@ -115,7 +115,8 @@ def test_same_device_tow_users(user: UserClient, user2: UserClient):
i, _ = user.get(res=m.Device)
pc = next(d for d in i['items'] if d['type'] == 'Desktop')
pc_id = pc['id']
assert i['items'][0]['url'] == f'/devices/{pc_id}'
devicehub_id = pc['devicehubID']
assert i['items'][0]['url'] == f'/devices/{devicehub_id}'
basic_snapshot = file('basic.snapshot')
basic_snapshot['uuid'] = f"{uuid.uuid4()}"
@ -550,7 +551,7 @@ def snapshot_and_check(user: UserClient,
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_erase_changing_hdd_between_pcs(user: UserClient):
"""Tests when we erase one device and next change the disk in other device we
"""Tests when we erase one device and next change the disk in other device we
want see in the second device the disks erase."""
s1 = file('erase-sectors-2-hdd.snapshot')
s2 = file('erase-sectors-2-hdd.snapshot2')
@ -617,7 +618,7 @@ def test_save_snapshot_in_file(app: Devicehub, user: UserClient):
@pytest.mark.mvp
def test_action_no_snapshot_without_save_file(app: Devicehub, user: UserClient):
""" This test check if the function save_snapshot_in_file not work when we
""" This test check if the function save_snapshot_in_file not work when we
send one other action different to snapshot
"""
s = file('laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot')
@ -738,7 +739,7 @@ def test_snapshot_not_failed_null_chassis(app: Devicehub, user: UserClient):
tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
snapshot_error = file('desktop-9644w8n-lenovo-0169622.snapshot')
snapshot_error['device']['chassis'] = None
snapshot_error['device']['chassis'] = None
uuid = snapshot_error['uuid']
snapshot, res = user.post(res=Snapshot, data=snapshot_error)
@ -819,7 +820,7 @@ def test_snapshot_bug_smallint_hdd(app: Devicehub, user: UserClient):
snapshot, _ = user.post(res=Snapshot, data=snapshot_file)
act = [act for act in snapshot['actions'] if act['type'] == 'TestDataStorage'][0]
assert act['currentPendingSectorCount'] == 473302660
assert act['currentPendingSectorCount'] == 473302660
assert act['offlineUncorrectable'] == 182042944
tmp_snapshots = app.config['TMP_SNAPSHOTS']
@ -837,5 +838,3 @@ def test_snapshot_mobil(app: Devicehub, user: UserClient):
tmp_snapshots = app.config['TMP_SNAPSHOTS']
shutil.rmtree(tmp_snapshots)