From 818e3ad0cc33762304b6f8e3bfda786dd2baf359 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 19 Nov 2021 12:44:52 +0100 Subject: [PATCH] new tests --- ereuse_devicehub/resources/action/models.py | 2 ++ tests/test_action.py | 29 ++++++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index ce88ed4b..93cdcdef 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1774,6 +1774,8 @@ class MoveOnDocument(JoinedTableMixin, ActionWithMultipleTradeDocuments): class Delete(ActionWithMultipleDevices): + # TODO in a new architecture we need rename this class to Deactivate + """The act save in device who and why this devices was delete. We never delete one device, but we can deactivate.""" pass diff --git a/tests/test_action.py b/tests/test_action.py index d8216ab7..53287bb6 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -2827,7 +2827,7 @@ def test_delete_devices(user: UserClient): snap, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) request = {'type': 'Delete', 'devices': [snap['device']['id']], 'name': 'borrado universal', 'severity': 'Info', 'description': 'duplicity of devices', 'endTime': '2021-07-07T22:00:00.000Z'} - + action, _ = user.post(res=models.Action, data=request) # Check get one device @@ -2841,6 +2841,7 @@ def test_delete_devices(user: UserClient): assert db_device.active == False + # Check use of filter from frontend url = '/devices/?filter={"type":["Computer"]}' @@ -2848,6 +2849,32 @@ def test_delete_devices(user: UserClient): assert len(devices['items']) == 0 +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_delete_devices_check_sync(user: UserClient): + """This action deactive one device and simulate than one devices is delete.""" + + file_snap1 = file('1-device-with-components.snapshot') + file_snap2 = file('2-device-with-components.snapshot') + snap, _ = user.post(file_snap, res=models.Snapshot) + request = {'type': 'Delete', 'devices': [snap['device']['id']], 'name': 'borrado universal', 'severity': 'Info', 'description': 'duplicity of devices', 'endTime': '2021-07-07T22:00:00.000Z'} + + action, _ = user.post(res=models.Action, data=request) + + device1 = Device.query.filter_by(id=snap['device']['id']).one() + + snap2, _ = user.post(file_snap, res=models.Snapshot) + request2 = {'type': 'Delete', 'devices': [snap2['device']['id']], 'name': 'borrado universal', 'severity': 'Info', 'description': 'duplicity of devices', 'endTime': '2021-07-07T22:00:00.000Z'} + + action2, _ = user.post(res=models.Action, data=request2) + + device2 = Device.query.filter_by(id=snap2['device']['id']).one() + # TODO problems with alembic and migrations + # TODO check than device2 is an other device than device1 + # TODO check than device2 have the components of device1 + import pdb; pdb.set_trace() + + @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_moveOnDocument_bug168(user: UserClient, user2: UserClient):