diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index f5b0aced..7f883ab1 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -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: diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 66160a8e..3126c75a 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -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')