From bef5df414b9a775de3bf48a72f6846be3b049613 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 22 Nov 2021 11:14:27 +0100 Subject: [PATCH] fixing bug in sync --- ereuse_devicehub/resources/device/sync.py | 2 +- tests/test_action.py | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 81c57657..8608ad95 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -154,7 +154,7 @@ class Sync: db_device = None if device.hid: with suppress(ResourceNotFound): - db_device = Device.query.filter_by(hid=device.hid, owner_id=g.user.id).one() + db_device = Device.query.filter_by(hid=device.hid, owner_id=g.user.id, active=True).one() if db_device and db_device.allocated: raise ResourceNotFound('device is actually allocated {}'.format(device)) try: diff --git a/tests/test_action.py b/tests/test_action.py index 53287bb6..f7a1240f 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -2856,23 +2856,24 @@ def test_delete_devices_check_sync(user: UserClient): file_snap1 = file('1-device-with-components.snapshot') file_snap2 = file('2-device-with-components.snapshot') - snap, _ = user.post(file_snap, res=models.Snapshot) + snap, _ = user.post(file_snap1, 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) + snap2, _ = user.post(file_snap2, 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() + # check than device2 is an other device than device1 + assert device2.id != device1.id + # check than device2 have the components of device1 + assert len([x for x in device2.components + if device1.id in [y.device.id for y in x.actions if hasattr(y, 'device')]]) == 1 @pytest.mark.mvp