Add description in lot, xfail test for lot delete

This commit is contained in:
Xavier Bustamante Talavera 2018-11-06 18:08:57 +01:00
parent 665a9036e8
commit b5e3d0c6ec
4 changed files with 17 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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