From 04a3ec99dedf3af490c702f6a4c30f5b97b2bb4c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 28 Oct 2022 14:08:51 +0200 Subject: [PATCH] change response --- ereuse_devicehub/api/views.py | 6 ++++-- tests/test_snapshot.py | 9 +++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/api/views.py b/ereuse_devicehub/api/views.py index b4ed2032..c566be00 100644 --- a/ereuse_devicehub/api/views.py +++ b/ereuse_devicehub/api/views.py @@ -72,11 +72,13 @@ class InventoryView(LoginMixin, SnapshotMixin): db.session().final_flush() db.session.commit() + url = "https://{}/".format(app.config['HOST']) + public_url = "{}{}".format(url.strip("/"), snapshot.device.url.to_text()) self.response = jsonify( { - 'url': snapshot.device.url.to_text(), 'dhid': snapshot.device.dhid, - 'sid': snapshot.sid, + 'url': url, + 'public_url': public_url, } ) self.response.status_code = 201 diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index a4753943..a1c711b8 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -1001,7 +1001,7 @@ def test_snapshot_wb_lite(user: UserClient): ssd = [x for x in dev.components if x.type == 'SolidStateDrive'][0] assert dev.manufacturer == 'lenovo' - assert body['sid'] == "MLKO1Y0R55XZM051WQ5KJM01RY44Q" + assert dev.dhid in body['public_url'] assert ssd.serial_number == 's35anx0j401001' assert res.status == '201 CREATED' assert '00:28:f8:a6:d5:7e' in dev.hid @@ -1020,11 +1020,11 @@ def test_snapshot_wb_lite_qemu(user: UserClient): snapshot = file_json("qemu-cc9927a9-55ad-4937-b36b-7185147d9fa9.json") body, res = user.post(snapshot, uri="/api/inventory/") - assert body['sid'] == "VL0L5" assert res.status == '201 CREATED' dev = m.Device.query.filter_by(devicehub_id=body['dhid']).one() dev = dev.placeholder.binding + assert dev.dhid in body['public_url'] assert dev.manufacturer == 'qemu' assert dev.model == 'standard' assert dev.serial_number is None @@ -1170,7 +1170,8 @@ def test_snapshot_lite_minimum(user: UserClient): }, } bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/") - assert bodyLite['sid'] == 'MLKO1' + dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() + assert dev.dhid in bodyLite['public_url'] assert res.status_code == 201 @@ -1197,10 +1198,10 @@ def test_snapshot_lite_error_in_components(user: UserClient): }, } bodyLite, res = user.post(snapshot_lite, uri="/api/inventory/") - assert bodyLite['sid'] == 'MLKO1' assert res.status_code == 201 dev = m.Device.query.filter_by(devicehub_id=bodyLite['dhid']).one() + assert dev.dhid in bodyLite['public_url'] assert 'Motherboard' not in [x.type for x in dev.components] error = SnapshotsLog.query.all() assert 'StopIteration' in error[0].description