change schema_version for schema_api

This commit is contained in:
Cayo Puigdefabregas 2022-04-08 16:46:57 +02:00
parent 50d0dffc16
commit 09738478ae
6 changed files with 25 additions and 10 deletions

View file

@ -63,7 +63,7 @@ class DevicehubConfig(Config):
"""The minimum version of ereuse.org workbench that this devicehub """The minimum version of ereuse.org workbench that this devicehub
accepts. we recommend not changing this value. accepts. we recommend not changing this value.
""" """
WORKBENCH_LITE = ["V1"] WORKBENCH_LITE = ["1.0.0"]
TMP_SNAPSHOTS = config('TMP_SNAPSHOTS', '/tmp/snapshots') TMP_SNAPSHOTS = config('TMP_SNAPSHOTS', '/tmp/snapshots')
TMP_LIVES = config('TMP_LIVES', '/tmp/lives') TMP_LIVES = config('TMP_LIVES', '/tmp/lives')

View file

@ -253,7 +253,7 @@ class UploadSnapshotForm(FlaskForm, SnapshotMix):
for filename, snapshot_json in self.snapshots: for filename, snapshot_json in self.snapshots:
path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email) path_snapshot = save_json(snapshot_json, self.tmp_snapshots, g.user.email)
snapshot_json.pop('debug', None) snapshot_json.pop('debug', None)
version = snapshot_json.get('schema_version') version = snapshot_json.get('schema_api')
if self.is_wb_lite_snapshot(version): if self.is_wb_lite_snapshot(version):
self.snapshot_json = schema_lite.load(snapshot_json) self.snapshot_json = schema_lite.load(snapshot_json)
snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json snapshot_json = ParseSnapshotLsHw(self.snapshot_json).snapshot_json

View file

@ -11,12 +11,13 @@ class Snapshot_lite_data(MarshmallowSchema):
hwinfo = String(required=False) hwinfo = String(required=False)
smart = List(Dict(), required=False) smart = List(Dict(), required=False)
lshw = Dict(required=False) lshw = Dict(required=False)
lspci = String(required=False)
class Snapshot_lite(Thing): class Snapshot_lite(Thing):
uuid = String(required=True) uuid = String(required=True)
version = String(required=True) version = String(required=True)
schema_version = String(required=True) schema_api = String(required=True)
software = String(required=True) software = String(required=True)
wbid = String(required=True) wbid = String(required=True)
type = String(required=True) type = String(required=True)
@ -25,7 +26,7 @@ class Snapshot_lite(Thing):
@validates_schema @validates_schema
def validate_workbench_version(self, data: dict): 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( raise ValidationError(
'Min. supported Workbench version is ' 'Min. supported Workbench version is '
'{} but yours is {}.'.format( '{} but yours is {}.'.format(

View file

@ -5,8 +5,9 @@
"wbid": "MLKO1Y0R55XZM051WQ5KJM01RY44Q", "wbid": "MLKO1Y0R55XZM051WQ5KJM01RY44Q",
"software": "Workbench", "software": "Workbench",
"version": "2022.03.00", "version": "2022.03.00",
"schema_version": "V1", "schema_api": "1.0.0",
"data": { "data": {
"lspci": "",
"lshw": { "lshw": {
"id": "__", "id": "__",
"class": "system", "class": "system",

View file

@ -5,8 +5,9 @@
"wbid": "YKPZ27NJ2NMRO4893M4L5NRZV5YJ1", "wbid": "YKPZ27NJ2NMRO4893M4L5NRZV5YJ1",
"software": "Workbench", "software": "Workbench",
"version": "2022.03.00", "version": "2022.03.00",
"schema_version": "V1", "schema_api": "1.0.0",
"data": { "data": {
"lspci": "",
"lshw": { "lshw": {
"id": "wb", "id": "wb",
"class": "system", "class": "system",

View file

@ -1023,8 +1023,14 @@ def test_snapshot_wb_lite_old_snapshots(user: UserClient):
'wbid': 'MLKO1', 'wbid': 'MLKO1',
'software': 'Workbench', 'software': 'Workbench',
'version': '2022.03.00', 'version': '2022.03.00',
"schema_version": "V1", "schema_api": "1.0.0",
'data': {'lshw': lshw, 'hwinfo': hwinfo, 'smart': [], 'dmidecode': ''}, 'data': {
'lshw': lshw,
'hwinfo': hwinfo,
'smart': [],
'dmidecode': '',
'lspci': '',
},
} }
body11, res = user.post(snapshot_11, res=Snapshot) body11, res = user.post(snapshot_11, res=Snapshot)
@ -1073,8 +1079,14 @@ def test_snapshot_errors(user: UserClient):
'wbid': 'MLKO1', 'wbid': 'MLKO1',
'software': 'Workbench', 'software': 'Workbench',
'version': '2022.03.00', 'version': '2022.03.00',
"schema_version": "V1", "schema_api": "1.0.0",
'data': {'lshw': lshw, 'hwinfo': hwinfo, 'smart': [], 'dmidecode': ''}, 'data': {
'lshw': lshw,
'hwinfo': hwinfo,
'smart': [],
'dmidecode': '',
'lspci': '',
},
} }
assert SnapshotErrors.query.all() == [] assert SnapshotErrors.query.all() == []