From 45a21eb2104e05227ff9ccf600ea99fd0afe0610 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 22 Sep 2022 12:08:37 +0200 Subject: [PATCH] add placeholder device in lot instead of snapshot device --- ereuse_devicehub/inventory/forms.py | 2 +- tests/test_render_2_0.py | 42 +++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 88ba70b0..f8ad673f 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -299,7 +299,7 @@ class UploadSnapshotForm(SnapshotMixin, FlaskForm): response = self.build(snapshot_json) db.session.add(response) - devices.append(response.device) + devices.append(response.device.binding.device) if hasattr(response, 'type'): self.result[filename] = 'Ok' diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 6b7769fc..96853efd 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -181,6 +181,48 @@ def test_upload_snapshot(user3: UserClientFlask): assert len(dev.components) == 9 +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_upload_snapshot_to_lot(user3: UserClientFlask): + # TODO + user3.get('/inventory/lot/add/') + lot_name = 'lot1' + data = { + 'name': lot_name, + 'csrf_token': generate_csrf(), + } + user3.post('/inventory/lot/add/', data=data) + lot = Lot.query.filter_by(name=lot_name).one() + + lot_id = lot.id + uri = f'/inventory/lot/{lot_id}/upload-snapshot/' + file_name = 'real-eee-1001pxd.snapshot.12.json' + user3.get(uri) + + snapshot = conftest.yaml2json(file_name.split(".json")[0]) + b_snapshot = bytes(json.dumps(snapshot), 'utf-8') + file_snap = (BytesIO(b_snapshot), file_name) + + data = { + 'snapshot': file_snap, + 'csrf_token': generate_csrf(), + } + body, status = user3.post(uri, data=data, content_type="multipart/form-data") + + txt = f"{file_name}: Ok" + assert status == '200 OK' + assert txt in body + db_snapthot = Snapshot.query.one() + dev = db_snapthot.device + assert dev not in lot.devices + assert dev.binding.device in lot.devices + + uri = f'/inventory/lot/{lot_id}/device/' + body, status = user3.get(uri) + assert dev.binding.device.devicehub_id in body + assert dev.binding.phid in body + + @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_inventory_with_device(user3: UserClientFlask):