Merge pull request #151 from eReuse/feature/endpoint-confirm

fixing bug
This commit is contained in:
cayop 2021-06-11 15:51:59 +02:00 committed by GitHub
commit f59d697099
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 34 deletions

View File

@ -230,15 +230,8 @@ class LotDeviceView(LotBaseChildrenView):
if not ids: if not ids:
return 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( devices = set(Device.query.filter(Device.id.in_(ids)).filter(
Device.owner_id.in_(users))) Device.owner==g.user))
lot.devices.update(devices) lot.devices.update(devices)

View File

@ -1642,7 +1642,7 @@ def test_trade_case4(user: UserClient, user2: UserClient):
lot, _ = user.post({'name': 'MyLot'}, res=Lot) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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']), devices = [('id', snap1['device']['id']),
('id', snap2['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) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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']), devices = [('id', snap1['device']['id']),
('id', snap2['device']['id']), ('id', snap2['device']['id']),
@ -1716,7 +1716,7 @@ def test_trade_case5(user: UserClient, user2: UserClient):
lot, _ = user.post({}, lot, _ = user.post({},
res=Lot, res=Lot,
item='{}/devices'.format(lot['id']), item='{}/devices'.format(lot['id']),
query=devices[:-1]) query=devices)
# the manager shares the temporary lot with the SCRAP as an incoming lot # the manager shares the temporary lot with the SCRAP as an incoming lot
# for the CRAP to confirm it # 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) user.post(res=models.Action, data=request_post)
trade = models.Trade.query.one() trade = models.Trade.query.one()
lot, _ = user.post({},
res=Lot,
item='{}/devices'.format(lot['id']),
query=devices[-1:])
device1, device2 = trade.devices device1, device2 = trade.devices
assert device1.actions[-2].t == 'Trade' 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) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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'])] devices = [('id', snap1['device']['id'])]
lot, _ = user.post({}, lot, _ = user.post({},
@ -1917,7 +1911,6 @@ def test_trade_case8(user: UserClient, user2: UserClient):
lot, _ = user.post({'name': 'MyLot'}, res=Lot) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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'])] devices = [('id', snap1['device']['id'])]
lot, _ = user.post({}, lot, _ = user.post({},
@ -1996,7 +1989,7 @@ def test_trade_case9(user: UserClient, user2: UserClient):
lot, _ = user.post({}, lot, _ = user.post({},
res=Lot, res=Lot,
item='{}/devices'.format(lot['id']), item='{}/devices'.format(lot['id']),
query=devices) query=devices[:-1])
# the manager shares the temporary lot with the SCRAP as an incoming lot # the manager shares the temporary lot with the SCRAP as an incoming lot
# for the CRAP to confirm it # 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) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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']), devices = [('id', snap1['device']['id']),
('id', snap2['device']['id']) ('id', snap2['device']['id'])
@ -2162,7 +2155,7 @@ def test_trade_case11(user: UserClient, user2: UserClient):
lot, _ = user.post({}, lot, _ = user.post({},
res=Lot, res=Lot,
item='{}/devices'.format(lot['id']), item='{}/devices'.format(lot['id']),
query=devices[:-1]) query=devices)
# the manager shares the temporary lot with the SCRAP as an incoming lot # the manager shares the temporary lot with the SCRAP as an incoming lot
# for the CRAP to confirm it # 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) user.post(res=models.Action, data=request_post)
trade = models.Trade.query.one() 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 device1, device = trade.devices
@ -2229,7 +2216,7 @@ def test_trade_case12(user: UserClient, user2: UserClient):
lot, _ = user.post({'name': 'MyLot'}, res=Lot) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
# The manager add 7 device into the lot # The manager add 7 device into the lot
snap1, _ = user.post(file('basic.snapshot'), res=models.Snapshot) 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']), devices = [('id', snap1['device']['id']),
('id', snap2['device']['id']) ('id', snap2['device']['id'])
@ -2237,7 +2224,7 @@ def test_trade_case12(user: UserClient, user2: UserClient):
lot, _ = user.post({}, lot, _ = user.post({},
res=Lot, res=Lot,
item='{}/devices'.format(lot['id']), item='{}/devices'.format(lot['id']),
query=devices[:-1]) query=devices)
# the manager shares the temporary lot with the SCRAP as an incoming lot # the manager shares the temporary lot with the SCRAP as an incoming lot
# for the CRAP to confirm it # for the CRAP to confirm it
@ -2257,11 +2244,6 @@ def test_trade_case12(user: UserClient, user2: UserClient):
trade = models.Trade.query.one() trade = models.Trade.query.one()
# import pdb; pdb.set_trace() # import pdb; pdb.set_trace()
lot, _ = user.post({},
res=Lot,
item='{}/devices'.format(lot['id']),
query=devices[-1:])
device1, device = trade.devices device1, device = trade.devices
# Normal confirm # Normal confirm