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
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

View file

@ -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*.

View file

@ -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):

View file

@ -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