From 0f6364f075769f99bb9b28452bce84ded2796e53 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 22 Sep 2022 10:15:37 +0200 Subject: [PATCH] fix dhid_bk --- ereuse_devicehub/inventory/views.py | 5 +++-- tests/test_render_2_0.py | 29 +++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index f5fb87d6..1e0896de 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -299,8 +299,9 @@ class BindingView(GenericMixin): # to do a backup of abstract_dhid and abstract_phid in # workbench device - self.abstract_device.dhid_bk = self.abstract_dhid - self.abstract_device.phid_bk = self.abstract_phid + if self.abstract_device: + self.abstract_device.dhid_bk = self.abstract_dhid + self.abstract_device.phid_bk = self.abstract_phid def post(self): for plog in PlaceholdersLog.query.filter_by( diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 6b7769fc..b5e30b48 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -2339,3 +2339,32 @@ def test_list_erasures(user3: UserClientFlask): txt = "WD-WCAV27984668" assert status == '200 OK' assert txt in body + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_bug_3821_binding(user3: UserClientFlask): + uri = '/inventory/device/add/' + user3.get(uri) + + data = { + 'csrf_token': generate_csrf(), + 'type': "Laptop", + 'phid': 'sid', + 'serial_number': "AAAAB", + 'model': "LC27T55", + 'manufacturer': "Samsung", + 'generation': 1, + 'weight': 0.1, + 'height': 0.1, + 'depth': 0.1, + 'id_device_supplier': "b2", + } + user3.post(uri, data=data) + dev = Device.query.one() + dhid = dev.dhid + assert dev.phid() == 'sid' + uri = f'/inventory/binding/{dhid}/sid/' + body, status = user3.get(uri) + assert status == '200 OK' + assert 'is not a Snapshot device!' in body