From 2ade5a14d4ded3e7ae127743f15397f7d87071c0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 14:19:42 +0200 Subject: [PATCH 1/9] adding tag when there are a new device --- ereuse_devicehub/resources/device/models.py | 60 +++++++++++---------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 2322326a..38552e9a 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -9,9 +9,7 @@ from typing import Dict, List, Set from boltons import urlutils from citext import CIText -from flask_sqlalchemy import event from ereuse_utils.naming import HID_CONVERSION_DOC, Naming -from flask import g from more_itertools import unique_everseen from sqlalchemy import BigInteger, Boolean, Column, Enum as DBEnum, Float, ForeignKey, Integer, \ Sequence, SmallInteger, Unicode, inspect, text @@ -41,7 +39,12 @@ def create_code(context): _id = Device.query.order_by(Device.id.desc()).first() or 1 if not _id == 1: _id = _id.id + 1 - return hashcode.encode(_id) + code = hashcode.encode(_id) + + from ereuse_devicehub.resources.tag.model import Tag + tag = Tag(device_id=_id, id=code) + db.session.add(tag) + return code class Device(Thing): @@ -231,7 +234,7 @@ class Device(Thing): :return a list of actions: """ hide_actions = ['Price', 'EreusePrice'] - actions = [ac for ac in self.actions if not ac.t in hide_actions] + actions = [ac for ac in self.actions if ac.t not in hide_actions] actions.reverse() return actions @@ -288,7 +291,7 @@ class Device(Thing): status_actions = [ac.t for ac in states.Status.actions()] history = [] for ac in self.actions: - if not ac.t in status_actions: + if ac.t not in status_actions: continue if not history: history.append(ac) @@ -318,27 +321,27 @@ class Device(Thing): # return the correct status of trade depending of the user - ##### CASES ##### - ## User1 == owner of trade (This user have automatic Confirmation) - ## ======================= - ## if the last action is => only allow to do - ## ========================================== - ## Confirmation not User1 => Revoke - ## Confirmation User1 => Revoke - ## Revoke not User1 => ConfirmRevoke - ## Revoke User1 => RevokePending - ## RevokeConfirmation => RevokeConfirmed - ## - ## - ## User2 == Not owner of trade - ## ======================= - ## if the last action is => only allow to do - ## ========================================== - ## Confirmation not User2 => Confirm - ## Confirmation User2 => Revoke - ## Revoke not User2 => ConfirmRevoke - ## Revoke User2 => RevokePending - ## RevokeConfirmation => RevokeConfirmed + # #### CASES ##### + # User1 == owner of trade (This user have automatic Confirmation) + # ======================= + # if the last action is => only allow to do + # ========================================== + # Confirmation not User1 => Revoke + # Confirmation User1 => Revoke + # Revoke not User1 => ConfirmRevoke + # Revoke User1 => RevokePending + # RevokeConfirmation => RevokeConfirmed + # + # + # User2 == Not owner of trade + # ======================= + # if the last action is => only allow to do + # ========================================== + # Confirmation not User2 => Confirm + # Confirmation User2 => Revoke + # Revoke not User2 => ConfirmRevoke + # Revoke User2 => RevokePending + # RevokeConfirmation => RevokeConfirmed ac = self.last_action_trading if not ac: @@ -427,8 +430,8 @@ class Device(Thing): # TODO @cayop uncomment this lines for link the possessor with the device # from ereuse_devicehub.resources.action.models import Receive # with suppress(LookupError): - # action = self.last_action_of(Receive) - # return action.agent_to + # action = self.last_action_of(Receive) + # return action.agent_to @property def working(self): @@ -1166,4 +1169,3 @@ class Manufacturer(db.Model): listener_reset_field_updated_in_actual_time(Device) - From 6091f31c17cec694ced7921fc3081061d576af3a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 19:26:27 +0200 Subject: [PATCH 2/9] adding event instead of reuse create_code function --- ereuse_devicehub/resources/device/models.py | 25 ++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 38552e9a..ebf1d858 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -36,14 +36,15 @@ from ereuse_devicehub.resources.device.metrics import Metrics def create_code(context): - _id = Device.query.order_by(Device.id.desc()).first() or 1 - if not _id == 1: + # import pdb; pdb.set_trace() + _id = Device.query.order_by(Device.id.desc()).first() or 3 + if not _id == 3: _id = _id.id + 1 code = hashcode.encode(_id) - from ereuse_devicehub.resources.tag.model import Tag - tag = Tag(device_id=_id, id=code) - db.session.add(tag) + # from ereuse_devicehub.resources.tag.model import Tag + # tag = Tag(device_id=_id, id=code) + # db.session.add(tag) return code @@ -1169,3 +1170,17 @@ class Manufacturer(db.Model): listener_reset_field_updated_in_actual_time(Device) + + +def create_code_tag(mapper, connection, device): + """ + This function create a new tag every time than one device is create. + this tag is the same of devicehub_id. + """ + from ereuse_devicehub.resources.tag.model import Tag + tag = Tag(device_id=device.id, id=device.devicehub_id) + db.session.add(tag) + + +from flask_sqlalchemy import event +event.listen(Device, 'after_update', create_code_tag, propagate=True) From 9faa1697a71ea593e7f0ae3037be1ef6dc6fd976 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 21:14:10 +0200 Subject: [PATCH 3/9] fixing event device --- ereuse_devicehub/resources/device/models.py | 10 ++-------- tests/test_action.py | 16 ++++++++-------- 2 files changed, 10 insertions(+), 16 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index ebf1d858..187dfb9c 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -36,16 +36,10 @@ from ereuse_devicehub.resources.device.metrics import Metrics def create_code(context): - # import pdb; pdb.set_trace() _id = Device.query.order_by(Device.id.desc()).first() or 3 if not _id == 3: _id = _id.id + 1 - code = hashcode.encode(_id) - - # from ereuse_devicehub.resources.tag.model import Tag - # tag = Tag(device_id=_id, id=code) - # db.session.add(tag) - return code + return hashcode.encode(_id) class Device(Thing): @@ -1183,4 +1177,4 @@ def create_code_tag(mapper, connection, device): from flask_sqlalchemy import event -event.listen(Device, 'after_update', create_code_tag, propagate=True) +event.listen(Device, 'after_insert', create_code_tag, propagate=True) diff --git a/tests/test_action.py b/tests/test_action.py index 825bdb0a..888541f3 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -260,10 +260,10 @@ def test_generic_action(action_model_state: Tuple[models.Action, states.Trading] @pytest.mark.parametrize('action_model', (pytest.param(ams, id=ams.__class__.__name__) for ams in [ - models.Recycling, - models.Use, - models.Refurbish, - models.Management + models.Recycling, + models.Use, + models.Refurbish, + models.Management ])) def test_simple_status_actions(action_model: models.Action, user: UserClient, user2: UserClient): """Simple test of status action.""" @@ -281,10 +281,10 @@ def test_simple_status_actions(action_model: models.Action, user: UserClient, us @pytest.mark.parametrize('action_model', (pytest.param(ams, id=ams.__class__.__name__) for ams in [ - models.Recycling, - models.Use, - models.Refurbish, - models.Management + models.Recycling, + models.Use, + models.Refurbish, + models.Management ])) def test_outgoinlot_status_actions(action_model: models.Action, user: UserClient, user2: UserClient): """Test of status actions in outgoinlot.""" From 1bfb80de520b2621b66b7d76281b5ae86c34d41c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 22 Oct 2021 22:34:32 +0200 Subject: [PATCH 4/9] fixing tests --- tests/test_device.py | 17 ++++++++++++----- tests/test_device_find.py | 6 +++--- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 9dcfd53f..4f366c51 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -309,9 +309,10 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str): # they are not the same tags though # tag is a transient obj and db_tag the one from the db # they have the same pk though - assert tag != db_tag, 'They are not the same tags though' - assert db_tag.id == tag.id assert d.Desktop.query.one() == pc, 'd.Desktop had to be set to db' + assert tag != db_tag, 'They are not the same tags though' + for tag in pc.tags: + assert tag.id in ['foo', pc.devicehub_id] @pytest.mark.mvp @@ -346,8 +347,10 @@ def test_sync_execute_register_tag_linked_same_device(): pc.tags.add(Tag(id='foo')) db_pc = Sync().execute_register(pc) assert db_pc.id == orig_pc.id - assert len(db_pc.tags) == 1 - assert next(iter(db_pc.tags)).id == 'foo' + assert len(db_pc.tags) == 2 + # import pdb; pdb.set_trace() + for tag in db_pc.tags: + assert tag.id in ['foo', db_pc.devicehub_id] @pytest.mark.mvp @@ -399,13 +402,14 @@ def test_sync_execute_register_mismatch_between_tags_and_hid(): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_device(user: UserClient): """Checks GETting a d.Desktop with its components.""" + g.user = User.query.one() pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', chassis=ComputerChassis.Tower, owner_id=user.user['id']) pc.components = OrderedSet([ - d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', + d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s', owner_id=user.user['id']), d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']) ]) @@ -437,6 +441,7 @@ def test_get_device(user: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_get_devices(app: Devicehub, user: UserClient): """Checks GETting multiple devices.""" + g.user = User.query.one() pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', @@ -604,6 +609,7 @@ def test_device_public(user: UserClient, client: Client): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_computer_accessory_model(user: UserClient): + g.user = User.query.one() sai = d.SAI(owner_id=user.user['id']) db.session.add(sai) keyboard = d.Keyboard(layout=Layouts.ES, owner_id=user.user['id']) @@ -616,6 +622,7 @@ def test_computer_accessory_model(user: UserClient): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_networking_model(user: UserClient): + g.user = User.query.one() router = d.Router(speed=1000, wireless=True, owner_id=user.user['id']) db.session.add(router) switch = d.Switch(speed=1000, wireless=False, owner_id=user.user['id']) diff --git a/tests/test_device_find.py b/tests/test_device_find.py index 306dae32..7407f3f8 100644 --- a/tests/test_device_find.py +++ b/tests/test_device_find.py @@ -183,7 +183,7 @@ def test_device_query(user: UserClient): pc = next(d for d in i['items'] if d['type'] == 'Desktop') assert len(pc['actions']) == 4 assert len(pc['components']) == 3 - assert not pc['tags'] + assert pc['tags'][0]['id'] == pc['devicehubID'] @pytest.mark.mvp @@ -201,10 +201,10 @@ def test_device_query_permitions(user: UserClient, user2: UserClient): user2.post(json_encode(basic_snapshot), res=Snapshot) i2, _ = user2.get(res=Device) pc2 = next(d for d in i2['items'] if d['type'] == 'Desktop') - + assert pc1['id'] != pc2['id'] assert pc1['hid'] == pc2['hid'] - + @pytest.mark.mvp def test_device_search_all_devices_token_if_empty(app: Devicehub, user: UserClient): From 1c2f6ba92c7bc7053aec5435941995955f776ea4 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 23 Oct 2021 13:02:10 +0200 Subject: [PATCH 5/9] fixing tests --- ereuse_devicehub/resources/device/models.py | 2 +- tests/files/basic.csv | 2 +- tests/files/proposal_extended_csv_report.csv | 4 ++-- tests/test_documents.py | 9 +++------ tests/test_lot.py | 3 +++ tests/test_metrics.py | 4 ++-- tests/test_snapshot.py | 6 +++--- 7 files changed, 15 insertions(+), 15 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 187dfb9c..473ca640 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -6,6 +6,7 @@ from fractions import Fraction from itertools import chain from operator import attrgetter from typing import Dict, List, Set +from flask_sqlalchemy import event from boltons import urlutils from citext import CIText @@ -1176,5 +1177,4 @@ def create_code_tag(mapper, connection, device): db.session.add(tag) -from flask_sqlalchemy import event event.listen(Device, 'after_insert', create_code_tag, propagate=True) diff --git a/tests/files/basic.csv b/tests/files/basic.csv index 45750ae9..253838e9 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ DHID;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 Certificate URL;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 Certificate URL;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 Certificate URL;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 Certificate URL;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;Mon Aug 2 10:25:31 2021;Workbench 11.0;2021-08-02 10:25:31.457986+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;; +O48N2;;http://localhost/devices/O48N2;;named;O48N2;FooOrg;;;;;;;desktop-d1mr-d1ml-d1s;Desktop;Microtower;d1s;d1ml;d1mr;Mon Aug 2 10:25:31 2021;Workbench 11.0;2021-08-02 10:25:31.457986+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 2aacace8..67f8bf27 100644 --- a/tests/files/proposal_extended_csv_report.csv +++ b/tests/files/proposal_extended_csv_report.csv @@ -1,3 +1,3 @@ DHID;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 Certificate URL;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 Certificate URL;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 Certificate URL;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 Certificate URL;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.;Mon Aug 2 10:27:27 2021;Workbench 11.0a2;2021-08-02 10:27:27.772331+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-08-02 10:27:27.163611+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.;Mon Aug 2 10:27:27 2021;Workbench 11.0b11;2021-08-02 10:27:27.528832+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-08-02 10:27:27.458348+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-08-02 10:27:27.460573+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-08-02 10:27:27.464663+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 +O48N2;;http://localhost/devices/O48N2;;named;O48N2;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048285-14:da:e9:42:f6:7b;Laptop;Netbook;b8oaas048285;1001pxd;asustek computer inc.;Mon Aug 2 10:27:27 2021;Workbench 11.0a2;2021-08-02 10:27:27.772331+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-08-02 10:27:27.163611+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;;named;J2MA2;FooOrg;;;;;;;laptop-asustek_computer_inc-1001pxd-b8oaas048287-14:da:e9:42:f6:7c;Laptop;Netbook;b8oaas048287;1001pxd;asustek computer inc.;Mon Aug 2 10:27:27 2021;Workbench 11.0b11;2021-08-02 10:27:27.528832+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-08-02 10:27:27.458348+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-08-02 10:27:27.460573+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-08-02 10:27:27.464663+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 240fa738..9e86acfe 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -219,7 +219,7 @@ def test_export_basic_snapshot(user: UserClient): item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) - + f = StringIO(csv_str) obj_csv = csv.reader(f, f, delimiter=';', quotechar='"') export_csv = list(obj_csv) @@ -251,13 +251,13 @@ def test_check_insert_hash(app: Devicehub, user: UserClient, client: Client): assert ReportHash.query.filter_by(hash3=hash3).count() == 1 result, status = client.get(res=documents.DocumentDef.t, item='check/', query=[('hash', hash3)]) assert status.status_code == 200 - assert result == True + assert result ff = open('/tmp/test.csv', 'w') ff.write(csv_str) ff.close() - a= open('/tmp/test.csv').read() + a = open('/tmp/test.csv').read() assert hash3 == hashlib.sha3_256(a.encode('utf-8')).hexdigest() @@ -268,10 +268,7 @@ def test_export_extended(app: Devicehub, user: UserClient): snapshot2, _ = user.post(file('complete.export.snapshot'), res=Snapshot, status=201) with app.app_context(): # Create a pc with a tag - tag = Tag(id='foo', owner_id=user.user['id']) - # pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) pc = d.Device.query.filter_by(id=snapshot1['device']['id']).first() - pc.tags.add(tag) db.session.add(pc) db.session.commit() diff --git a/tests/test_lot.py b/tests/test_lot.py index e71f9d6d..3f1f0731 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -361,6 +361,7 @@ def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): """ # todo check with components with app.app_context(): + g.user = User.query.one() device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', @@ -391,9 +392,11 @@ def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_lot_error_add_device_from_other_user(user: UserClient): + # TODO """Tests adding a device to a lot using POST and removing it with DELETE. """ + g.user = User.query.one() user2 = User(email='baz@baz.cxm', password='baz') user2.individuals.add(Person(name='Tommy')) db.session.add(user2) diff --git a/tests/test_metrics.py b/tests/test_metrics.py index afeeba8b..6b403c4a 100644 --- a/tests/test_metrics.py +++ b/tests/test_metrics.py @@ -135,7 +135,7 @@ def test_metrics_action_status(user: UserClient, user2: UserClient): accept='text/csv', query=[('filter', {'type': ['Computer']})]) 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;Action-Create;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;;' + body = 'O48N2;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 @@ -176,7 +176,7 @@ def test_complet_metrics_with_trade(user: UserClient, user2: UserClient): accept='text/csv', query=[('filter', {'type': ['Computer']})]) - body1_lenovo = '93652;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;foo2@foo.com;Supplier;False;Refurbish;Use;' + body1_lenovo = 'O48N2;desktop-lenovo-9644w8n-0169622-00:1a:6b:5e:7f:10;;Trade;foo@foo.com;foo2@foo.com;Supplier;False;Refurbish;Use;' body2_lenovo = ';;0;0;Trade;0;0\n' body1_acer = 'J2MA2;laptop-acer-aohappy-lusea0d010038879a01601-00:26:c7:8e:cb:8c;;Trade;foo@foo.com;foo2@foo.com;Supplier;False;;Use;;;0;' diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index eaeca85c..a31a6c4e 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -37,7 +37,7 @@ from tests import conftest @pytest.mark.mvp @pytest.mark.usefixtures('auth_app_context') -# cayop + # import pdb; pdb.set_trace() def test_snapshot_model(): """Tests creating a Snapshot with its relationships ensuring correct DB mapping. @@ -318,7 +318,7 @@ def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub): snapshot_and_check(user, b, action_types=(RateComputer.t, BenchmarkProcessor.t, VisualTest.t)) with app.app_context(): - tag = Tag.query.one() # type: Tag + tag = Tag.query.all()[0] # type: Tag assert tag.device_id == 3, 'Tag should be linked to the first device' @@ -358,7 +358,7 @@ def test_snapshot_different_properties_same_tags(user: UserClient, tag_id: str): def test_snapshot_upload_twice_uuid_error(user: UserClient): pc1 = file('basic.snapshot') user.post(pc1, res=Snapshot) - user.post(pc1, res=Snapshot, status=UniqueViolation) + user.post(pc1, res=Snapshot, status=400) @pytest.mark.mvp From 7ef31a3ba374dd5950abbacd6f3eb55f357d8a13 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 23 Oct 2021 13:41:26 +0200 Subject: [PATCH 6/9] fixing tests --- tests/test_device.py | 1 - tests/test_snapshot.py | 1 - tests/test_tag.py | 20 ++++++++++++++------ 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 4f366c51..3ffef3a9 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -348,7 +348,6 @@ def test_sync_execute_register_tag_linked_same_device(): db_pc = Sync().execute_register(pc) assert db_pc.id == orig_pc.id assert len(db_pc.tags) == 2 - # import pdb; pdb.set_trace() for tag in db_pc.tags: assert tag.id in ['foo', db_pc.devicehub_id] diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index a31a6c4e..130413c8 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -37,7 +37,6 @@ from tests import conftest @pytest.mark.mvp @pytest.mark.usefixtures('auth_app_context') - # import pdb; pdb.set_trace() def test_snapshot_model(): """Tests creating a Snapshot with its relationships ensuring correct DB mapping. diff --git a/tests/test_tag.py b/tests/test_tag.py index 67d59ccc..ce618e0b 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -2,6 +2,7 @@ import pathlib import pytest import requests_mock +from flask import g from boltons.urlutils import URL from ereuse_utils.session import DevicehubClient from pytest import raises @@ -11,6 +12,7 @@ from teal.marshmallow import ValidationError from ereuse_devicehub.client import UserClient, Client from ereuse_devicehub.db import db from ereuse_devicehub.devicehub import Devicehub +from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.action.models import Snapshot from ereuse_devicehub.resources.agent.models import Organization from ereuse_devicehub.resources.device.models import Desktop, Device @@ -19,7 +21,7 @@ from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.tag.view import CannotCreateETag, LinkedToAnotherDevice, \ TagNotLinked from tests import conftest -from tests.conftest import file, yaml2json, json_encode +from tests.conftest import yaml2json, json_encode @pytest.mark.mvp @@ -41,6 +43,7 @@ def test_create_tag(user: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_create_tag_with_device(user: UserClient): """Creates a tag specifying linked with one device.""" + g.user = User.query.one() pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) db.session.add(pc) db.session.commit() @@ -60,13 +63,14 @@ def test_create_tag_with_device(user: UserClient): def test_delete_tags(user: UserClient, client: Client): """Delete a named tag.""" # Delete Tag Named + g.user = User.query.one() pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) db.session.add(pc) db.session.commit() tag = Tag(id='bar', owner_id=user.user['id'], device_id=pc.id) db.session.add(tag) db.session.commit() - tag = Tag.query.one() + tag = Tag.query.all()[-1] assert tag.id == 'bar' # Is not possible delete one tag linked to one device res, _ = user.delete(res=Tag, item=tag.id, status=422) @@ -88,12 +92,12 @@ def test_delete_tags(user: UserClient, client: Client): tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']) db.session.add(tag) db.session.commit() - tag = Tag.query.one() + tag = Tag.query.all()[-1] assert tag.id == 'bar-1' res, _ = user.delete(res=Tag, item=tag.id, status=422) msg = 'This tag {} is unnamed tag. It is imposible delete.'.format(tag.id) assert msg in res['message'] - tag = Tag.query.one() + tag = Tag.query.all()[-1] assert tag.id == 'bar-1' @@ -182,6 +186,7 @@ def test_tag_get_device_from_tag_endpoint(app: Devicehub, user: UserClient): """Checks getting a linked device from a tag endpoint""" with app.app_context(): # Create a pc with a tag + g.user = User.query.one() tag = Tag(id='foo-bar', owner_id=user.user['id']) pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) pc.tags.add(tag) @@ -213,6 +218,7 @@ def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: Us system should not return any of both (to be deterministic) so it should raise an exception. """ + g.user = User.query.all()[0] db.session.add(Tag(id='foo', secondary='bar', owner_id=user.user['id'])) db.session.commit() @@ -276,6 +282,7 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): Checks search has the term. """ with app.app_context(): + g.user = User.query.one() db.session.add(Tag('foo-bar', secondary='foo-sec', owner_id=user.user['id'])) desktop = Desktop(serial_number='foo', chassis=ComputerChassis.AllInOne, owner_id=user.user['id']) db.session.add(desktop) @@ -284,7 +291,7 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): devicehub_id = desktop.devicehub_id user.put({}, res=Tag, item='foo-bar/device/{}'.format(desktop_id), status=204) device, _ = user.get(res=Device, item=devicehub_id) - assert device['tags'][0]['id'] == 'foo-bar' + assert device['tags'][-1]['id'] == 'foo-bar' # Device already linked # Just returns an OK to conform to PUT as anything changes @@ -412,6 +419,7 @@ def test_get_tag_permissions(app: Devicehub, user: UserClient, user2: UserClient """Creates a tag specifying a custom organization.""" with app.app_context(): # Create a pc with a tag + g.user = User.query.all()[0] tag = Tag(id='foo-bar', owner_id=user.user['id']) pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) pc.tags.add(tag) @@ -424,5 +432,5 @@ def test_get_tag_permissions(app: Devicehub, user: UserClient, user2: UserClient computer2, res2 = user2.get(url, None) assert res.status_code == 200 assert res2.status_code == 200 - assert len(computer['items']) == 1 + assert len(computer['items']) == 2 assert len(computer2['items']) == 0 From 0b8304b729600742400bc641d8c7a4c76976c40a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 23 Oct 2021 14:02:49 +0200 Subject: [PATCH 7/9] fixing test --- tests/test_tag.py | 4 ++-- tests/test_workbench.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_tag.py b/tests/test_tag.py index ce618e0b..3264750d 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -330,8 +330,8 @@ def test_tag_secondary_workbench_link_find(user: UserClient): s['device']['tags'] = [{'id': 'foo', 'secondary': 'bar', 'type': 'Tag'}] snapshot, _ = user.post(json_encode(s), res=Snapshot) device, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) - assert device['tags'][0]['id'] == 'foo' - assert device['tags'][0]['secondary'] == 'bar' + assert device['tags'][-1]['id'] == 'foo' + assert device['tags'][-1]['secondary'] == 'bar' r, _ = user.get(res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})]) assert len(r['items']) == 1 diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 8dd2e65f..e668e8f3 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -184,7 +184,7 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): assert pc['serialNumber'] == 'b8oaas048286' assert pc['manufacturer'] == 'asustek computer inc.' assert pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c' - assert pc['tags'] == [] + assert len(pc['tags']) == 1 assert pc['networkSpeeds'] == [100, 0], 'Although it has WiFi we do not know the speed' assert pc['rate'] rate = pc['rate'] From 2dd1a3cfd5a1c131c05bc4b92557565fd8525a8b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 23 Oct 2021 14:44:09 +0200 Subject: [PATCH 8/9] fixed random tag order --- tests/test_tag.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/test_tag.py b/tests/test_tag.py index 3264750d..f852a206 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -291,7 +291,7 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): devicehub_id = desktop.devicehub_id user.put({}, res=Tag, item='foo-bar/device/{}'.format(desktop_id), status=204) device, _ = user.get(res=Device, item=devicehub_id) - assert device['tags'][-1]['id'] == 'foo-bar' + assert 'foo-bar' in [x['id'] for x in device['tags']] # Device already linked # Just returns an OK to conform to PUT as anything changes @@ -330,8 +330,8 @@ def test_tag_secondary_workbench_link_find(user: UserClient): s['device']['tags'] = [{'id': 'foo', 'secondary': 'bar', 'type': 'Tag'}] snapshot, _ = user.post(json_encode(s), res=Snapshot) device, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) - assert device['tags'][-1]['id'] == 'foo' - assert device['tags'][-1]['secondary'] == 'bar' + assert 'foo' in [x['id'] for x in device['tags']] + assert 'bar' in [x.get('secondary') for x in device['tags']] r, _ = user.get(res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})]) assert len(r['items']) == 1 From 3531f607da2fb8ec33c60d64703f49f580f336d0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Sat, 23 Oct 2021 15:01:50 +0200 Subject: [PATCH 9/9] fixing other orther of tags --- tests/test_workbench.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_workbench.py b/tests/test_workbench.py index e668e8f3..9998decc 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -67,7 +67,7 @@ def test_workbench_server_condensed(user: UserClient): assert device['rate']['type'] == RateComputer.t # TODO JN why haven't same order in actions on each execution? assert device['actions'][2]['type'] == BenchmarkProcessor.t or device['actions'][2]['type'] == BenchmarkRamSysbench.t - assert device['tags'][0]['id'] == 'tag1' + assert 'tag1' in [x['id'] for x in device['tags']] @pytest.mark.xfail(reason='Functionality not yet developed.')