From aed23450df8c146ace536d1921303f47bbfcb56e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 19 Jul 2022 12:27:10 +0200 Subject: [PATCH] fix tests --- tests/files/export_devices.csv | 2 +- tests/test_render_2_0.py | 119 ++++++------ tests/test_snapshot.py | 12 -- tests/test_system_uuid.py | 332 ++++++++++++++++++++++----------- tests/test_tag.py | 153 ++++++++++----- tests/test_workbench.py | 79 +++++--- 6 files changed, 438 insertions(+), 259 deletions(-) diff --git a/tests/files/export_devices.csv b/tests/files/export_devices.csv index 0a9305b3..c04354f5 100644 --- a/tests/files/export_devices.csv +++ b/tests/files/export_devices.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;Allocate state;Lifecycle 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 cycle count;Test DataStorage 1 Lifetime (days);Test DataStorage 1 Power on hours;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 cycle count;Test DataStorage 2 Lifetime (days);Test DataStorage 2 Power on hours;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 cycle count;Test DataStorage 3 Lifetime (days);Test DataStorage 3 Power on hours;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 cycle count;Test DataStorage 4 Lifetime (days);Test DataStorage 4 Power on hours;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) -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 May 16 19:03:20 2022;Workbench 11.0a2;2022-05-16 19:03:20.478795+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;2022-05-16 19:03:20.354718+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;;;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;SoundCard 9: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;;;;;;;;;;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.;Tue Jul 19 12:01:13 2022;Workbench 11.0a2;2022-07-19 12:01:13.257367+02:00;;;;;intel atom cpu n455 @ 2.66ghz;1024;238475;Processor 7: 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 11: model None, S/N None;;;;1024;667;;;;;;;;;;;;;;;;;;;HardDrive 12: model hts54322, S/N e2024242cv86mm;hitachi;hts54322;e2024242cv86mm;238475;harddrive-hitachi-hts54322-e2024242cv86mm;e2024242cv86mm;238475;Workbench 11.0a2;Success;;EraseBasic;Shred;1:16:49;2022-07-19 12:01:13.203689+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;;;0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;Motherboard 13: model 1001pxd, S/N eee0123456720;asustek computer inc.;1001pxd;eee0123456720;;;;;GraphicCard 8: 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 5: 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 6: 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 9: model nm10/ich7 family high definition audio controller, S/N None;intel corporation;nm10/ich7 family high definition audio controller;;SoundCard 10: model usb 2.0 uvc vga webcam, S/N 0x0001;azurewave;usb 2.0 uvc vga webcam;0x0001;;;;;;;;;;15.7188 diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 944995e6..2bf0bed9 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -190,7 +190,7 @@ def test_inventory_with_device(user3: UserClientFlask): assert status == '200 OK' assert "Unassigned" in body - assert db_snapthot.device.devicehub_id in body + assert db_snapthot.device.binding.device.devicehub_id in body @pytest.mark.mvp @@ -203,7 +203,7 @@ def test_inventory_filter(user3: UserClientFlask): assert status == '200 OK' assert "Unassigned" in body - assert db_snapthot.device.devicehub_id in body + assert db_snapthot.device.binding.device.devicehub_id in body @pytest.mark.mvp @@ -709,7 +709,7 @@ def test_action_recycling(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' @@ -722,15 +722,15 @@ def test_action_recycling(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Recycling", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'Recycling' + assert dev.binding.device.actions[-1].type == 'Recycling' assert 'Action "Recycling" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -764,15 +764,15 @@ def test_action_use(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Use", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'Use' + assert dev.binding.device.actions[-1].type == 'Use' assert 'Action "Use" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -787,15 +787,15 @@ def test_action_refurbish(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Refurbish", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'Refurbish' + assert dev.binding.device.actions[-1].type == 'Refurbish' assert 'Action "Refurbish" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -810,15 +810,15 @@ def test_action_management(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Management", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'Management' + assert dev.binding.device.actions[-1].type == 'Management' assert 'Action "Management" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -833,7 +833,7 @@ def test_action_allocate(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-01', 'end_time': '2000-06-01', 'end_users': 2, @@ -842,9 +842,9 @@ def test_action_allocate(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'Allocate' + assert dev.binding.device.actions[-1].type == 'Allocate' assert 'Action "Allocate" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -859,18 +859,18 @@ def test_action_allocate_error_required(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Trade", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/allocate/add/' body, status = user3.post(uri, data=data) - assert dev.actions[-1].type != 'Allocate' + assert 'Allocate' not in [x.type for x in dev.binding.device.actions] data = { 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/allocate/add/' @@ -892,7 +892,7 @@ def test_action_allocate_error_dates(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-06-01', 'end_time': '2000-01-01', 'end_users': 2, @@ -903,7 +903,7 @@ def test_action_allocate_error_dates(user3: UserClientFlask): assert status == '200 OK' assert 'Action Allocate error' in body assert 'The action cannot finish before it starts.' in body - assert dev.actions[-1].type != 'Allocate' + assert 'Allocate' not in [x.type for x in dev.binding.device.actions] @pytest.mark.mvp @@ -920,7 +920,7 @@ def test_action_allocate_error_future_dates(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': start_time, 'end_time': end_time, 'end_users': 2, @@ -931,7 +931,7 @@ def test_action_allocate_error_future_dates(user3: UserClientFlask): assert status == '200 OK' assert 'Action Allocate error' in body assert 'Not a valid date value.!' in body - assert dev.actions[-1].type != 'Allocate' + assert 'Allocate' not in [x.type for x in dev.binding.device.actions] @pytest.mark.mvp @@ -946,7 +946,7 @@ def test_action_deallocate(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-01', 'end_time': '2000-06-01', 'end_users': 2, @@ -955,22 +955,22 @@ def test_action_deallocate(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' user3.post(uri, data=data) - assert dev.allocated_status.type == 'Allocate' + assert dev.binding.device.allocated_status.type == 'Allocate' data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-01', 'end_time': '2000-06-01', 'end_users': 2, } body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.allocated_status.type == 'Deallocate' + assert dev.binding.device.allocated_status.type == 'Deallocate' assert 'Action "Deallocate" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @@ -985,7 +985,7 @@ def test_action_deallocate_error(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-05-01', 'end_time': '2000-06-01', 'end_users': 2, @@ -994,20 +994,20 @@ def test_action_deallocate_error(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' user3.post(uri, data=data) - assert dev.allocated_status.type == 'Allocate' + assert dev.binding.device.allocated_status.type == 'Allocate' data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-01', 'end_time': '2000-02-01', 'end_users': 2, } body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.allocated_status.type != 'Deallocate' + assert dev.binding.device.allocated_status.type != 'Deallocate' assert 'Action Deallocate error!' in body assert 'Sorry some of this devices are actually deallocate' in body @@ -1024,7 +1024,7 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-01', 'end_time': '2000-01-01', 'end_users': 2, @@ -1033,36 +1033,36 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' user3.post(uri, data=data) - assert dev.allocated_status.type == 'Allocate' - assert len(dev.actions) == 11 + assert dev.binding.device.allocated_status.type == 'Allocate' + assert len(dev.binding.device.actions) == 1 data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-02-01', 'end_time': '2000-02-01', 'end_users': 2, } body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.allocated_status.type == 'Deallocate' - assert len(dev.actions) == 12 + assert dev.binding.device.allocated_status.type == 'Deallocate' + assert len(dev.binding.device.actions) == 2 # is not possible to do an allocate between an allocate and an deallocate data = { 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-15', 'end_time': '2000-01-15', 'end_users': 2, } user3.post(uri, data=data) - assert dev.allocated_status.type == 'Deallocate' + assert dev.binding.device.allocated_status.type == 'Deallocate' # assert 'Action Deallocate error!' in body # assert 'Sorry some of this devices are actually deallocate' in body # @@ -1070,14 +1070,14 @@ def test_action_allocate_deallocate_error(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-15', 'end_time': '2000-01-15', 'end_users': 2, } user3.post(uri, data=data) - assert len(dev.actions) == 12 + assert len(dev.binding.device.actions) == 2 @pytest.mark.mvp @@ -1092,7 +1092,7 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-10', 'end_users': 2, } @@ -1100,25 +1100,25 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' user3.post(uri, data=data) - assert len(dev.actions) == 11 + assert len(dev.binding.device.actions) == 1 data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-20', 'end_users': 2, } body, status = user3.post(uri, data=data) assert status == '200 OK' - assert len(dev.actions) == 12 + assert len(dev.binding.device.actions) == 2 data = { 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-02-10', 'end_users': 2, } @@ -1126,40 +1126,40 @@ def test_action_allocate_deallocate_error2(user3: UserClientFlask): uri = '/inventory/action/allocate/add/' user3.post(uri, data=data) - assert len(dev.actions) == 13 + assert len(dev.binding.device.actions) == 3 data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-02-20', 'end_users': 2, } user3.post(uri, data=data) - assert len(dev.actions) == 14 + assert len(dev.binding.device.actions) == 4 data = { 'csrf_token': generate_csrf(), 'type': "Allocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-25', 'end_users': 2, } user3.post(uri, data=data) - assert len(dev.actions) == 15 + assert len(dev.binding.device.actions) == 5 data = { 'csrf_token': generate_csrf(), 'type': "Deallocate", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), 'start_time': '2000-01-27', 'end_users': 2, } user3.post(uri, data=data) - assert len(dev.actions) == 16 + assert len(dev.binding.device.actions) == 6 @pytest.mark.mvp @@ -1174,20 +1174,21 @@ def test_action_toprepare(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'type': "ToPrepare", 'severity': "Info", - 'devices': "{}".format(dev.id), + 'devices': "{}".format(dev.binding.device.id), } uri = '/inventory/action/add/' body, status = user3.post(uri, data=data) assert status == '200 OK' - assert dev.actions[-1].type == 'ToPrepare' + assert dev.binding.device.actions[-1].type == 'ToPrepare' assert 'Action "ToPrepare" created successfully!' in body - assert dev.devicehub_id in body + assert dev.binding.device.devicehub_id in body @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) def test_action_prepare(user3: UserClientFlask): + # ??? snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json') dev = snap.device uri = '/inventory/device/' diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index a6738711..5888b05c 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -367,18 +367,6 @@ def test_snapshot_mismatch_id(): pass -@pytest.mark.mvp -def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub): - """Tests a posting Snapshot with a local tag.""" - b = yaml2json('basic.snapshot') - b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}] - - snapshot_and_check(user, b, action_types=(BenchmarkProcessor.t, VisualTest.t)) - with app.app_context(): - tag = Tag.query.all()[0] # type: Tag - assert tag.device_id == 3, 'Tag should be linked to the first device' - - @pytest.mark.mvp def test_snapshot_tag_inner_tag_mismatch_between_tags_and_hid( user: UserClient, tag_id: str diff --git a/tests/test_system_uuid.py b/tests/test_system_uuid.py index e8f62956..71eae0e7 100644 --- a/tests/test_system_uuid.py +++ b/tests/test_system_uuid.py @@ -92,7 +92,7 @@ def test_wb11_to_wb11_with_uuid_api(user: UserClient): db_snapthot = Snapshot.query.one() device = db_snapthot.device - assert Computer.query.count() == 1 + assert Computer.query.count() == 2 assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' assert device.system_uuid is None @@ -106,10 +106,14 @@ def test_wb11_to_wb11_with_uuid_api(user: UserClient): snapshot_11['debug']['lshw']['configuration']['uuid'] == '364ee69c-9c82-9cb1-2111-88ae1da6f3d0' ) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -123,20 +127,28 @@ def test_wb11_with_uuid_to_wb11_api(user: UserClient): snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003' user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' # insert the same computer with wb11 with hid and with uuid, (new version) snapshot_11 = conftest.file_json('system_uuid3.json') assert 'debug' not in snapshot_11 user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -150,10 +162,14 @@ def test_wb11_with_uuid_to_wb11_without_hid_api(user: UserClient): snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003' user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' # insert the same computer with wb11 with hid and with uuid, (new version) snapshot_11 = conftest.file_json('system_uuid3.json') @@ -162,7 +178,7 @@ def test_wb11_with_uuid_to_wb11_without_hid_api(user: UserClient): snapshot_11['debug'] = {'lshw': snapshot_lite['data']['lshw']} user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 + assert Computer.query.count() == 2 @pytest.mark.mvp @@ -186,7 +202,7 @@ def test_wb11_to_wb11_with_uuid_form(user3: UserClientFlask): db_snapthot = Snapshot.query.one() device = db_snapthot.device - assert Computer.query.count() == 1 + assert Computer.query.count() == 2 assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' assert device.system_uuid is None @@ -203,10 +219,14 @@ def test_wb11_to_wb11_with_uuid_form(user3: UserClientFlask): } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -231,10 +251,14 @@ def test_wb11_with_uuid_to_wb11_form(user3: UserClientFlask): } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' # insert the same computer with wb11 with hid and with uuid, (new version) snapshot = conftest.file_json('system_uuid3.json') @@ -248,10 +272,14 @@ def test_wb11_with_uuid_to_wb11_form(user3: UserClientFlask): } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -276,10 +304,14 @@ def test_wb11_with_uuid_to_wb11_without_hid_form(user3: UserClientFlask): } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' # insert the same computer with wb11 with hid and with uuid, (new version) snapshot_11 = conftest.file_json('system_uuid3.json') @@ -295,7 +327,7 @@ def test_wb11_with_uuid_to_wb11_without_hid_form(user3: UserClientFlask): } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 + assert Computer.query.count() == 2 @pytest.mark.mvp @@ -305,17 +337,25 @@ def test_wb11_to_wblite_api(user: UserClient): # insert computer with wb11 with hid and without uuid, (old version) snapshot_11 = conftest.file_json('system_uuid3.json') user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None snapshot_lite = conftest.file_json('system_uuid2.json') user.post(snapshot_lite, uri="/api/inventory/") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -324,17 +364,25 @@ def test_wblite_to_wb11_api(user: UserClient): snapshot_lite = conftest.file_json('system_uuid2.json') user.post(snapshot_lite, uri="/api/inventory/") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' snapshot_11 = conftest.file_json('system_uuid3.json') user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -354,10 +402,14 @@ def test_wb11_to_wblite_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None file_name = 'system_uuid2.json' snapshot_lite = conftest.file_json(file_name) @@ -369,10 +421,14 @@ def test_wb11_to_wblite_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -392,10 +448,14 @@ def test_wblite_to_wb11_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' file_name = 'system_uuid3.json' snapshot_11 = conftest.file_json(file_name) @@ -407,10 +467,14 @@ def test_wblite_to_wb11_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -419,18 +483,26 @@ def test_wblite_to_wblite_api(user: UserClient): snapshot_lite = conftest.file_json('system_uuid2.json') user.post(snapshot_lite, uri="/api/inventory/") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' snapshot_lite = conftest.file_json('system_uuid2.json') snapshot_lite['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003' user.post(snapshot_lite, uri="/api/inventory/") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -450,10 +522,14 @@ def test_wblite_to_wblite_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' file_name = 'system_uuid2.json' snapshot_lite = conftest.file_json(file_name) @@ -466,10 +542,14 @@ def test_wblite_to_wblite_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -479,17 +559,21 @@ def test_wb11_to_wb11_duplicity_api(user: UserClient): # insert computer with wb11 with hid and without uuid, (old version) snapshot_11 = conftest.file_json('system_uuid3.json') user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None snapshot_11 = conftest.file_json('system_uuid3.json') snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003' components = [x for x in snapshot_11['components'] if x['type'] != 'NetworkAdapter'] snapshot_11['components'] = components user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 2 + assert Computer.query.count() == 4 for c in Computer.query.all(): assert 'laptop-acer-aohappy-lusea0d010038879a01601' in c.hid assert c.system_uuid is None @@ -512,10 +596,14 @@ def test_wb11_to_wb11_duplicity_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None snapshot_11 = conftest.file_json('system_uuid3.json') snapshot_11['uuid'] = '0973fda0-589a-11eb-ae93-0242ac130003' @@ -530,10 +618,12 @@ def test_wb11_to_wb11_duplicity_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 2 - for c in Computer.query.all(): - assert 'laptop-acer-aohappy-lusea0d010038879a01601' in c.hid - assert c.system_uuid is None + + assert Computer.query.count() == 4 + for device in Computer.query.all(): + if device.binding: + assert 'laptop-acer-aohappy-lusea0d010038879a01601' in device.hid + assert device.system_uuid is None @pytest.mark.mvp @@ -543,10 +633,14 @@ def test_wb11_smbios_2_5_api(user: UserClient): # insert computer with wb11 with hid and without uuid, (old version) snapshot_11 = conftest.file_json('system_uuid4.json') user.post(snapshot_11, res=Snapshot) - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None @pytest.mark.mvp @@ -566,10 +660,14 @@ def test_wb11_smbios_2_5_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert device.system_uuid is None + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert device.system_uuid is None @pytest.mark.mvp @@ -580,10 +678,14 @@ def test_wblite_smbios_2_5_api(user: UserClient): snapshot_lite = conftest.file_json('system_uuid2.json') snapshot_lite['data']['lshw']['capabilities']['smbios-3.0'] = 'SMBIOS version 2.5' user.post(snapshot_lite, uri="/api/inventory/") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' @pytest.mark.mvp @@ -604,7 +706,11 @@ def test_wblite_smbios_2_5_form(user3: UserClientFlask): 'csrf_token': generate_csrf(), } user3.post(uri, data=data, content_type="multipart/form-data") - assert Computer.query.count() == 1 - device = Computer.query.one() - assert device.hid == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' - assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' + assert Computer.query.count() == 2 + for device in Computer.query.all(): + if device.binding: + assert ( + device.hid + == 'laptop-acer-aohappy-lusea0d010038879a01601-88:ae:1d:a6:f3:d0' + ) + assert str(device.system_uuid) == '9ce64e36-829c-b19c-2111-88ae1da6f3d0' diff --git a/tests/test_tag.py b/tests/test_tag.py index f852a206..36dfb108 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -2,26 +2,29 @@ import pathlib import pytest import requests_mock -from flask import g from boltons.urlutils import URL from ereuse_utils.session import DevicehubClient +from flask import g from pytest import raises -from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation, DBError +from teal.db import DBError, MultipleResourcesFound, ResourceNotFound, UniqueViolation from teal.marshmallow import ValidationError -from ereuse_devicehub.client import UserClient, Client +from ereuse_devicehub.client import Client, UserClient 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 from ereuse_devicehub.resources.enums import ComputerChassis from ereuse_devicehub.resources.tag import Tag -from ereuse_devicehub.resources.tag.view import CannotCreateETag, LinkedToAnotherDevice, \ - TagNotLinked +from ereuse_devicehub.resources.tag.view import ( + CannotCreateETag, + LinkedToAnotherDevice, + TagNotLinked, +) +from ereuse_devicehub.resources.user.models import User from tests import conftest -from tests.conftest import yaml2json, json_encode +from tests.conftest import json_encode, yaml2json @pytest.mark.mvp @@ -29,7 +32,9 @@ from tests.conftest import yaml2json, json_encode def test_create_tag(user: UserClient): """Creates a tag specifying a custom organization.""" org = Organization(name='bar', tax_id='bartax') - tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']) + 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() @@ -44,7 +49,9 @@ def test_create_tag(user: UserClient): 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']) + 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']) @@ -64,7 +71,9 @@ 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']) + 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) @@ -89,7 +98,9 @@ def test_delete_tags(user: UserClient, client: Client): # Delete Tag UnNamed org = Organization(name='bar', tax_id='bartax') - tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']) + 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.all()[-1] @@ -106,7 +117,9 @@ def test_delete_tags(user: UserClient, client: Client): def test_create_tag_default_org(user: UserClient): """Creates a tag using the default organization.""" tag = Tag(id='foo-1', owner_id=user.user['id']) - assert not tag.org_id, 'org-id is set as default value so it should only load on flush' + assert ( + not tag.org_id + ), 'org-id is set as default value so it should only load on flush' # We don't want the organization to load, or it would make this # object, from transient to new (added to session) assert 'org' not in vars(tag), 'Organization should not have been loaded' @@ -188,7 +201,9 @@ def test_tag_get_device_from_tag_endpoint(app: Devicehub, user: UserClient): # 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 = Desktop( + serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'] + ) pc.tags.add(tag) db.session.add(pc) db.session.commit() @@ -213,7 +228,9 @@ def test_tag_get_device_from_tag_endpoint_no_tag(user: UserClient): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: UserClient, user2: UserClient, client: Client): +def test_tag_get_device_from_tag_endpoint_multiple_tags( + app: Devicehub, user: UserClient, user2: UserClient, client: Client +): """As above, but when there are two tags with the secondary ID, the system should not return any of both (to be deterministic) so it should raise an exception. @@ -232,8 +249,12 @@ def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: Us tag1 = Tag.from_an_id('foo').filter_by(owner_id=user.user['id']).one() tag2 = Tag.from_an_id('foo').filter_by(owner_id=user2.user['id']).one() - pc1 = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id']) - pc2 = Desktop(serial_number='sn2', chassis=ComputerChassis.Tower, owner_id=user2.user['id']) + pc1 = Desktop( + serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'] + ) + pc2 = Desktop( + serial_number='sn2', chassis=ComputerChassis.Tower, owner_id=user2.user['id'] + ) pc1.tags.add(tag1) pc2.tags.add(tag2) db.session.add(pc1) @@ -266,7 +287,17 @@ def test_tag_create_etags_cli(app: Devicehub, user: UserClient): # todo what happens to organization? owner_id = user.user['id'] runner = app.test_cli_runner() - args = ('tag', 'add', '-p', 'https://t.ereuse.org', '-s', 'foo', 'DT-BARBAR', '-u', owner_id) + args = ( + 'tag', + 'add', + '-p', + 'https://t.ereuse.org', + '-s', + 'foo', + 'DT-BARBAR', + '-u', + owner_id, + ) runner.invoke(*args) with app.app_context(): tag = Tag.query.one() # type: Tag @@ -284,7 +315,11 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): 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']) + desktop = Desktop( + serial_number='foo', + chassis=ComputerChassis.AllInOne, + owner_id=user.user['id'], + ) db.session.add(desktop) db.session.commit() desktop_id = desktop.id @@ -330,13 +365,21 @@ 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 'foo' in [x['id'] for x in device['tags']] - assert 'bar' in [x.get('secondary') for x in device['tags']] + desktop = Device.query.filter_by( + devicehub_id=snapshot['device']['devicehubID'] + ).one() + assert ['O48N2'] == [x['id'] for x in device['tags']] + assert 'foo' in [x.id for x in desktop.binding.device.tags] + assert 'bar' in [x.secondary for x in desktop.binding.device.tags] - r, _ = user.get(res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})]) - assert len(r['items']) == 1 - r, _ = user.get(res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})]) - assert len(r['items']) == 1 + r, _ = user.get( + res=Device, query=[('search', 'foo'), ('filter', {'type': ['Computer']})] + ) + assert len(r['items']) == 0 + r, _ = user.get( + res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})] + ) + assert len(r['items']) == 0 @pytest.mark.mvp @@ -359,19 +402,24 @@ def test_tag_multiple_secondary_org(user: UserClient): @pytest.mark.mvp -def test_create_num_regular_tags(user: UserClient, requests_mock: requests_mock.mocker.Mocker): +def test_create_num_regular_tags( + user: UserClient, requests_mock: requests_mock.mocker.Mocker +): """Create regular tags. This is done using a tag provider that returns IDs. These tags are printable. """ - requests_mock.post('https://example.com/', - # request - request_headers={ - 'Authorization': 'Basic {}'.format(DevicehubClient.encode_token( - '52dacef0-6bcb-4919-bfed-f10d2c96ecee')) - }, - # response - json=['tag1id', 'tag2id'], - status_code=201) + requests_mock.post( + 'https://example.com/', + # request + request_headers={ + 'Authorization': 'Basic {}'.format( + DevicehubClient.encode_token('52dacef0-6bcb-4919-bfed-f10d2c96ecee') + ) + }, + # response + json=['tag1id', 'tag2id'], + status_code=201, + ) data, _ = user.post({}, res=Tag, query=[('num', 2)]) assert data['items'][0]['id'] == 'tag1id' assert data['items'][0]['printable'], 'Tags made this way are printable' @@ -380,28 +428,37 @@ def test_create_num_regular_tags(user: UserClient, requests_mock: requests_mock. @pytest.mark.mvp -def test_get_tags_endpoint(user: UserClient, app: Devicehub, - requests_mock: requests_mock.mocker.Mocker): +def test_get_tags_endpoint( + user: UserClient, app: Devicehub, requests_mock: requests_mock.mocker.Mocker +): """Performs GET /tags after creating 3 tags, 2 printable and one not. Only the printable ones are returned. """ # Prepare test with app.app_context(): org = Organization(name='bar', tax_id='bartax') - tag = Tag(id='bar-1', org=org, provider=URL('http://foo.bar'), owner_id=user.user['id']) + tag = Tag( + id='bar-1', + org=org, + provider=URL('http://foo.bar'), + owner_id=user.user['id'], + ) db.session.add(tag) db.session.commit() assert not tag.printable - requests_mock.post('https://example.com/', - # request - request_headers={ - 'Authorization': 'Basic {}'.format(DevicehubClient.encode_token( - '52dacef0-6bcb-4919-bfed-f10d2c96ecee')) - }, - # response - json=['tag1id', 'tag2id'], - status_code=201) + requests_mock.post( + 'https://example.com/', + # request + request_headers={ + 'Authorization': 'Basic {}'.format( + DevicehubClient.encode_token('52dacef0-6bcb-4919-bfed-f10d2c96ecee') + ) + }, + # response + json=['tag1id', 'tag2id'], + status_code=201, + ) user.post({}, res=Tag, query=[('num', 2)]) # Test itself @@ -421,7 +478,9 @@ def test_get_tag_permissions(app: Devicehub, user: UserClient, user2: UserClient # 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 = Desktop( + serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'] + ) pc.tags.add(tag) db.session.add(pc) db.session.commit() diff --git a/tests/test_workbench.py b/tests/test_workbench.py index e91a4107..f787e502 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -1,17 +1,21 @@ """Tests that emulates the behaviour of a WorkbenchServer.""" import json +import math import pathlib -import math import pytest from ereuse_devicehub.client import UserClient from ereuse_devicehub.resources.action import models as em -from ereuse_devicehub.resources.action.models import RateComputer, BenchmarkProcessor, BenchmarkRamSysbench +from ereuse_devicehub.resources.action.models import ( + BenchmarkProcessor, + BenchmarkRamSysbench, + RateComputer, +) from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.tag.model import Tag -from tests.conftest import file, file_workbench, yaml2json, json_encode +from tests.conftest import file, file_workbench, json_encode, yaml2json @pytest.mark.mvp @@ -22,10 +26,9 @@ def test_workbench_server_condensed(user: UserClient): """ s = yaml2json('workbench-server-1.snapshot') s['device']['actions'].append(yaml2json('workbench-server-2.stress-test')) - s['components'][4]['actions'].extend(( - yaml2json('workbench-server-3.erase'), - yaml2json('workbench-server-4.install') - )) + s['components'][4]['actions'].extend( + (yaml2json('workbench-server-3.erase'), yaml2json('workbench-server-4.install')) + ) s['components'][5]['actions'].append(yaml2json('workbench-server-3.erase')) # Create tags for t in s['device']['tags']: @@ -34,7 +37,7 @@ def test_workbench_server_condensed(user: UserClient): snapshot, _ = user.post(res=em.Snapshot, data=json_encode(s)) pc_id = snapshot['device']['id'] cpu_id = snapshot['components'][3]['id'] - ssd_id= snapshot['components'][4]['id'] + ssd_id = snapshot['components'][4]['id'] hdd_id = snapshot['components'][5]['id'] actions = snapshot['actions'] assert {(action['type'], action['device']) for action in actions} == { @@ -60,8 +63,13 @@ def test_workbench_server_condensed(user: UserClient): assert device['processorModel'] == device['components'][3]['model'] == 'p1-1ml' assert device['ramSize'] == 2048, 'There are 3 RAM: 2 x 1024 and 1 None sizes' # TODO JN why haven't same order in actions on each execution? - assert any([ac['type'] in [BenchmarkProcessor.t, BenchmarkRamSysbench.t] for ac in device['actions']]) - assert 'tag1' in [x['id'] for x in device['tags']] + assert any( + [ + ac['type'] in [BenchmarkProcessor.t, BenchmarkRamSysbench.t] + for ac in device['actions'] + ] + ) + assert 'tag1' not in [x['id'] for x in device['tags']] @pytest.mark.xfail(reason='Functionality not yet developed.') @@ -136,7 +144,10 @@ def test_real_hp_11(user: UserClient): s = file('real-hp.snapshot.11') snapshot, _ = user.post(res=em.Snapshot, data=s) pc = snapshot['device'] - assert pc['hid'] == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg-6c:62:6d:81:22:9f' + assert ( + pc['hid'] + == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg-6c:62:6d:81:22:9f' + ) assert pc['chassis'] == 'Tower' assert set(e['type'] for e in snapshot['actions']) == { 'BenchmarkDataStorage', @@ -146,7 +157,7 @@ def test_real_hp_11(user: UserClient): 'BenchmarkRamSysbench', 'StressTest', 'TestBios', - 'VisualTest' + 'VisualTest', } assert len(list(e['type'] for e in snapshot['actions'])) == 8 @@ -177,22 +188,32 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): assert pc['model'] == '1001pxd' 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['hid'] + == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c' + ) assert len(pc['tags']) == 1 - assert pc['networkSpeeds'] == [100, 0], 'Although it has WiFi we do not know the speed' + assert pc['networkSpeeds'] == [ + 100, + 0, + ], 'Although it has WiFi we do not know the speed' # assert pc['actions'][0]['appearanceRange'] == 'A' # assert pc['actions'][0]['functionalityRange'] == 'B' # TODO add appearance and functionality Range in device[rate] components = snapshot['components'] wifi = components[0] - assert wifi['hid'] == 'networkadapter-qualcomm_atheros-' \ - 'ar9285_wireless_network_adapter-74_2f_68_8b_fd_c8' + assert ( + wifi['hid'] == 'networkadapter-qualcomm_atheros-' + 'ar9285_wireless_network_adapter-74_2f_68_8b_fd_c8' + ) assert wifi['serialNumber'] == '74:2f:68:8b:fd:c8' assert wifi['wireless'] eth = components[1] - assert eth['hid'] == 'networkadapter-qualcomm_atheros-' \ - 'ar8152_v2_0_fast_ethernet-14_da_e9_42_f6_7c' + assert ( + eth['hid'] == 'networkadapter-qualcomm_atheros-' + 'ar8152_v2_0_fast_ethernet-14_da_e9_42_f6_7c' + ) assert eth['speed'] == 100 assert not eth['wireless'] cpu = components[2] @@ -219,7 +240,10 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): assert em.Snapshot.t in action_types assert len(actions) == 6 gpu = components[3] - assert gpu['model'] == 'atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller' + assert ( + gpu['model'] + == 'atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller' + ) assert gpu['manufacturer'] == 'intel corporation' assert gpu['memory'] == 256 gpu, _ = user.get(res=Device, item=gpu['devicehubID']) @@ -285,25 +309,26 @@ SNAPSHOTS_NEED_ID = { 'nox.snapshot.json', 'ecs-computers.snapshot.json', 'custom.snapshot.json', - 'ecs-2.snapshot.json' + 'ecs-2.snapshot.json', } """Snapshots that do not generate HID requiring a custom ID.""" @pytest.mark.mvp -@pytest.mark.parametrize('file', - (pytest.param(f, id=f.name) - for f in pathlib.Path(__file__).parent.joinpath('workbench_files').iterdir()) - ) +@pytest.mark.parametrize( + 'file', + ( + pytest.param(f, id=f.name) + for f in pathlib.Path(__file__).parent.joinpath('workbench_files').iterdir() + ), +) def test_workbench_fixtures(file: pathlib.Path, user: UserClient): """Uploads the Snapshot files Workbench tests generate. Keep this files up to date with the Workbench version. """ s = json.load(file.open()) - user.post(res=em.Snapshot, - data=json_encode(s), - status=201) + user.post(res=em.Snapshot, data=json_encode(s), status=201) @pytest.mark.mvp