From 0d4c70a74e1e3aeac19670250e4aebcde014b554 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Jun 2021 15:49:31 +0200 Subject: [PATCH] fixing bug --- ereuse_devicehub/resources/lot/views.py | 9 +------ tests/test_action.py | 34 ++++++------------------- 2 files changed, 9 insertions(+), 34 deletions(-) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 29a77e86..f5b80ae3 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -230,15 +230,8 @@ class LotDeviceView(LotBaseChildrenView): if not ids: return - users = [g.user.id] - if lot.trade: - # all users involved in the trade action can modify the lot - trade_users = [lot.trade.user_from.id, lot.trade.user_to.id] - if g.user.id in trade_users: - users = trade_users - devices = set(Device.query.filter(Device.id.in_(ids)).filter( - Device.owner_id.in_(users))) + Device.owner==g.user)) lot.devices.update(devices) diff --git a/tests/test_action.py b/tests/test_action.py index 7c22d502..6e1aca2b 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -1642,7 +1642,7 @@ def test_trade_case4(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) + snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id']), ('id', snap2['device']['id']), @@ -1708,7 +1708,7 @@ def test_trade_case5(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) + snap2, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id']), ('id', snap2['device']['id']), @@ -1716,7 +1716,7 @@ def test_trade_case5(user: UserClient, user2: UserClient): lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), - query=devices[:-1]) + query=devices) # the manager shares the temporary lot with the SCRAP as an incoming lot # for the CRAP to confirm it @@ -1735,11 +1735,6 @@ def test_trade_case5(user: UserClient, user2: UserClient): user.post(res=models.Action, data=request_post) trade = models.Trade.query.one() - lot, _ = user.post({}, - res=Lot, - item='{}/devices'.format(lot['id']), - query=devices[-1:]) - device1, device2 = trade.devices assert device1.actions[-2].t == 'Trade' @@ -1850,7 +1845,6 @@ def test_trade_case7(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id'])] lot, _ = user.post({}, @@ -1917,7 +1911,6 @@ def test_trade_case8(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id'])] lot, _ = user.post({}, @@ -1996,7 +1989,7 @@ def test_trade_case9(user: UserClient, user2: UserClient): lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), - query=devices) + query=devices[:-1]) # the manager shares the temporary lot with the SCRAP as an incoming lot # for the CRAP to confirm it @@ -2154,7 +2147,7 @@ def test_trade_case11(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) + snap2, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id']), ('id', snap2['device']['id']) @@ -2162,7 +2155,7 @@ def test_trade_case11(user: UserClient, user2: UserClient): lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), - query=devices[:-1]) + query=devices) # the manager shares the temporary lot with the SCRAP as an incoming lot # for the CRAP to confirm it @@ -2180,12 +2173,6 @@ def test_trade_case11(user: UserClient, user2: UserClient): user.post(res=models.Action, data=request_post) trade = models.Trade.query.one() - # import pdb; pdb.set_trace() - - lot, _ = user.post({}, - res=Lot, - item='{}/devices'.format(lot['id']), - query=devices[-1:]) device1, device = trade.devices @@ -2229,7 +2216,7 @@ def test_trade_case12(user: UserClient, user2: UserClient): lot, _ = user.post({'name': 'MyLot'}, res=Lot) # The manager add 7 device into the lot snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) - snap2, _ = user2.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) + snap2, _ = user.post(file('acer.happy.battery.snapshot'), res=models.Snapshot) devices = [('id', snap1['device']['id']), ('id', snap2['device']['id']) @@ -2237,7 +2224,7 @@ def test_trade_case12(user: UserClient, user2: UserClient): lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), - query=devices[:-1]) + query=devices) # the manager shares the temporary lot with the SCRAP as an incoming lot # for the CRAP to confirm it @@ -2257,11 +2244,6 @@ def test_trade_case12(user: UserClient, user2: UserClient): trade = models.Trade.query.one() # import pdb; pdb.set_trace() - lot, _ = user.post({}, - res=Lot, - item='{}/devices'.format(lot['id']), - query=devices[-1:]) - device1, device = trade.devices # Normal confirm