From 9faa1697a71ea593e7f0ae3037be1ef6dc6fd976 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 21:14:10 +0200 Subject: [PATCH] fixing event device --- ereuse_devicehub/resources/device/models.py | 10 ++-------- tests/test_action.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index ebf1d858..187dfb9c 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -36,16 +36,10 @@ from ereuse_devicehub.resources.device.metrics import Metrics def create_code(context): - # import pdb; pdb.set_trace() _id = Device.query.order_by(Device.id.desc()).first() or 3 if not _id == 3: _id = _id.id + 1 - code = hashcode.encode(_id) - - # from ereuse_devicehub.resources.tag.model import Tag - # tag = Tag(device_id=_id, id=code) - # db.session.add(tag) - return code + return hashcode.encode(_id) class Device(Thing): @@ -1183,4 +1177,4 @@ def create_code_tag(mapper, connection, device): from flask_sqlalchemy import event -event.listen(Device, 'after_update', create_code_tag, propagate=True) +event.listen(Device, 'after_insert', create_code_tag, propagate=True) diff --git a/tests/test_action.py b/tests/test_action.py index 825bdb0a..888541f3 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -260,10 +260,10 @@ def test_generic_action(action_model_state: Tuple[models.Action, states.Trading] @pytest.mark.parametrize('action_model', (pytest.param(ams, id=ams.__class__.__name__) for ams in [ - models.Recycling, - models.Use, - models.Refurbish, - models.Management + models.Recycling, + models.Use, + models.Refurbish, + models.Management ])) def test_simple_status_actions(action_model: models.Action, user: UserClient, user2: UserClient): """Simple test of status action.""" @@ -281,10 +281,10 @@ def test_simple_status_actions(action_model: models.Action, user: UserClient, us @pytest.mark.parametrize('action_model', (pytest.param(ams, id=ams.__class__.__name__) for ams in [ - models.Recycling, - models.Use, - models.Refurbish, - models.Management + models.Recycling, + models.Use, + models.Refurbish, + models.Management ])) def test_outgoinlot_status_actions(action_model: models.Action, user: UserClient, user2: UserClient): """Test of status actions in outgoinlot."""