Adding severity to incomplete HID when POST an action Snapshot (#32)

* Adding severity to incomplete HID snapshot

* Minor fixes when HID are null
This commit is contained in:
Jordi Nadeu 2020-07-07 17:17:19 +02:00 committed by GitHub
parent d172a0e756
commit 75150437b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 8 deletions

View File

@ -12,7 +12,7 @@ from ereuse_devicehub.resources.action.models import Action, RateComputer, Snaps
InitTransfer InitTransfer
from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate from ereuse_devicehub.resources.action.rate.v1_0 import CannotRate
from ereuse_devicehub.resources.device.models import Component, Computer 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') SUPPORTED_WORKBENCH = StrictVersion('11.0')
@ -99,7 +99,9 @@ class ActionView(View):
snapshot.actions.add(price) snapshot.actions.add(price)
elif snapshot.software == SnapshotSoftware.WorkbenchAndroid: 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.add(snapshot)
db.session().final_flush() db.session().final_flush()
ret = self.schema.jsonify(snapshot) # transform it back ret = self.schema.jsonify(snapshot) # transform it back

View File

@ -52,7 +52,7 @@ class Device(Thing):
""" """
type = Column(Unicode(STR_SM_SIZE), nullable=False) type = Column(Unicode(STR_SM_SIZE), nullable=False)
hid = Column(Unicode(), check_lower('hid'), unique=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 systems use to ID a device globally. This field is auto-generated
from Devicehub using literal identifiers from the device, from Devicehub using literal identifiers from the device,
so it can re-generated *offline*. so it can re-generated *offline*.

View File

@ -12,7 +12,6 @@ from teal.marshmallow import ValidationError
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.action.models import Remove 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.device.models import Component, Computer, Device
from ereuse_devicehub.resources.tag.model import Tag 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 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' 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 db_device = None
if device.hid: if device.hid:
with suppress(ResourceNotFound): with suppress(ResourceNotFound):

View File

@ -247,6 +247,7 @@ def test_snapshot_post_without_hid(user: UserClient):
assert snapshot['author']['id'] == user.user['id'] assert snapshot['author']['id'] == user.user['id']
assert 'actions' not in snapshot['device'] assert 'actions' not in snapshot['device']
assert 'author' not in snapshot['device'] assert 'author' not in snapshot['device']
assert snapshot['severity'] == 'Warning'
response = user.post(snapshot, res=Snapshot) response = user.post(snapshot, res=Snapshot)
assert response.status == 201 assert response.status == 201