From 0f7c9504b0ae6529eba3954b5596d93778f0fdf9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 15 Dec 2022 10:18:22 +0100 Subject: [PATCH] fix settings_version --- ereuse_devicehub/parser/models.py | 4 ++- ereuse_devicehub/parser/parser.py | 1 + ereuse_devicehub/parser/schemas.py | 1 + ...QMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json | 1 + tests/test_snapshot.py | 32 ++++--------------- 5 files changed, 13 insertions(+), 26 deletions(-) diff --git a/ereuse_devicehub/parser/models.py b/ereuse_devicehub/parser/models.py index 38ddbaf7..8caa0620 100644 --- a/ereuse_devicehub/parser/models.py +++ b/ereuse_devicehub/parser/models.py @@ -90,7 +90,9 @@ class SnapshotsLog(Thing): settings_version = self.snapshot.settings_version or '' settings_version = "".join([x[0] for x in settings_version.split(' ') if x]) - return "{} ({})".format(self.version, settings_version) + if settings_version: + return "{} ({})".format(self.version, settings_version) + return "{}".format(self.version) class PlaceholdersLog(Thing): diff --git a/ereuse_devicehub/parser/parser.py b/ereuse_devicehub/parser/parser.py index 49e7dee6..0dfe8a57 100644 --- a/ereuse_devicehub/parser/parser.py +++ b/ereuse_devicehub/parser/parser.py @@ -343,6 +343,7 @@ class ParseSnapshotLsHw: "components": self.components, "uuid": snapshot['uuid'], "version": "14.0.0", + "settings_version": snapshot.get("settings_version"), "endTime": snapshot["timestamp"], "elapsed": 1, "sid": snapshot["sid"], diff --git a/ereuse_devicehub/parser/schemas.py b/ereuse_devicehub/parser/schemas.py index 1a84b8bc..fbdc671d 100644 --- a/ereuse_devicehub/parser/schemas.py +++ b/ereuse_devicehub/parser/schemas.py @@ -22,6 +22,7 @@ class Snapshot_lite(Thing): sid = String(required=True) type = String(required=True) timestamp = String(required=True) + settings_version = String(required=False) data = Nested(Snapshot_lite_data, required=True) @validates_schema diff --git a/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json b/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json index 2a4c85a7..c8034fe6 100644 --- a/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json +++ b/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json @@ -6,6 +6,7 @@ "software": "Workbench", "version": "2022.03.00", "schema_api": "1.0.0", + "settings_version": "Basic Metadata", "data": { "lspci": "", "lshw": { diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index dad60950..2ee04e76 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -1420,29 +1420,11 @@ def test_bug_4028_components(user: UserClient): def test_settings_version(user: UserClient): """Tests when we have one computer and then we change the disk, then the new disk need to have placeholder too.""" - s = yaml2json('real-eee-1001pxd.snapshot.12') - s['settings_version'] = 'Basic Metadata (BM)' - snap1, _ = user.post(s, res=Snapshot) - dev1 = m.Device.query.filter_by(id=snap1['device']['id']).one() - assert m.Placeholder.query.count() * 2 == m.Device.query.count() - components1 = [c for c in dev1.components] - for c in s['components']: - if c['type'] == 'HardDrive': - c['serialNumber'] = 'E2024242CV86MF' + s = file_json("2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json") + body, res = user.post(s, uri="/api/inventory/") + assert m.Computer.query.first().dhid == body['dhid'] + snapshot = Snapshot.query.first() + log = SnapshotsLog.query.first() - s['uuid'] = str(uuid4()) - snap2, _ = user.post(s, res=Snapshot) - dev2 = m.Device.query.filter_by(id=snap2['device']['id']).one() - components2 = [c for c in dev2.components] - - assert '' not in [c.phid() for c in components1] - assert '' not in [c.phid() for c in components2] - assert len(components1) == len(components2) - assert m.Placeholder.query.count() == 16 - assert m.Placeholder.query.count() * 2 == m.Device.query.count() - for c in m.Placeholder.query.filter(): - assert c.binding - assert c.device - - for c in m.Device.query.filter(): - assert c.binding or c.placeholder + assert log.get_version() == "14.0 (BM)" + assert snapshot.settings_version == "Basic Metadata"