From dc8aea9b9bca52a036a2a49bbba79f1eb84a3b43 Mon Sep 17 00:00:00 2001 From: nad Date: Tue, 3 Mar 2020 12:03:09 +0100 Subject: [PATCH] Adds display size to mobile device schema --- ereuse_devicehub/resources/action/schemas.py | 10 +++++++--- ereuse_devicehub/resources/action/views.py | 6 ++++-- ereuse_devicehub/resources/device/models.py | 2 ++ ereuse_devicehub/resources/device/models.pyi | 2 ++ ereuse_devicehub/resources/device/schemas.py | 3 +++ ereuse_devicehub/resources/enums.py | 1 + 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 8ba3c84e..7ef82dd4 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -318,7 +318,7 @@ class Snapshot(ActionWithOneDevice): @validates_schema def validate_components_only_workbench(self, data: dict): - if data['software'] != SnapshotSoftware.Workbench: + if (data['software'] != SnapshotSoftware.Workbench) and (data['software'] != SnapshotSoftware.WorkbenchAndroid): if data.get('components', None) is not None: raise ValidationError('Only Workbench can add component info', field_names=['components']) @@ -329,14 +329,18 @@ class Snapshot(ActionWithOneDevice): # todo test if data['software'] == SnapshotSoftware.Workbench: if not data.get('uuid', None): - raise ValidationError('Snapshots from Workbench must have uuid', + raise ValidationError('Snapshots from Workbench and WorkbenchAndroid must have uuid', field_names=['uuid']) if data.get('elapsed', None) is None: raise ValidationError('Snapshots from Workbench must have elapsed', field_names=['elapsed']) + elif data['software'] == SnapshotSoftware.WorkbenchAndroid: + if not data.get('uuid', None): + raise ValidationError('Snapshots from Workbench and WorkbenchAndroid must have uuid', + field_names=['uuid']) else: if data.get('uuid', None): - raise ValidationError('Only Snapshots from Workbench can have uuid', + raise ValidationError('Only Snapshots from Workbench or WorkbenchAndroid can have uuid', field_names=['uuid']) if data.get('elapsed', None): raise ValidationError('Only Snapshots from Workbench can have elapsed', diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index de6805b4..30c35633 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -55,8 +55,8 @@ class ActionView(View): # snapshot, and we want to wait to flush snapshot at the end device = snapshot_json.pop('device') # type: Computer components = None - if snapshot_json['software'] == SnapshotSoftware.Workbench: - components = snapshot_json.pop('components') # type: List[Component] + if snapshot_json['software'] == (SnapshotSoftware.Workbench or SnapshotSoftware.WorkbenchAndroid): + components = snapshot_json.pop('components', None) # type: List[Component] snapshot = Snapshot(**snapshot_json) # Remove new actions from devices so they don't interfere with sync @@ -94,6 +94,8 @@ class ActionView(View): snapshot.actions.add(rate_computer) if price: snapshot.actions.add(price) + elif snapshot.software == SnapshotSoftware.WorkbenchAndroid: + pass # TODO try except to compute RateMobile db.session.add(snapshot) db.session().final_flush() diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 2bb8a221..0e2f07e7 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -512,6 +512,8 @@ class Mobile(Device): ram_size.comment = """The total of RAM of the device in MB.""" data_storage_size = db.Column(db.Integer, check_range('data_storage_size', 0, 10 ** 8)) data_storage_size.comment = """The total of data storage of the device in MB""" + display_size = db.Column(db.Float(decimal_return_scale=1), check_range('display_size', min=0.1, max=30.0)) + display_size.comment = """The total size of the device screen""" @validates('imei') def validate_imei(self, _, value: int): diff --git a/ereuse_devicehub/resources/device/models.pyi b/ereuse_devicehub/resources/device/models.pyi index 65605ce8..36a9b156 100644 --- a/ereuse_devicehub/resources/device/models.pyi +++ b/ereuse_devicehub/resources/device/models.pyi @@ -219,6 +219,7 @@ class Mobile(Device): meid = ... # type: Column ram_size = ... # type: Column data_storage_size = ... # type: Column + display_size = ... # type: Column def __init__(self, **kwargs) -> None: super().__init__(**kwargs) @@ -226,6 +227,7 @@ class Mobile(Device): self.meid = ... # type: Optional[str] self.ram_size = ... # type: Optional[int] self.data_storage_size = ... # type: Optional[int] + self.display_size = ... # type: Optional[float] class Smartphone(Mobile): diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 093cec75..f7d7fcb7 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -197,6 +197,9 @@ class Mobile(Device): data_storage_size = Integer(validate=Range(0, 10 ** 8), data_key='dataStorageSize', description=m.Mobile.data_storage_size) + display_size = Float(validate=Range(min=0.1, max=30.0), + data_key='displaySize', + description=m.Mobile.display_size.comment) @pre_load def convert_check_imei(self, data): diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index 91502d09..50d7ce33 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -9,6 +9,7 @@ import inflection class SnapshotSoftware(Enum): """The software used to perform the Snapshot.""" Workbench = 'Workbench' + WorkbenchAndroid = 'WorkbenchAndroid' AndroidApp = 'AndroidApp' Web = 'Web' DesktopApp = 'DesktopApp'