From 106ab2f6502408709ad0c39da1934a4c3488ad28 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 18 Oct 2022 11:18:50 +0200 Subject: [PATCH] add tests and redirect from abstract device to twin page --- ereuse_devicehub/resources/device/views.py | 5 ++++- tests/test_render_2_0.py | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index e6e158a4..6896089c 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -137,7 +137,10 @@ class DeviceView(View): return self.one_private(id) def one_public(self, id: int): - device = Device.query.filter_by(devicehub_id=id, active=True).one() + devices = Device.query.filter_by(devicehub_id=id, active=True).all() + if not devices: + devices = [Device.query.filter_by(dhid_bk=id, active=True).one()] + device = devices[0] abstract = None if device.binding: return flask.redirect(device.public_link) diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index dbe3c851..bfb248f2 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1675,6 +1675,7 @@ def test_export_lots(user3: UserClientFlask): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_export_snapshot_json(user3: UserClientFlask): + # ?? file_name = 'real-eee-1001pxd.snapshot.13.json' snap = create_device(user3, file_name) @@ -2158,9 +2159,16 @@ def test_manual_binding(user3: UserClientFlask): # check new structure assert dev_wb.binding.phid == '1' assert dev_wb.binding.device == dev + assert dev_wb.phid() == dev.phid() + assert dev_wb.is_abstract() == dev.is_abstract() == 'Twin' + # assert dev_wb. assert Placeholder.query.filter_by(id=old_placeholder.id).first() is None assert Device.query.filter_by(id=old_placeholder.device.id).first() is None + body_real, status = user3.get(f'/devices/{dhid_real}') + body_abstract, status = user3.get(f'/devices/{dhid_abstract}') + assert body_real == body_abstract + @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__)