From 09738478ae7b0b80843d3d15ec2aec104ee4a314 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 8 Apr 2022 16:46:57 +0200 Subject: [PATCH] change schema_version for schema_api --- ereuse_devicehub/config.py | 2 +- ereuse_devicehub/inventory/forms.py | 2 +- ereuse_devicehub/parser/schemas.py | 5 +++-- ...QMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json | 3 ++- ...KPZ27NJ2NMRO4893M4L5NRZV5YJ1_snapshot.json | 3 ++- tests/test_snapshot.py | 20 +++++++++++++++---- 6 files changed, 25 insertions(+), 10 deletions(-) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index 2d9118f5..c9c47b1b 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -63,7 +63,7 @@ class DevicehubConfig(Config): """The minimum version of ereuse.org workbench that this devicehub accepts. we recommend not changing this value. """ - WORKBENCH_LITE = ["V1"] + WORKBENCH_LITE = ["1.0.0"] TMP_SNAPSHOTS = config('TMP_SNAPSHOTS', '/tmp/snapshots') TMP_LIVES = config('TMP_LIVES', '/tmp/lives') diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index b36378cb..f99f48a7 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -253,7 +253,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix): for filename, snapshot_json in self.snapshots: path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) snapshot_json.pop('debug', None) - version = snapshot_json.get('schema_version') + version = snapshot_json.get('schema_api') if self.is_wb_lite_snapshot(version): self.snapshot_json = schema_lite.load(snapshot_json) snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json diff --git a/ereuse_devicehub/parser/schemas.py b/ereuse_devicehub/parser/schemas.py index ad2ccdb1..f65f9090 100644 --- a/ereuse_devicehub/parser/schemas.py +++ b/ereuse_devicehub/parser/schemas.py @@ -11,12 +11,13 @@ class Snapshot_lite_data(MarshmallowSchema): hwinfo = String(required=False) smart = List(Dict(), required=False) lshw = Dict(required=False) + lspci = String(required=False) class Snapshot_lite(Thing): uuid = String(required=True) version = String(required=True) - schema_version = String(required=True) + schema_api = String(required=True) software = String(required=True) wbid = String(required=True) type = String(required=True) @@ -25,7 +26,7 @@ class Snapshot_lite(Thing): @validates_schema def validate_workbench_version(self, data: dict): - if data['schema_version'] not in app.config['WORKBENCH_LITE']: + if data['schema_api'] not in app.config['WORKBENCH_LITE']: raise ValidationError( 'Min. supported Workbench version is ' '{} but yours is {}.'.format( diff --git a/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json b/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json index 3093c7e5..45065b64 100644 --- a/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json +++ b/tests/files/2022-03-31_17h18m51s_ZQMPKKX51K67R68VO2X9RNZL08JPL_snapshot.json @@ -5,8 +5,9 @@ "wbid": "MLKO1Y0R55XZM051WQ5KJM01RY44Q", "software": "Workbench", "version": "2022.03.00", - "schema_version": "V1", + "schema_api": "1.0.0", "data": { + "lspci": "", "lshw": { "id": "__", "class": "system", diff --git a/tests/files/2022-04-01_06h28m54s_YKPZ27NJ2NMRO4893M4L5NRZV5YJ1_snapshot.json b/tests/files/2022-04-01_06h28m54s_YKPZ27NJ2NMRO4893M4L5NRZV5YJ1_snapshot.json index f33f2988..f11364c8 100644 --- a/tests/files/2022-04-01_06h28m54s_YKPZ27NJ2NMRO4893M4L5NRZV5YJ1_snapshot.json +++ b/tests/files/2022-04-01_06h28m54s_YKPZ27NJ2NMRO4893M4L5NRZV5YJ1_snapshot.json @@ -5,8 +5,9 @@ "wbid": "YKPZ27NJ2NMRO4893M4L5NRZV5YJ1", "software": "Workbench", "version": "2022.03.00", - "schema_version": "V1", + "schema_api": "1.0.0", "data": { + "lspci": "", "lshw": { "id": "wb", "class": "system", diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 11f6f4f9..87756e25 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -1023,8 +1023,14 @@ def test_snapshot_wb_lite_old_snapshots(user: UserClient): 'wbid': 'MLKO1', 'software': 'Workbench', 'version': '2022.03.00', - "schema_version": "V1", - 'data': {'lshw': lshw, 'hwinfo': hwinfo, 'smart': [], 'dmidecode': ''}, + "schema_api": "1.0.0", + 'data': { + 'lshw': lshw, + 'hwinfo': hwinfo, + 'smart': [], + 'dmidecode': '', + 'lspci': '', + }, } body11, res = user.post(snapshot_11, res=Snapshot) @@ -1073,8 +1079,14 @@ def test_snapshot_errors(user: UserClient): 'wbid': 'MLKO1', 'software': 'Workbench', 'version': '2022.03.00', - "schema_version": "V1", - 'data': {'lshw': lshw, 'hwinfo': hwinfo, 'smart': [], 'dmidecode': ''}, + "schema_api": "1.0.0", + 'data': { + 'lshw': lshw, + 'hwinfo': hwinfo, + 'smart': [], + 'dmidecode': '', + 'lspci': '', + }, } assert SnapshotErrors.query.all() == []