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 @property
def url(self) -> urlutils.URL: def url(self) -> urlutils.URL:
"""The URL where to GET this device.""" """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 @property
def rate(self): def rate(self):

View File

@ -62,7 +62,7 @@ class TagDeviceView(View):
if not tag.device: if not tag.device:
raise TagNotLinked(tag.id) raise TagNotLinked(tag.id)
if not request.authorization: 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) return app.resources[Device.t].schema.jsonify(tag.device)
# noinspection PyMethodOverriding # 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 # todo this could be more efficient by Device.query... join with tag
device = Tag.query.filter_by(id=id).one().device device = Tag.query.filter_by(id=id).one().device
if not request.authorization: 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: if device is None:
raise TagNotLinked(id) raise TagNotLinked(id)
return app.resources[Device.t].schema.jsonify(device) 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 @pytest.mark.mvp
def test_device_query(user: UserClient): def test_device_query(user: UserClient):
"""Checks result of inventory.""" """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) i, _ = user.get(res=Device)
assert i['url'] == '/devices/' 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') pc = next(d for d in i['items'] if d['type'] == 'Desktop')
assert len(pc['actions']) == 4 assert len(pc['actions']) == 4
assert len(pc['components']) == 3 assert len(pc['components']) == 3

View File

@ -63,7 +63,7 @@ def test_snapshot_model():
assert m.Desktop.query.one_or_none() is None assert m.Desktop.query.one_or_none() is None
assert m.Device.query.one_or_none() is None assert m.Device.query.one_or_none() is None
# Check properties # 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 @pytest.mark.mvp
@ -115,7 +115,8 @@ def test_same_device_tow_users(user: UserClient, user2: UserClient):
i, _ = user.get(res=m.Device) i, _ = user.get(res=m.Device)
pc = next(d for d in i['items'] if d['type'] == 'Desktop') pc = next(d for d in i['items'] if d['type'] == 'Desktop')
pc_id = pc['id'] 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 = file('basic.snapshot')
basic_snapshot['uuid'] = f"{uuid.uuid4()}" basic_snapshot['uuid'] = f"{uuid.uuid4()}"
@ -837,5 +838,3 @@ def test_snapshot_mobil(app: Devicehub, user: UserClient):
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
shutil.rmtree(tmp_snapshots) shutil.rmtree(tmp_snapshots)