From 75150437b6777ff3e592414deaf874f3f397813d Mon Sep 17 00:00:00 2001 From: Jordi Nadeu Date: Tue, 7 Jul 2020 17:17:19 +0200 Subject: [PATCH] Adding severity to incomplete HID when POST an action Snapshot (#32) * Adding severity to incomplete HID snapshot * Minor fixes when HID are null --- ereuse_devicehub/resources/action/views.py | 8 +++++--- ereuse_devicehub/resources/device/models.py | 2 +- ereuse_devicehub/resources/device/sync.py | 4 ---- tests/test_snapshot.py | 1 + 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/ereuse_devicehub/resources/action/views.py b/ereuse_devicehub/resources/action/views.py index 0c098352..37d8873c 100644 --- a/ereuse_devicehub/resources/action/views.py +++ b/ereuse_devicehub/resources/action/views.py @@ -12,7 +12,7 @@ from ereuse_devicehub.resources.action.models import Action, RateComputer, Snaps InitTransfer from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate from ereuse_devicehub.resources.device.models import Component, Computer -from ereuse_devicehub.resources.enums import SnapshotSoftware +from ereuse_devicehub.resources.enums import SnapshotSoftware, Severity SUPPORTED_WORKBENCH = StrictVersion('11.0') @@ -98,8 +98,10 @@ class ActionView(View): if price: snapshot.actions.add(price) elif snapshot.software == SnapshotSoftware.WorkbenchAndroid: - pass # TODO try except to compute RateMobile - + pass # TODO try except to compute RateMobile + # Check if HID is null and add Severity:Warning to Snapshot + if snapshot.device.hid is None: + snapshot.severity = Severity.Warning db.session.add(snapshot) db.session().final_flush() ret = self.schema.jsonify(snapshot) # transform it back diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 0d5f11e9..0184b56c 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -52,7 +52,7 @@ class Device(Thing): """ type = Column(Unicode(STR_SM_SIZE), nullable=False) hid = Column(Unicode(), check_lower('hid'), unique=False) - hid.comment = """The Hardware ID (HID) is the unique ID traceability + hid.comment = """The Hardware ID (HID) is the ID traceability systems use to ID a device globally. This field is auto-generated from Devicehub using literal identifiers from the device, so it can re-generated *offline*. diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index a299f801..5f13d5a0 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -12,7 +12,6 @@ from teal.marshmallow import ValidationError from ereuse_devicehub.db import db from ereuse_devicehub.resources.action.models import Remove -from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.models import Component, Computer, Device from ereuse_devicehub.resources.tag.model import Tag @@ -151,9 +150,6 @@ class Sync: """ assert inspect(device).transient, 'Device cannot be already synced from DB' assert all(inspect(tag).transient for tag in device.tags), 'Tags cannot be synced from DB' - if not device.tags and not device.hid: - # We cannot identify this device - raise NeedsId() db_device = None if device.hid: with suppress(ResourceNotFound): diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 098e0c5f..5df769cd 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -247,6 +247,7 @@ def test_snapshot_post_without_hid(user: UserClient): assert snapshot['author']['id'] == user.user['id'] assert 'actions' not in snapshot['device'] assert 'author' not in snapshot['device'] + assert snapshot['severity'] == 'Warning' response = user.post(snapshot, res=Snapshot) assert response.status == 201