Ensure only computers can have components

This commit is contained in:
Xavier Bustamante Talavera 2018-09-21 10:43:15 +02:00
parent e9eec80be7
commit bc95fa98b1
2 changed files with 21 additions and 1 deletions

View file

@ -55,7 +55,10 @@ class Sync:
db_device = self.execute_register(device)
db_components, events = OrderedSet(), OrderedSet()
if components is not None: # We have component info (see above)
assert isinstance(db_device, Computer)
if not isinstance(db_device, Computer):
# Until a good reason is given, we synthetically forbid
# non-computers with components
raise ValidationError('Only computers can have components.')
blacklist = set() # type: Set[int]
not_new_components = set()
for component in components:

View file

@ -5,6 +5,7 @@ from uuid import uuid4
import pytest
from teal.db import UniqueViolation
from teal.marshmallow import ValidationError
from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db
@ -281,6 +282,22 @@ def test_snapshot_upload_twice_uuid_error(user: UserClient):
user.post(pc1, res=Snapshot, status=UniqueViolation)
def test_snapshot_component_containing_components(user: UserClient):
"""There is no reason for components to have components and when
this happens it is always an error.
This test avoids this until an appropriate use-case is presented.
"""
s = file('basic.snapshot')
s['device'] = {
'type': 'Processor',
'serialNumber': 'foo',
'manufacturer': 'bar',
'model': 'baz'
}
user.post(s, res=Snapshot, status=ValidationError)
def test_erase(user: UserClient):
"""Tests a Snapshot with EraseSectors."""
s = file('erase-sectors.snapshot')