Ensure only computers can have components
This commit is contained in:
parent
e9eec80be7
commit
bc95fa98b1
|
@ -55,7 +55,10 @@ class Sync:
|
||||||
db_device = self.execute_register(device)
|
db_device = self.execute_register(device)
|
||||||
db_components, events = OrderedSet(), OrderedSet()
|
db_components, events = OrderedSet(), OrderedSet()
|
||||||
if components is not None: # We have component info (see above)
|
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]
|
blacklist = set() # type: Set[int]
|
||||||
not_new_components = set()
|
not_new_components = set()
|
||||||
for component in components:
|
for component in components:
|
||||||
|
|
|
@ -5,6 +5,7 @@ from uuid import uuid4
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from teal.db import UniqueViolation
|
from teal.db import UniqueViolation
|
||||||
|
from teal.marshmallow import ValidationError
|
||||||
|
|
||||||
from ereuse_devicehub.client import UserClient
|
from ereuse_devicehub.client import UserClient
|
||||||
from ereuse_devicehub.db import db
|
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)
|
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):
|
def test_erase(user: UserClient):
|
||||||
"""Tests a Snapshot with EraseSectors."""
|
"""Tests a Snapshot with EraseSectors."""
|
||||||
s = file('erase-sectors.snapshot')
|
s = file('erase-sectors.snapshot')
|
||||||
|
|
Reference in New Issue