diff --git a/ereuse_devicehub/resources/lot/models.py b/ereuse_devicehub/resources/lot/models.py index 16220026..fd8a8373 100644 --- a/ereuse_devicehub/resources/lot/models.py +++ b/ereuse_devicehub/resources/lot/models.py @@ -21,6 +21,8 @@ from ereuse_devicehub.resources.user.models import User class Lot(Thing): id = db.Column(UUID(as_uuid=True), primary_key=True) # uuid is generated on init by default name = db.Column(CIText(), nullable=False) + description = db.Column(CIText()) + description.comment = """A comment about the lot.""" closed = db.Column(db.Boolean, default=False, nullable=False) closed.comment = """ A closed lot cannot be modified anymore. @@ -36,13 +38,14 @@ class Lot(Thing): descendant lots. """ - def __init__(self, name: str, closed: bool = closed.default.arg) -> None: + def __init__(self, name: str, closed: bool = closed.default.arg, + description: str = None) -> None: """ Initializes a lot :param name: :param closed: """ - super().__init__(id=uuid.uuid4(), name=name, closed=closed) + super().__init__(id=uuid.uuid4(), name=name, closed=closed, description=description) Path(self) # Lots have always one edge per default. def add_child(self, child): diff --git a/ereuse_devicehub/resources/lot/models.pyi b/ereuse_devicehub/resources/lot/models.pyi index ff060e7d..9ae74b8a 100644 --- a/ereuse_devicehub/resources/lot/models.pyi +++ b/ereuse_devicehub/resources/lot/models.pyi @@ -20,6 +20,7 @@ class Lot(Thing): closed = ... # type: Column devices = ... # type: relationship paths = ... # type: relationship + description = ... # type: Column def __init__(self, name: str, closed: bool = closed.default.arg) -> None: super().__init__() @@ -28,6 +29,7 @@ class Lot(Thing): self.closed = ... # type: bool self.devices = ... # type: Set[Device] self.paths = ... # type: Set[Path] + description = ... # type: str def add_child(self, child: Union[Lot, uuid.UUID]): pass diff --git a/ereuse_devicehub/resources/lot/schemas.py b/ereuse_devicehub/resources/lot/schemas.py index e2eaefec..2594f8b3 100644 --- a/ereuse_devicehub/resources/lot/schemas.py +++ b/ereuse_devicehub/resources/lot/schemas.py @@ -11,6 +11,7 @@ from ereuse_devicehub.resources.schemas import Thing class Lot(Thing): id = f.UUID(dump_only=True) name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True) + description = SanitizedStr(description=m.Lot.description.comment) closed = f.Boolean(missing=False, description=m.Lot.closed.comment) devices = NestedOn(Device, many=True, dump_only=True) children = NestedOn('Lot', many=True, dump_only=True) diff --git a/tests/test_lot.py b/tests/test_lot.py index 4316327e..051db214 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -25,11 +25,18 @@ In case of error, debug with: def test_lot_modify_patch_endpoint(user: UserClient): """Creates and modifies lot properties through the endpoint""" - l, _ = user.post({'name': 'foo'}, res=Lot) + l, _ = user.post({'name': 'foo', 'description': 'baz'}, res=Lot) assert l['name'] == 'foo' - user.patch({'name': 'bar'}, res=Lot, item=l['id'], status=204) + assert l['description'] == 'baz' + user.patch({'name': 'bar', 'description': 'bax'}, res=Lot, item=l['id'], status=204) l_after, _ = user.get(res=Lot, item=l['id']) assert l_after['name'] == 'bar' + assert l_after['description'] == 'bax' + + +@pytest.mark.xfail(reason='No DEL endpoint') +def test_lot_delete_endpoint(user: UserClient): + pass @pytest.mark.xfail(reason='the IN comparison does not work for device')