diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index db0f3c43..d3671c1b 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -101,7 +101,7 @@ class Computer(Device): collection_class=OrderedSet, description='The components that are inside this computer.') chassis = EnumField(enums.ComputerChassis, - required=False, + required=True, description=m.Computer.chassis.comment) ram_size = Integer(dump_only=True, data_key='ramSize', diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index b9665f8f..7648e7d7 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -1,5 +1,5 @@ from contextlib import suppress -from enum import Enum, IntEnum, unique +from enum import Enum, IntEnum, unique, EnumMeta from typing import Set, Union import inflection @@ -207,9 +207,20 @@ class DisplayTech(Enum): return self.name +class DefaultEnumMeta(EnumMeta): + default = object() + + def __call__(cls, value=default, *args, **kwargs): + # import pdb; pdb.set_trace() + if value is DefaultEnumMeta.default: + # Assume the first enum is default + return next(iter(cls)) + return super().__call__(value, *args, **kwargs) + @unique -class ComputerChassis(Enum): +class ComputerChassis(Enum, metaclass=DefaultEnumMeta): """The chassis of a computer.""" + Nothing = None Tower = 'Tower' Docking = 'Docking' AllInOne = 'All in one' diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 278aa299..7b3f5e20 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -679,24 +679,17 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient) @pytest.mark.mvp -def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient): +def test_snapshot_not_failed_null_chassis(app: Devicehub, user: UserClient): """ This test check if the file snapshot is create when some snapshot is wrong """ tmp_snapshots = app.config['TMP_SNAPSHOTS'] path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors') - snapshot_error = file('failed.snapshot.422.null-chassis') + snapshot_error = file('desktop-9644w8n-lenovo-0169622.snapshot') + snapshot_error['device']['chassis'] = 'Nothing' uuid = snapshot_error['uuid'] - snapshot = {'software': '', 'version': '', 'uuid': ''} - with pytest.raises(TypeError): - user.post(res=Snapshot, data=snapshot_error) + snapshot, res = user.post(res=Snapshot, data=snapshot_error) - files = [x for x in os.listdir(path_dir_base) if uuid in x] - if files: - path_snapshot = os.path.join(path_dir_base, files[0]) - with open(path_snapshot) as file_snapshot: - snapshot = json.loads(file_snapshot.read()) - - shutil.rmtree(tmp_snapshots) + shutil.rmtree(tmp_snapshots) assert snapshot['software'] == snapshot_error['software'] assert snapshot['version'] == snapshot_error['version']