From 118825ed772d5a0567e9626f7c69567e59b24161 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Oct 2021 10:43:28 +0200 Subject: [PATCH 1/3] testing bug confirmed in metrics --- tests/test_metrics.py | 48 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index 6b403c4a..aeffa538 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -297,3 +297,51 @@ def test_visual_metrics_for_old_owners(user: UserClient, user2: UserClient): assert body in csv_receiver assert body in csv_supplier + assert csv_receiver == csv_supplier + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_bug_trade_confirmed(user: UserClient, user2: UserClient): + """When the receiber do a Trade, then the confirmation is wrong.""" + # Insert computer + lenovo = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot') + snap1, _ = user.post(json_encode(lenovo), res=ma.Snapshot) + lot, _ = user.post({'name': 'MyLot'}, res=Lot) + devices = [('id', snap1['device']['id'])] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices) + request_post = { + 'type': 'Trade', + 'devices': [snap1['device']['id']], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'lot': lot['id'], + 'confirms': True, + } + trade, _ = user.post(res=ma.Action, data=request_post) + + csv_not_confirmed, _ = user.get(res=documents.DocumentDef.t, + item='actions/', + accept='text/csv', + query=[('filter', {'type': ['Computer']})]) + request_confirm = { + 'type': 'Confirm', + 'action': trade['id'], + 'devices': [snap1['device']['id']] + } + user2.post(res=ma.Action, data=request_confirm) + csv_confirmed, _ = user2.get(res=documents.DocumentDef.t, + item='actions/', + accept='text/csv', + query=[('filter', {'type': ['Computer']})]) + + body_not_confirmed = "Trade;foo2@foo.com;foo@foo.com;Receiver;False;" + body_confirmed = "Trade;foo2@foo.com;foo@foo.com;Receiver;True;" + + assert body_not_confirmed in csv_not_confirmed + assert body_confirmed in csv_confirmed From 15fa4546d118907f1b6cdff731c981f4c1677697 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Oct 2021 12:20:16 +0200 Subject: [PATCH 2/3] fixing general case for devices --- ereuse_devicehub/resources/device/metrics.py | 6 ++---- tests/test_metrics.py | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/device/metrics.py b/ereuse_devicehub/resources/device/metrics.py index eaa72f04..898fc5d8 100644 --- a/ereuse_devicehub/resources/device/metrics.py +++ b/ereuse_devicehub/resources/device/metrics.py @@ -137,10 +137,8 @@ class Metrics(MetricsMix): if the action is one trade action, is possible than have a list of confirmations. Get the doble confirm for to know if this trade is confirmed or not. """ - if hasattr(self.act, 'acceptances'): - accept = self.act.acceptances[-1] - if accept.t == 'Confirm' and accept.user == self.act.user_to: - return True + if self.device.trading == 'TradeConfirmed': + return True return False def get_trade(self): diff --git a/tests/test_metrics.py b/tests/test_metrics.py index aeffa538..efdb26e4 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -304,7 +304,6 @@ def test_visual_metrics_for_old_owners(user: UserClient, user2: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_bug_trade_confirmed(user: UserClient, user2: UserClient): """When the receiber do a Trade, then the confirmation is wrong.""" - # Insert computer lenovo = yaml2json('desktop-9644w8n-lenovo-0169622.snapshot') snap1, _ = user.post(json_encode(lenovo), res=ma.Snapshot) lot, _ = user.post({'name': 'MyLot'}, res=Lot) From 5cce2f4efb90dd8b0e23d7ca9cde6c9932f04f4e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 25 Oct 2021 13:24:22 +0200 Subject: [PATCH 3/3] change some sintaxis --- ereuse_devicehub/resources/action/views/trade.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/views/trade.py b/ereuse_devicehub/resources/action/views/trade.py index af44cedb..16f2572b 100644 --- a/ereuse_devicehub/resources/action/views/trade.py +++ b/ereuse_devicehub/resources/action/views/trade.py @@ -66,7 +66,7 @@ class TradeView(): # check than the user than want to do the action is one of the users # involved in the action - if not g.user in [self.trade.user_from, self.trade.user_to]: + if g.user not in [self.trade.user_from, self.trade.user_to]: txt = "You do not participate in this trading" raise ValidationError(txt)