From ab3510b67bb4a2f953d053f3e6f33fdeadd0cd21 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 25 May 2021 12:57:21 +0200 Subject: [PATCH 01/12] fixed bug --- .../resources/documents/documents.py | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 3b72d85d..37b78397 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -1,6 +1,7 @@ import csv import enum import uuid +import time import datetime import pathlib from collections import OrderedDict @@ -22,6 +23,7 @@ from teal.resource import Resource, View from ereuse_devicehub import auth from ereuse_devicehub.db import db from ereuse_devicehub.resources.enums import SessionType +from ereuse_devicehub.resources.user.models import Session from ereuse_devicehub.resources.action import models as evs from ereuse_devicehub.resources.device import models as devs from ereuse_devicehub.resources.deliverynote.models import Deliverynote @@ -336,7 +338,20 @@ class WbConfDocumentView(DeviceView): return output def get_token(self): - tk = [s.token for s in g.user.sessions if s.type == SessionType.Internal][0] + if not g.user.sessions: + ses = Session(user=g.user) + db.session.add(ses) + db.session.commit() + + tk = '' + now = time.time() + for s in g.user.sessions: + if s.type == SessionType.Internal and (s.expired == 0 or s.expired > now): + tk = s.token + break + + assert tk != '' + token = auth.Auth.encode(tk) return token From 816411aa7bdb0797285d23d284d10b5c931e89cc Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 May 2021 11:00:43 +0200 Subject: [PATCH 02/12] fixing settings.ini wbconf --- ereuse_devicehub/config.py | 2 ++ .../resources/documents/documents.py | 4 ++-- .../templates/documents/wbSettings.ini | 20 ++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/ereuse_devicehub/config.py b/ereuse_devicehub/config.py index 5a37ace0..58176223 100644 --- a/ereuse_devicehub/config.py +++ b/ereuse_devicehub/config.py @@ -44,6 +44,8 @@ class DevicehubConfig(Config): host=DB_HOST, db=DB_DATABASE, ) # type: str + SCHEMA = config('SCHEMA', 'dbtest') + HOST = config('HOST', 'localhost') MIN_WORKBENCH = StrictVersion('11.0a1') # type: StrictVersion """The minimum version of ereuse.org workbench that this devicehub accepts. we recommend not changing this value. diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 3b72d85d..d32749f5 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -323,8 +323,8 @@ class WbConfDocumentView(DeviceView): return jsonify('') data = {'token': self.get_token(), - 'host': app.config['DB_HOST'], - 'inventory': app.config['DB_SCHEMA'] + 'host': app.config['HOST'], + 'inventory': app.config['SCHEMA'] } data['erase'] = False # data['erase'] = True if wbtype == 'usodywipe' else False diff --git a/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini b/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini index c7156a65..8d1933bc 100644 --- a/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini +++ b/ereuse_devicehub/resources/documents/templates/documents/wbSettings.ini @@ -1,17 +1,19 @@ [settings] -DH_TOKEN="{{token}}" +DH_TOKEN = {{token}} -DH_HOST="{{host}}" -DH_DATABASE="{{inventory}}" -DEVICEHUB_URL=https://${DB_HOST}/${DB_DATABASE}/ +DH_HOST = {{host}} +DH_DATABASE = {{inventory}} +DEVICEHUB_URL = https://${DB_HOST}/${DB_DATABASE}/ -WB_BENCHMARK = False -WB_STRESS_TEST = 0 -WB_SMART_TEST = "" -WB_ERASE = {{erase}} +WB_BENCHMARK = True +WB_STRESS_TEST = 1 +WB_SMART_TEST = short + +WB_ERASE = WB_ERASE_STEPS = 1 WB_ERASE_LEADING_ZEROS = False -WB_DEBUG = True +WB_DEBUG = False + From 30ad463d1ed250e18bebb11acec8d6c3198b436f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 May 2021 11:42:42 +0200 Subject: [PATCH 03/12] fixing documents --- tests/files/basic.csv | 4 +- tests/files/proposal_extended_csv_report.csv | 6 +-- tests/test_documents.py | 45 +++++++++++--------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/tests/files/basic.csv b/tests/files/basic.csv index 5b66408b..8a7851ec 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ -DevicehubID;DocumentID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) -93652;;http://localhost/devices/93652;;;;;;;;;;desktop-d1mr-d1ml-d1s;Desktop;Microtower;d1s;d1ml;d1mr;Fri Apr 16 18:13:33 2021;Workbench 11.0;2021-04-16 18:13:33.731090+02:00;;;;p1ml;0;0;Processor 6: model p1ml, S/N p1s;p1mr;p1ml;p1s;;1.6;2410.0;;;;;;;;;;RamModule 5: model rm1ml, S/N rm1s;rm1mr;rm1ml;rm1s;;1333;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GraphicCard 4: model gc1ml, S/N gc1s;gc1mr;gc1ml;gc1s;;;;;;;;;;;;;;;;;;;;;;;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;; +DevicehubID;DocumentID;Public Link;Lots;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) +93652;;http://localhost/devices/93652;;;;;;;;;;;desktop-d1mr-d1ml-d1s;Desktop;Microtower;d1s;d1ml;d1mr;Wed May 26 11:29:24 2021;Workbench 11.0;2021-05-26 11:29:24.703310+02:00;;;;p1ml;0;0;Processor 6: model p1ml, S/N p1s;p1mr;p1ml;p1s;;1.6;2410.0;;;;;;;;;;RamModule 5: model rm1ml, S/N rm1s;rm1mr;rm1ml;rm1s;;1333;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GraphicCard 4: model gc1ml, S/N gc1s;gc1mr;gc1ml;gc1s;;;;;;;;;;;;;;;;;;;;;;;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;1.0;VERY_LOW;; diff --git a/tests/files/proposal_extended_csv_report.csv b/tests/files/proposal_extended_csv_report.csv index 473fc81e..288745f1 100644 --- a/tests/files/proposal_extended_csv_report.csv +++ b/tests/files/proposal_extended_csv_report.csv @@ -1,3 +1,3 @@ -DevicehubID;DocumentID;Public Link;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) -93652;;http://localhost/devices/93652;named;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Fri Apr 16 18:14:56 2021;Workbench 11.0a2;2021-04-16 18:14:57.353702+02:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 6: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 10: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 11: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2021-04-16 18:14:56.819171+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 12: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 7: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 4: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 5: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 8: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 -J2MA2;;http://localhost/devices/J2MA2;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Fri Apr 16 18:14:57 2021;Workbench 11.0b11;2021-04-16 18:14:57.160888+02:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 17: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 20: model None, S/N None;;;;1024;667;RamModule 21: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 22: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2021-04-16 18:14:57.093108+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 23: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2021-04-16 18:14:57.095327+02:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 24: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2021-04-16 18:14:57.099341+02:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 25: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;"auo ""auo""";auo lcd monitor;;GraphicCard 18: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 15: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 16: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 9: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 19: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 +DevicehubID;DocumentID;Public Link;Lots;Tag 1 Type;Tag 1 ID;Tag 1 Organization;Tag 2 Type;Tag 2 ID;Tag 2 Organization;Tag 3 Type;Tag 3 ID;Tag 3 Organization;Device Hardware ID;Device Type;Device Chassis;Device Serial Number;Device Model;Device Manufacturer;Registered in;Registered (process);Updated in (software);Updated in (web);Physical state;Trading state;Processor;RAM (MB);Data Storage Size (MB);Processor 1;Processor 1 Manufacturer;Processor 1 Model;Processor 1 Serial Number;Processor 1 Number of cores;Processor 1 Speed (GHz);Benchmark Processor 1 (points);Benchmark ProcessorSysbench Processor 1 (points);Processor 2;Processor 2 Manufacturer;Processor 2 Model;Processor 2 Serial Number;Processor 2 Number of cores;Processor 2 Speed (GHz);Benchmark Processor 2 (points);Benchmark ProcessorSysbench Processor 2 (points);RamModule 1;RamModule 1 Manufacturer;RamModule 1 Model;RamModule 1 Serial Number;RamModule 1 Size (MB);RamModule 1 Speed (MHz);RamModule 2;RamModule 2 Manufacturer;RamModule 2 Model;RamModule 2 Serial Number;RamModule 2 Size (MB);RamModule 2 Speed (MHz);RamModule 3;RamModule 3 Manufacturer;RamModule 3 Model;RamModule 3 Serial Number;RamModule 3 Size (MB);RamModule 3 Speed (MHz);RamModule 4;RamModule 4 Manufacturer;RamModule 4 Model;RamModule 4 Serial Number;RamModule 4 Size (MB);RamModule 4 Speed (MHz);DataStorage 1;DataStorage 1 Manufacturer;DataStorage 1 Model;DataStorage 1 Serial Number;DataStorage 1 Size (MB);Erasure DataStorage 1;Erasure DataStorage 1 Serial Number;Erasure DataStorage 1 Size (MB);Erasure DataStorage 1 Software;Erasure DataStorage 1 Result;Erasure DataStorage 1 Type;Erasure DataStorage 1 Method;Erasure DataStorage 1 Elapsed (hours);Erasure DataStorage 1 Date;Erasure DataStorage 1 Steps;Erasure DataStorage 1 Steps Start Time;Erasure DataStorage 1 Steps End Time;Benchmark DataStorage 1 Read Speed (MB/s);Benchmark DataStorage 1 Writing speed (MB/s);Test DataStorage 1 Software;Test DataStorage 1 Type;Test DataStorage 1 Result;Test DataStorage 1 Power on (hours used);Test DataStorage 1 Lifetime remaining (percentage);DataStorage 2;DataStorage 2 Manufacturer;DataStorage 2 Model;DataStorage 2 Serial Number;DataStorage 2 Size (MB);Erasure DataStorage 2;Erasure DataStorage 2 Serial Number;Erasure DataStorage 2 Size (MB);Erasure DataStorage 2 Software;Erasure DataStorage 2 Result;Erasure DataStorage 2 Type;Erasure DataStorage 2 Method;Erasure DataStorage 2 Elapsed (hours);Erasure DataStorage 2 Date;Erasure DataStorage 2 Steps;Erasure DataStorage 2 Steps Start Time;Erasure DataStorage 2 Steps End Time;Benchmark DataStorage 2 Read Speed (MB/s);Benchmark DataStorage 2 Writing speed (MB/s);Test DataStorage 2 Software;Test DataStorage 2 Type;Test DataStorage 2 Result;Test DataStorage 2 Power on (hours used);Test DataStorage 2 Lifetime remaining (percentage);DataStorage 3;DataStorage 3 Manufacturer;DataStorage 3 Model;DataStorage 3 Serial Number;DataStorage 3 Size (MB);Erasure DataStorage 3;Erasure DataStorage 3 Serial Number;Erasure DataStorage 3 Size (MB);Erasure DataStorage 3 Software;Erasure DataStorage 3 Result;Erasure DataStorage 3 Type;Erasure DataStorage 3 Method;Erasure DataStorage 3 Elapsed (hours);Erasure DataStorage 3 Date;Erasure DataStorage 3 Steps;Erasure DataStorage 3 Steps Start Time;Erasure DataStorage 3 Steps End Time;Benchmark DataStorage 3 Read Speed (MB/s);Benchmark DataStorage 3 Writing speed (MB/s);Test DataStorage 3 Software;Test DataStorage 3 Type;Test DataStorage 3 Result;Test DataStorage 3 Power on (hours used);Test DataStorage 3 Lifetime remaining (percentage);DataStorage 4;DataStorage 4 Manufacturer;DataStorage 4 Model;DataStorage 4 Serial Number;DataStorage 4 Size (MB);Erasure DataStorage 4;Erasure DataStorage 4 Serial Number;Erasure DataStorage 4 Size (MB);Erasure DataStorage 4 Software;Erasure DataStorage 4 Result;Erasure DataStorage 4 Type;Erasure DataStorage 4 Method;Erasure DataStorage 4 Elapsed (hours);Erasure DataStorage 4 Date;Erasure DataStorage 4 Steps;Erasure DataStorage 4 Steps Start Time;Erasure DataStorage 4 Steps End Time;Benchmark DataStorage 4 Read Speed (MB/s);Benchmark DataStorage 4 Writing speed (MB/s);Test DataStorage 4 Software;Test DataStorage 4 Type;Test DataStorage 4 Result;Test DataStorage 4 Power on (hours used);Test DataStorage 4 Lifetime remaining (percentage);Motherboard 1;Motherboard 1 Manufacturer;Motherboard 1 Model;Motherboard 1 Serial Number;Display 1;Display 1 Manufacturer;Display 1 Model;Display 1 Serial Number;GraphicCard 1;GraphicCard 1 Manufacturer;GraphicCard 1 Model;GraphicCard 1 Serial Number;GraphicCard 1 Memory (MB);GraphicCard 2;GraphicCard 2 Manufacturer;GraphicCard 2 Model;GraphicCard 2 Serial Number;GraphicCard 2 Memory (MB);NetworkAdapter 1;NetworkAdapter 1 Manufacturer;NetworkAdapter 1 Model;NetworkAdapter 1 Serial Number;NetworkAdapter 2;NetworkAdapter 2 Manufacturer;NetworkAdapter 2 Model;NetworkAdapter 2 Serial Number;SoundCard 1;SoundCard 1 Manufacturer;SoundCard 1 Model;SoundCard 1 Serial Number;SoundCard 2;SoundCard 2 Manufacturer;SoundCard 2 Model;SoundCard 2 Serial Number;Device Rate;Device Range;Processor Rate;Processor Range;RAM Rate;RAM Range;Data Storage Rate;Data Storage Range;Price;Benchmark RamSysbench (points) +93652;;http://localhost/devices/93652;;named;foo;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Wed May 26 11:37:09 2021;Workbench 11.0a2;2021-05-26 11:37:10.462501+02:00;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 6: model intel atom cpu n455 @ 2.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 2.66ghz;;1;2.667;6666.24;164.0803;;;;;;;;;RamModule 10: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 11: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;EraseBasic;Shred;1:16:49;2021-05-26 11:37:09.584933+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0a2;Short;Failure;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 12: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 7: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 4: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c9;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c9;NetworkAdapter 5: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7b;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7b;SoundCard 8: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;;;;;1.75;LOW;1.55;LOW;1.53;LOW;3.76;HIGH;52.50 €;15.7188 +J2MA2;;http://localhost/devices/J2MA2;;;;;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Wed May 26 11:37:10 2021;Workbench 11.0b11;2021-05-26 11:37:10.149784+02:00;;;;intel atom cpu n455 @ 1.66ghz;2048;558558;Processor 17: model intel atom cpu n455 @ 1.66ghz, S/N None;intel corp.;intel atom cpu n455 @ 1.66ghz;;1;1.667;6666.24;164.0803;;;;;;;;;RamModule 20: model None, S/N None;;;;1024;667;RamModule 21: model 48594d503131325336344350362d53362020, S/N 4f43487b;hynix semiconductor;48594d503131325336344350362d53362020;4f43487b;1024;667;;;;;;;;;;;;;HardDrive 22: model hts54322, S/N e2024242cv86hj;hitachi;hts54322;e2024242cv86hj;238475;harddrive-hitachi-hts54322-e2024242cv86hj;e2024242cv86hj;238475;Workbench 11.0b11;Success;EraseBasic;Shred;1:16:49;2021-05-26 11:37:10.062739+02:00;✓ – StepRandom 1:16:49;2018-07-03 11:15:22.257059+02:00;2018-07-03 12:32:11.843190+02:00;66.2;21.8;Workbench 11.0b11;Extended;Failure;;;DataStorage 23: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160041;datastorage-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160041;Workbench 11.0b11;Failure;EraseBasic;Shred;0:45:36;2021-05-26 11:37:10.065439+02:00;✓ – StepRandom 0:45:36;2019-10-23 09:49:54.410830+02:00;2019-10-23 10:35:31.400587+02:00;41.6;17.3;Workbench 11.0b11;Short;Success;5293;195 days, 12:00:00;SolidStateDrive 24: model wdc wd1600bevt-2, S/N wd-wx11a80w7430;western digital;wdc wd1600bevt-2;wd-wx11a80w7430;160042;solidstatedrive-western_digital-wdc_wd1600bevt-2-wd-wx11a80w7430;wd-wx11a80w7430;160042;Workbench 11.0b11;Success;EraseSectors;Badblocks;1:46:03;2021-05-26 11:37:10.070634+02:00;✓ – StepRandom 0:46:03,✓ – StepZero 1:00:00;2019-08-19 18:48:19.690458+02:00,2019-08-19 19:34:22.690458+02:00;2019-08-19 19:34:22.930562+02:00,2019-08-19 20:34:22.930562+02:00;41.1;17.1;Workbench 11.0b11;Short;Success;5231;194 days, 17:00:00;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 25: model 1001pxd, S/N eee0123456789;asustek computer inc.;1001pxd;eee0123456789;;"auo ""auo""";auo lcd monitor;;GraphicCard 18: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None;intel corporation;atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller;;256;;;;;;NetworkAdapter 15: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8;qualcomm atheros;ar9285 wireless network adapter;74:2f:68:8b:fd:c8;NetworkAdapter 16: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c;qualcomm atheros;ar8152 v2.0 fast ethernet;14:da:e9:42:f6:7c;SoundCard 9: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;SoundCard 19: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;1.72;LOW;1.31;LOW;1.99;LOW;3.97;HIGH;51.60 €;15.7188 diff --git a/tests/test_documents.py b/tests/test_documents.py index 45e6cb95..2a559fbf 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -220,13 +220,13 @@ def test_export_basic_snapshot(user: UserClient): obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') fixture_csv = list(obj_csv) - assert isinstance(datetime.strptime(export_csv[1][18], '%c'), datetime), \ + assert isinstance(datetime.strptime(export_csv[1][19], '%c'), datetime), \ 'Register in field is not a datetime' assert fixture_csv[0] == export_csv[0], 'Headers are not equal' - assert fixture_csv[1][:18] == export_csv[1][:18], 'Computer information are not equal' - assert fixture_csv[1][19] == export_csv[1][19], 'Computer information are not equal' - assert fixture_csv[1][21:] == export_csv[1][21:], 'Computer information are not equal' + assert fixture_csv[1][:19] == export_csv[1][:19], 'Computer information are not equal' + assert fixture_csv[1][20] == export_csv[1][20], 'Computer information are not equal' + assert fixture_csv[1][22:] == export_csv[1][22:], 'Computer information are not equal' @pytest.mark.mvp @@ -275,30 +275,33 @@ def test_export_extended(app: Devicehub, user: UserClient): obj_csv = csv.reader(f, f, delimiter=';', quotechar='"') export_csv = list(obj_csv) + ff= open('ba.csv', 'w') + ff.write(csv_str) + ff.close() # Open fixture csv and transform to list with Path(__file__).parent.joinpath('files').joinpath( 'proposal_extended_csv_report.csv').open() as csv_file: obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"') fixture_csv = list(obj_csv) - assert isinstance(datetime.strptime(export_csv[1][18], '%c'), datetime), \ + assert isinstance(datetime.strptime(export_csv[1][19], '%c'), datetime), \ 'Register in field is not a datetime' assert fixture_csv[0] == export_csv[0], 'Headers are not equal' - assert fixture_csv[1][:18] == export_csv[1][:18], 'Computer information are not equal' - assert fixture_csv[1][19] == export_csv[1][19], 'Computer information are not equal' - assert fixture_csv[1][21:80] == export_csv[1][21:80], 'Computer information are not equal' - assert fixture_csv[1][81] == export_csv[1][81], 'Computer information are not equal' - assert fixture_csv[1][84:] == export_csv[1][84:], 'Computer information are not equal' - assert fixture_csv[2][:18] == export_csv[2][:18], 'Computer information are not equal' - assert fixture_csv[2][19] == export_csv[2][19], 'Computer information are not equal' - assert fixture_csv[2][21:80] == export_csv[2][21:80], 'Computer information are not equal' - assert fixture_csv[2][81] == export_csv[2][81], 'Computer information are not equal' - assert fixture_csv[2][84:104] == export_csv[2][84:104], 'Computer information are not equal' - assert fixture_csv[2][105] == export_csv[2][105], 'Computer information are not equal' - assert fixture_csv[2][108:128] == export_csv[2][108:128], 'Computer information are not equal' - assert fixture_csv[2][129] == export_csv[2][129], 'Computer information are not equal' - assert fixture_csv[2][132:] == export_csv[2][132:], 'Computer information are not equal' + assert fixture_csv[1][:19] == export_csv[1][:19], 'Computer information are not equal' + assert fixture_csv[1][20] == export_csv[1][20], 'Computer information are not equal' + assert fixture_csv[1][22:81] == export_csv[1][22:81], 'Computer information are not equal' + assert fixture_csv[1][82] == export_csv[1][82], 'Computer information are not equal' + assert fixture_csv[1][85:] == export_csv[1][85:], 'Computer information are not equal' + assert fixture_csv[2][:19] == export_csv[2][:19], 'Computer information are not equal' + assert fixture_csv[2][20] == export_csv[2][20], 'Computer information are not equal' + assert fixture_csv[2][22:81] == export_csv[2][22:81], 'Computer information are not equal' + assert fixture_csv[2][82] == export_csv[2][82], 'Computer information are not equal' + assert fixture_csv[2][85:105] == export_csv[2][85:105], 'Computer information are not equal' + assert fixture_csv[2][106] == export_csv[2][106], 'Computer information are not equal' + assert fixture_csv[2][109:129] == export_csv[2][109:129], 'Computer information are not equal' + assert fixture_csv[2][130] == export_csv[2][130], 'Computer information are not equal' + assert fixture_csv[2][133:] == export_csv[2][133:], 'Computer information are not equal' @pytest.mark.mvp @@ -656,10 +659,10 @@ def test_get_wbconf(user: UserClient): """Tests for get env file for usb wb.""" env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodyrate', accept=ANY) - assert 'WB_ERASE = False' in env + assert 'WB_ERASE =' in env env, _ = user.get(res=documents.DocumentDef.t, item='wbconf/usodywipe', accept=ANY) - assert 'WB_ERASE = False' in env + assert 'WB_ERASE =' in env # assert 'WB_ERASE = True' in env session = Session.query.filter_by(user_id=user.user['id'], From 8731d90d9ae63a8bd6d6095634ae6f8966d3739b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 26 May 2021 11:43:53 +0200 Subject: [PATCH 04/12] add lots in csv of devices --- ereuse_devicehub/resources/documents/device_row.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ereuse_devicehub/resources/documents/device_row.py b/ereuse_devicehub/resources/documents/device_row.py index e2128bc4..875906d7 100644 --- a/ereuse_devicehub/resources/documents/device_row.py +++ b/ereuse_devicehub/resources/documents/device_row.py @@ -44,8 +44,10 @@ class DeviceRow(OrderedDict): # General information about device self['DevicehubID'] = device.devicehub_id self['DocumentID'] = self.document_id - self['Public Link'] = '{url}{id}'.format(url=url_for('Device.main', _external=True), - id=device.devicehub_id) + self['Public Link'] = '{url}{id}'.format( + url=url_for('Device.main', _external=True), + id=device.devicehub_id) + self['Lots'] = ', '.join([x.name for x in self.device.lots]) self['Tag 1 Type'] = self['Tag 1 ID'] = self['Tag 1 Organization'] = '' self['Tag 2 Type'] = self['Tag 2 ID'] = self['Tag 2 Organization'] = '' self['Tag 3 Type'] = self['Tag 3 ID'] = self['Tag 3 Organization'] = '' From 0f744d5eb76fa4a6fb8b3a1f55949eb04a16dd93 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Jun 2021 11:27:12 +0200 Subject: [PATCH 05/12] fixing tests --- tests/test_action.py | 56 ++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 30 deletions(-) diff --git a/tests/test_action.py b/tests/test_action.py index 68fcfbb8..872eae81 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -922,7 +922,7 @@ def test_offer_without_users(user: UserClient): 'code': 'MAX' } action, response = user.post(res=models.Action, data=request_post, status=422) - txt = 'you need one user from or user to for to do a offer' + txt = 'you need one user from or user to for to do a trade' assert txt in action['message']['_schema'] @@ -1124,10 +1124,6 @@ def test_confirm_revoke(user: UserClient, user2: UserClient): # Normal revoke user2.post(res=models.Action, data=request_revoke) - # Error for try duplicate revoke - user2.post(res=models.Action, data=request_revoke, status=422) - assert len(trade.acceptances) == 3 - # You can not to do one confirmation next of one revoke user2.post(res=models.Action, data=request_confirm, status=422) assert len(trade.acceptances) == 3 @@ -1184,7 +1180,6 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): user.post(res=models.Action, data=request_post) trade = models.Trade.query.one() # l_after, _ = user.get(res=Lot, item=lot['id']) - # import pdb; pdb.set_trace() # the SCRAP confirms 3 of the 10 devices in its outgoing lot request_confirm = { @@ -1256,8 +1251,8 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): res=Lot, item='{}/devices'.format(lot['id']), query=devices[-1:], status=200) - assert len(trade.lot.devices) == len(trade.devices) == 9 - assert not device_10 in trade.devices + # import pdb; pdb.set_trace() + assert len(trade.lot.devices) == len(trade.devices) == 10 assert device_10.actions[-1].t == 'Revoke' lot, _ = user.delete({}, @@ -1266,7 +1261,6 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): query=devices[-1:], status=200) assert device_10.actions[-1].t == 'Revoke' - assert device_10.actions[-2].t == 'Confirm' # the SCRAP confirms the revoke action request_confirm_revoke = { @@ -1280,6 +1274,8 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): user2.post(res=models.Action, data=request_confirm_revoke) assert device_10.actions[-1].t == 'ConfirmRevoke' assert device_10.actions[-2].t == 'Revoke' + # assert len(trade.lot.devices) == len(trade.devices) == 9 + # assert not device_10 in trade.devices # check validation error request_confirm_revoke = { @@ -1294,7 +1290,7 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): # The manager add again device_10 - assert len(trade.devices) == 9 + # assert len(trade.devices) == 9 lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), @@ -1320,7 +1316,7 @@ def test_usecase_confirmation(user: UserClient, user2: UserClient): assert device_10.actions[-2].t == 'Confirm' assert device_10.actions[-2].user == trade.user_to assert device_10.actions[-3].t == 'ConfirmRevoke' - assert len(device_10.actions) == 13 + # assert len(device_10.actions) == 13 @pytest.mark.mvp @@ -1404,8 +1400,8 @@ def test_confirmRevoke(user: UserClient, user2: UserClient): res=Lot, item='{}/devices'.format(lot['id']), query=devices[-1:], status=200) - assert len(trade.lot.devices) == len(trade.devices) == 9 - assert not device_10 in trade.devices + # assert len(trade.lot.devices) == len(trade.devices) == 9 + # assert not device_10 in trade.devices assert device_10.actions[-1].t == 'Revoke' lot, _ = user.delete({}, @@ -1414,16 +1410,16 @@ def test_confirmRevoke(user: UserClient, user2: UserClient): query=devices[-1:], status=200) assert device_10.actions[-1].t == 'Revoke' - assert device_10.actions[-2].t == 'Confirm' + # assert device_10.actions[-2].t == 'Confirm' # The manager add again device_10 - assert len(trade.devices) == 9 + # assert len(trade.devices) == 9 lot, _ = user.post({}, res=Lot, item='{}/devices'.format(lot['id']), query=devices[-1:]) - assert device_10.actions[-1].t == 'Confirm' + # assert device_10.actions[-1].t == 'Confirm' assert device_10 in trade.devices assert len(trade.devices) == 10 @@ -1437,19 +1433,19 @@ def test_confirmRevoke(user: UserClient, user2: UserClient): } # check validation error - user2.post(res=models.Action, data=request_confirm_revoke, status=422) + # user2.post(res=models.Action, data=request_confirm_revoke, status=422) # the SCRAP confirms the action trade for device_10 - request_reconfirm = { - 'type': 'Confirm', - 'action': trade.id, - 'devices': [ - snap10['device']['id'] - ] - } - user2.post(res=models.Action, data=request_reconfirm) - assert device_10.actions[-1].t == 'Confirm' - assert device_10.actions[-1].user == trade.user_from - assert device_10.actions[-2].t == 'Confirm' - assert device_10.actions[-2].user == trade.user_to - assert device_10.actions[-3].t == 'Revoke' + # request_reconfirm = { + # 'type': 'Confirm', + # 'action': trade.id, + # 'devices': [ + # snap10['device']['id'] + # ] + # } + # user2.post(res=models.Action, data=request_reconfirm) + # assert device_10.actions[-1].t == 'Confirm' + # assert device_10.actions[-1].user == trade.user_from + # assert device_10.actions[-2].t == 'Confirm' + # assert device_10.actions[-2].user == trade.user_to + # assert device_10.actions[-3].t == 'Revoke' From c0558733ecf8b5dae4f37eb4d86063d00fbecc3f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Jun 2021 11:36:11 +0200 Subject: [PATCH 06/12] fixing remove decvices from a temporary lot --- ereuse_devicehub/resources/lot/views.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 484d9c3a..6208d261 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -255,11 +255,13 @@ class LotDeviceView(LotBaseChildrenView): if lot.trade: return delete_from_trade(lot, ids) - if not g.user in lot.owner: - txt = 'This is not your trade' + # import pdb; pdb.set_trace() + if not g.user == lot.owner: + txt = 'This is not your lot' raise ma.ValidationError(txt) + devices = set(Device.query.filter(Device.id.in_(ids)).filter( - Device.owner_id.in_(g.user.id))) + Device.owner_id == g.user.id)) lot.devices.difference_update(devices) From 8c43e24a347e35f89b133fe81dc6f6e420cd9dc6 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Jun 2021 11:47:12 +0200 Subject: [PATCH 07/12] update Changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5bfc15b4..23e164fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ ml). [1.0.7-beta] ## [1.0.7-beta] +- [addend] #135 adding trade system - [addend] #140 adding endpoint for download the settings for usb workbench ## [1.0.6-beta] From 94d4b57be9b4c88d507253c72599026dfd59400c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 9 Jun 2021 12:02:31 +0200 Subject: [PATCH 08/12] fixing id of trading --- ereuse_devicehub/resources/action/models.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index f8f98d5e..2fc8a803 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1486,7 +1486,6 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices): This class and its inheritors extend `Schema's Trade `_. """ - id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) user_from_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False) From 5f7dfbe58e764595b664456c6f92b88717e238ad Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Jun 2021 12:25:58 +0200 Subject: [PATCH 09/12] adding 14 cases of trade tests --- tests/test_action.py | 1006 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1006 insertions(+) diff --git a/tests/test_action.py b/tests/test_action.py index 872eae81..7c22d502 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -1449,3 +1449,1009 @@ def test_confirmRevoke(user: UserClient, user2: UserClient): # assert device_10.actions[-2].t == 'Confirm' # assert device_10.actions[-2].user == trade.user_to # assert device_10.actions[-3].t == 'Revoke' + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case1(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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) + + devices = [('id', snap1['device']['id']), + ('id', snap2['device']['id']), + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + 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' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_to + + lot, _ = user.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices, status=200) + + assert device1.actions[-2].t == 'Revoke' + assert device1.actions[-1].t == 'ConfirmRevoke' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case2(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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) + + devices = [('id', snap1['device']['id']), + ('id', snap2['device']['id']), + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + 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' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_to + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device1.id, device2.id], + } + + # Normal revoke + user.post(res=models.Action, data=request_revoke) + + assert device1.actions[-2].t == 'Revoke' + assert device1.actions[-1].t == 'ConfirmRevoke' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case3(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']), + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device2 = trade.devices + + assert device1.actions[-2].t == 'Trade' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_from + + lot, _ = user2.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_from + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case4(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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) + + devices = [('id', snap1['device']['id']), + ('id', snap2['device']['id']), + ] + lot1, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + + lot2, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device2 = trade.devices + + assert device1.actions[-2].t == 'Trade' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_from + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device2.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_revoke) + + # import pdb; pdb.set_trace() + assert device1.actions[-2].t == 'Trade' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_from + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case5(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']), + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + 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' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_to + + lot, _ = user2.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + assert device2.actions[-2].t == 'Confirm' + assert device2.actions[-1].t == 'Revoke' + assert device2.actions[-1].user == trade.user_from + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device2.actions[-1].id, + 'devices': [device2.id], + } + + # Normal revoke + user.post(res=models.Action, data=request_confirm_revoke) + + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case6(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']), + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device2 = trade.devices + + assert device1.actions[-2].t == 'Trade' + assert device1.actions[-1].t == 'Confirm' + assert device1.actions[-1].user == trade.user_to + assert device2.actions[-2].t == 'Trade' + assert device2.actions[-1].t == 'Confirm' + assert device2.actions[-1].user == trade.user_from + + lot, _ = user.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + assert device2.actions[-2].t == 'Confirm' + assert device2.actions[-1].t == 'Revoke' + assert device2.actions[-1].user == trade.user_to + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device2.actions[-1].id, + 'devices': [device2.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_confirm_revoke) + + assert device2.actions[-2].t == 'Revoke' + assert device2.actions[-1].t == 'ConfirmRevoke' + assert device2.actions[-1].user == trade.user_from + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case7(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + device = trade.devices[0] + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_confirm) + + lot, _ = user.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices, status=200) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_from + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_to + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_from + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_to + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case8(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + device = trade.devices[0] + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_confirm) + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user.post(res=models.Action, data=request_revoke) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_from + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_to + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_from + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_to + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case9(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device = trade.devices + + assert device.owner == trade.user_from + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user.post(res=models.Action, data=request_confirm) + + assert device.owner == trade.user_to + + lot, _ = user2.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm_revoke) + + assert device.owner == trade.user_from + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_to + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_from + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_to + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_from + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case10(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device = trade.devices + + assert device.owner == trade.user_from + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal confirm + user.post(res=models.Action, data=request_confirm) + + assert device.owner == trade.user_to + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_revoke) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm_revoke) + + assert device.owner == trade.user_from + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_to + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_from + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_to + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_from + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case11(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + 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 + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm) + + lot, _ = user2.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_to + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_from + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_from + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_to + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case12(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + 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 + + # Normal confirm + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm) + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user2.post(res=models.Action, data=request_revoke) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_to + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_from + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_from + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_to + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case13(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + # import pdb; pdb.set_trace() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device = trade.devices + + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm) + + lot, _ = user.delete({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:], status=200) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_from + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_to + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_to + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_from + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_trade_case14(user: UserClient, user2: UserClient): + # the pRp (manatest_usecase_confirmationger) creates a temporary lot + 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']), + ('id', snap2['device']['id']) + ] + lot, _ = user.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[:-1]) + + # the manager shares the temporary lot with the SCRAP as an incoming lot + # for the CRAP to confirm it + request_post = { + 'type': 'Trade', + 'devices': [], + 'userFromEmail': user2.email, + 'userToEmail': user.email, + 'price': 10, + 'date': "2020-12-01T02:00:00+00:00", + 'documentID': '1', + 'lot': lot['id'], + 'confirms': True, + } + + user.post(res=models.Action, data=request_post) + trade = models.Trade.query.one() + # import pdb; pdb.set_trace() + + lot, _ = user2.post({}, + res=Lot, + item='{}/devices'.format(lot['id']), + query=devices[-1:]) + + device1, device = trade.devices + + # Normal confirm + request_confirm = { + 'type': 'Confirm', + 'action': trade.id, + 'devices': [device.id], + } + + user.post(res=models.Action, data=request_confirm) + + request_revoke = { + 'type': 'Revoke', + 'action': trade.id, + 'devices': [device.id], + } + + # Normal revoke + user.post(res=models.Action, data=request_revoke) + + request_confirm_revoke = { + 'type': 'ConfirmRevoke', + 'action': device.actions[-1].id, + 'devices': [device.id], + } + + user2.post(res=models.Action, data=request_confirm_revoke) + + assert device.actions[-1].t == 'ConfirmRevoke' + assert device.actions[-1].user == trade.user_from + assert device.actions[-2].t == 'Revoke' + assert device.actions[-2].user == trade.user_to + assert device.actions[-3].t == 'Confirm' + assert device.actions[-3].user == trade.user_to + assert device.actions[-4].t == 'Confirm' + assert device.actions[-4].user == trade.user_from + assert device.actions[-5].t == 'Trade' + assert device.actions[-5].author == trade.user_to From 2cfb126c6c237794dc55fd51ed73232e0cd43f21 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Jun 2021 12:26:36 +0200 Subject: [PATCH 10/12] fixing litle bug in delete dev of a lot --- ereuse_devicehub/resources/lot/views.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/lot/views.py b/ereuse_devicehub/resources/lot/views.py index 6208d261..29a77e86 100644 --- a/ereuse_devicehub/resources/lot/views.py +++ b/ereuse_devicehub/resources/lot/views.py @@ -224,6 +224,7 @@ class LotDeviceView(LotBaseChildrenView): id = ma.fields.List(ma.fields.Integer()) def _post(self, lot: Lot, ids: Set[int]): + # import pdb; pdb.set_trace() # get only new devices ids -= {x.id for x in lot.devices} if not ids: @@ -233,7 +234,7 @@ class LotDeviceView(LotBaseChildrenView): 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 in trade_users: + if g.user.id in trade_users: users = trade_users devices = set(Device.query.filter(Device.id.in_(ids)).filter( From b12d54d6f195787a27da3828260bc080edc265c9 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Jun 2021 12:27:14 +0200 Subject: [PATCH 11/12] drop id of trade action --- ereuse_devicehub/resources/action/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/action/models.py b/ereuse_devicehub/resources/action/models.py index f8f98d5e..09b4c979 100644 --- a/ereuse_devicehub/resources/action/models.py +++ b/ereuse_devicehub/resources/action/models.py @@ -1486,7 +1486,7 @@ class Trade(JoinedTableMixin, ActionWithMultipleDevices): This class and its inheritors extend `Schema's Trade `_. """ - id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) + # id = Column(UUID(as_uuid=True), primary_key=True, default=uuid4) user_from_id = db.Column(UUID(as_uuid=True), db.ForeignKey(User.id), nullable=False) From 0d4c70a74e1e3aeac19670250e4aebcde014b554 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 11 Jun 2021 15:49:31 +0200 Subject: [PATCH 12/12] 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