chassis not required

This commit is contained in:
Cayo Puigdefabregas 2020-12-16 22:05:33 +01:00
parent b1c141e02b
commit aef220a5dc
3 changed files with 19 additions and 15 deletions

View File

@ -101,7 +101,7 @@ class Computer(Device):
collection_class=OrderedSet, collection_class=OrderedSet,
description='The components that are inside this computer.') description='The components that are inside this computer.')
chassis = EnumField(enums.ComputerChassis, chassis = EnumField(enums.ComputerChassis,
required=False, required=True,
description=m.Computer.chassis.comment) description=m.Computer.chassis.comment)
ram_size = Integer(dump_only=True, ram_size = Integer(dump_only=True,
data_key='ramSize', data_key='ramSize',

View File

@ -1,5 +1,5 @@
from contextlib import suppress from contextlib import suppress
from enum import Enum, IntEnum, unique from enum import Enum, IntEnum, unique, EnumMeta
from typing import Set, Union from typing import Set, Union
import inflection import inflection
@ -207,9 +207,20 @@ class DisplayTech(Enum):
return self.name 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 @unique
class ComputerChassis(Enum): class ComputerChassis(Enum, metaclass=DefaultEnumMeta):
"""The chassis of a computer.""" """The chassis of a computer."""
Nothing = None
Tower = 'Tower' Tower = 'Tower'
Docking = 'Docking' Docking = 'Docking'
AllInOne = 'All in one' AllInOne = 'All in one'

View File

@ -679,22 +679,15 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
@pytest.mark.mvp @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 """ """ This test check if the file snapshot is create when some snapshot is wrong """
tmp_snapshots = app.config['TMP_SNAPSHOTS'] tmp_snapshots = app.config['TMP_SNAPSHOTS']
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors') 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'] uuid = snapshot_error['uuid']
snapshot = {'software': '', 'version': '', 'uuid': ''} snapshot, res = user.post(res=Snapshot, data=snapshot_error)
with pytest.raises(TypeError):
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)