From 17f8aebb94d75e36177c0c9441108722d7bbace6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 14 Oct 2021 18:13:20 +0200 Subject: [PATCH] fixing rows --- ereuse_devicehub/resources/device/metrics.py | 14 +++++++++----- .../resources/documents/device_row.py | 17 ++++++++++++++--- tests/test_metrics.py | 7 ++++++- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/resources/device/metrics.py b/ereuse_devicehub/resources/device/metrics.py index c8646775..68a790b4 100644 --- a/ereuse_devicehub/resources/device/metrics.py +++ b/ereuse_devicehub/resources/device/metrics.py @@ -25,11 +25,15 @@ class Metrics: """ return {'type': '', 'action_type': 'Status', + 'document_name': '', 'status_receiver': self.status_receiver, 'status_supplier': self.status_supplier, + 'status_receiver_created': '', + 'status_supplier_created': '', 'trade_supplier': '', - 'trade_receiver': self.act.author, + 'trade_receiver': self.act.author.email, 'trade_confirmed': '', + 'trade_weight': 0, 'action_create_by': self.action_create_by, 'devicehubID': self.devicehub_id, 'hid': self.hid, @@ -54,6 +58,7 @@ class Metrics: self.last_trade['status_supplier_created'] = self.act.created return + self.action_create_by = 'Receiver' if self.last_trade: # if exist one trade action before self.last_trade['status_receiver'] = self.act.type @@ -61,9 +66,8 @@ class Metrics: return # If not exist any trade action for this device - self.action_create_by = 'Receiver' row = self.get_template_row() - row['type'] = 'Status' + row['status_receiver_created'] = self.act.created self.rows.append(row) def get_snapshot(self): @@ -134,8 +138,8 @@ class Metrics: self.last_trade = row row['type'] = 'Trade' row['action_type'] = 'Trade' - row['trade_supplier'] = self.act.user_from - row['trade_receiver'] = self.act.user_to + row['trade_supplier'] = self.act.user_from.email + row['trade_receiver'] = self.act.user_to.email row['self.status_receiver'] = self.status_receiver row['self.status_supplier'] = self.status_supplier row['trade_confirmed'] = self.get_confirms() diff --git a/ereuse_devicehub/resources/documents/device_row.py b/ereuse_devicehub/resources/documents/device_row.py index 4e683ef9..36c93819 100644 --- a/ereuse_devicehub/resources/documents/device_row.py +++ b/ereuse_devicehub/resources/documents/device_row.py @@ -427,9 +427,20 @@ class ActionRow(OrderedDict): # General information about allocates, deallocate and lives self['DHID'] = allocate['devicehubID'] self['Hid'] = allocate['hid'] - self['Start'] = allocate['start'] - self['FinalUserCode'] = allocate['finalUserCode'] - self['NumEndUsers'] = allocate['numEndUsers'] + self['Document-Name'] = allocate['document_name'] + self['Action-Type'] = allocate['action_type'] + self['Action-User-LastOwner-Supplier'] = allocate['trade_supplier'] + self['Action-User-LastOwner-Receiver'] = allocate['trade_receiver'] + self['Action-Create-By'] = allocate['action_create_by'] + self['Trade-Confirmed'] = allocate['trade_confirmed'] + self['Status-Supplier'] = allocate['status_supplier'] + self['Status-Receiver'] = allocate['status_receiver'] + self['Status Supplier – Created Date'] = allocate['status_supplier_created'] + self['Status Receiver – Created Date'] = allocate['status_receiver_created'] + self['Trade-Weight'] = allocate['trade_weight'] + self['Allocate-Start'] = allocate['start'] + self['Allocate-User-Code'] = allocate['finalUserCode'] + self['Allocate-NumUsers'] = allocate['numEndUsers'] self['UsageTimeAllocate'] = allocate['usageTimeAllocate'] self['Type'] = allocate['type'] self['LiveCreate'] = allocate['liveCreate'] diff --git a/tests/test_metrics.py b/tests/test_metrics.py index aca7808c..46c2a20c 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -136,7 +136,11 @@ def test_metrics_action_status(user: UserClient, user2: UserClient): item='actions/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) - import pdb; pdb.set_trace() + # import pdb; pdb.set_trace() + head = 'DHID;Hid;Document-Name;Action-Type;Action-User-LastOwner-Supplier;Action-User-LastOwner-Receiver;Action-Create-By;Trade-Confirmed;Status-Supplier;Status-Receiver;Status Supplier – Created Date;Status Receiver – Created Date;Trade-Weight;Allocate-Start;Allocate-User-Code;Allocate-NumUsers;UsageTimeAllocate;Type;LiveCreate;UsageTimeHdd\n' + body = '93652;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Status;;foo@foo.com;Receiver;;;Use;;' + assert head in csv_str + assert body in csv_str @pytest.mark.mvp @@ -156,6 +160,7 @@ def test_complet_metrics(user: UserClient, user2: UserClient): res=Lot, item='{}/devices'.format(lot['id']), query=devices) + import pdb; pdb.set_trace() # request_post = { # 'type': 'Trade', # 'devices': [span1['device']['id'], snap2['device']['id']],