From 5d9928bd70908f944a1bc70b0031ce20b0b513f7 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 20 Jul 2022 14:58:32 +0200 Subject: [PATCH] fixed tests --- ereuse_devicehub/resources/action/schemas.py | 5 +++- tests/files/basic-stock.csv | 3 ++- tests/test_device.py | 27 ++++++++++---------- tests/test_device_find.py | 1 - tests/test_documents.py | 7 ++++- tests/test_render_2_0.py | 14 +++++----- tests/test_tag.py | 8 +++--- tests/test_workbench.py | 3 +-- 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 39f51e2c..56165555 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -76,7 +76,10 @@ class Action(Thing): if 'end_time' in data and data['end_time'].replace(tzinfo=tzutc()) < unix_time: data['end_time'] = unix_time - if 'start_time' in data and data['start_time'].replace(tzinfo=tzutc()) < unix_time: + if ( + 'start_time' in data + and data['start_time'].replace(tzinfo=tzutc()) < unix_time + ): data['start_time'] = unix_time if data.get('end_time') and data.get('start_time'): diff --git a/tests/files/basic-stock.csv b/tests/files/basic-stock.csv index 18d3773d..7555ed23 100644 --- a/tests/files/basic-stock.csv +++ b/tests/files/basic-stock.csv @@ -1,2 +1,3 @@ Type;Chassis;Serial Number;Model;Manufacturer;Registered in;Physical state;Allocate state;Lifecycle state;Processor;RAM (MB);Data Storage Size (MB) -Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 11:11:28 2022;;;;p1ml;0;0 +Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0 +Desktop;Microtower;d1s;d1ml;d1mr;Wed Jul 20 13:20:26 2022;;;;p1ml;0;0 diff --git a/tests/test_device.py b/tests/test_device.py index 0e4c7eae..9f3b200d 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -347,7 +347,7 @@ 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) == 2 + assert len(db_pc.tags) == 1 for tag in db_pc.tags: assert tag.id in ['foo', db_pc.devicehub_id] @@ -501,7 +501,7 @@ def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserCl devices2, res2 = user2.get(url, None) assert res.status_code == 200 assert res2.status_code == 200 - assert len(devices['items']) == 1 + assert len(devices['items']) == 2 assert len(devices2['items']) == 0 @@ -515,13 +515,13 @@ def test_get_devices_unassigned(user: UserClient): devices, res = user.get(url, None) assert res.status_code == 200 - assert len(devices['items']) == 1 + assert len(devices['items']) == 2 url = '/devices/?filter={"type":["Computer"]}&unassign=1' devices, res = user.get(url, None) assert res.status_code == 200 - assert len(devices['items']) == 1 + assert len(devices['items']) == 2 from ereuse_devicehub.resources.lot.models import Lot device_id = devices['items'][0]['id'] @@ -537,13 +537,13 @@ def test_get_devices_unassigned(user: UserClient): devices, res = user.get(url, None) assert res.status_code == 200 - assert len(devices['items']) == 1 + assert len(devices['items']) == 2 url = '/devices/?filter={"type":["Computer"]}&unassign=1' devices, res = user.get(url, None) assert res.status_code == 200 - assert len(devices['items']) == 0 + assert len(devices['items']) == 1 @pytest.mark.mvp @@ -702,7 +702,7 @@ def test_hid_with_2networkadapters(app: Devicehub, user: UserClient): laptop = devices['items'][0] assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' - assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 + assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2 @pytest.mark.mvp @@ -723,7 +723,7 @@ def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClie devices, _ = user.get(res=d.Device) laptop = devices['items'][0] assert laptop['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d' - assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 1 + assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2 assert len([c for c in laptop['components'] if c['type'] == 'NetworkAdapter']) == 1 @@ -746,22 +746,21 @@ def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient) user.post(json_encode(snapshot), res=m.Snapshot) devices, _ = user.get(res=d.Device) laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] - assert len(laptops) == 2 - hids = [h['hid'] for h in laptops] + assert len(laptops) == 4 + hids = [laptops[0]['hid'], laptops[2]['hid']] proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d', 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'] assert all([h in proof_hid for h in hids]) # we drop all network cards snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abc' - snapshot['components'] = [c for c in snapshot['components'] if not c in [network, network2]] + snapshot['components'] = [c for c in snapshot['components'] if c not in [network, network2]] user.post(json_encode(snapshot), res=m.Snapshot) devices, _ = user.get(res=d.Device) laptops = [c for c in devices['items'] if c['type'] == 'Laptop'] - assert len(laptops) == 3 - hids = [h['hid'] for h in laptops] + assert len(laptops) == 4 + hids = [laptops[0]['hid'], laptops[2]['hid']] proof_hid = ['laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d', 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d', 'laptop-asustek_computer_inc-1000h-94oaaq021116'] assert all([h in proof_hid for h in hids]) - diff --git a/tests/test_device_find.py b/tests/test_device_find.py index 7d18a991..646a3bb0 100644 --- a/tests/test_device_find.py +++ b/tests/test_device_find.py @@ -183,7 +183,6 @@ def test_device_query(user: UserClient): pc = next(d for d in i['items'] if d['type'] == 'Desktop') assert len(pc['actions']) == 3 assert len(pc['components']) == 3 - assert pc['tags'][0]['id'] == pc['devicehubID'] @pytest.mark.mvp diff --git a/tests/test_documents.py b/tests/test_documents.py index 1a5cfedf..535d39ee 100644 --- a/tests/test_documents.py +++ b/tests/test_documents.py @@ -515,12 +515,14 @@ def test_report_devices_stock_control(user: UserClient, user2: UserClient): fixture_csv = list(obj_csv) assert user.user['id'] != user2.user['id'] - assert len(export_csv) == 2 + assert len(export_csv) == 3 export_csv[0] = export_csv[0][0].split(';') export_csv[1] = export_csv[1][0].split(';') + export_csv[2] = export_csv[2][0].split(';') fixture_csv[0] = fixture_csv[0][0].split(';') fixture_csv[1] = fixture_csv[1][0].split(';') + fixture_csv[2] = fixture_csv[2][0].split(';') assert isinstance( datetime.strptime(export_csv[1][5], '%c'), datetime @@ -529,9 +531,12 @@ def test_report_devices_stock_control(user: UserClient, user2: UserClient): # Pop dates fields from csv lists to compare them fixture_csv[1] = fixture_csv[1][:5] + fixture_csv[1][6:] export_csv[1] = export_csv[1][:5] + export_csv[1][6:] + fixture_csv[2] = fixture_csv[2][:5] + fixture_csv[2][6:] + export_csv[2] = export_csv[2][:5] + export_csv[2][6:] assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' + assert fixture_csv[2] == export_csv[2], 'Computer information are not equal' assert fixture_csv == export_csv diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 0fb5ab0b..3daa86d9 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -311,7 +311,7 @@ def test_label_details(user3: UserClientFlask): @pytest.mark.usefixtures(conftest.app_context.__name__) def test_link_tag_to_device(user3: UserClientFlask): snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json') - dev = snap.device + dev = snap.device.binding.device uri = '/labels/add/' user3.get(uri) @@ -332,7 +332,7 @@ def test_link_tag_to_device(user3: UserClientFlask): uri = '/inventory/tag/devices/add/' user3.post(uri, data=data) - assert len(list(dev.tags)) == 2 + assert len(list(dev.tags)) == 1 tags = [tag.id for tag in dev.tags] assert "tag1" in tags @@ -342,7 +342,7 @@ def test_link_tag_to_device(user3: UserClientFlask): def test_unlink_tag_to_device(user3: UserClientFlask): # create device snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json') - dev = snap.device + dev = snap.device.binding.device # create tag uri = '/labels/add/' @@ -380,9 +380,7 @@ def test_unlink_tag_to_device(user3: UserClientFlask): } user3.post(uri, data=data) - assert len(list(dev.tags)) == 1 - tag = list(dev.tags)[0] - assert not tag.id == "tag1" + assert len(list(dev.tags)) == 0 @pytest.mark.mvp @@ -390,7 +388,7 @@ def test_unlink_tag_to_device(user3: UserClientFlask): def test_print_labels(user3: UserClientFlask): # create device snap = create_device(user3, 'real-eee-1001pxd.snapshot.12.json') - dev = snap.device + dev = snap.device.binding.device # create tag uri = '/labels/add/' @@ -412,7 +410,7 @@ def test_print_labels(user3: UserClientFlask): uri = '/inventory/tag/devices/add/' user3.post(uri, data=data) - assert len(list(dev.tags)) == 2 + assert len(list(dev.tags)) == 1 uri = '/labels/print' data = { diff --git a/tests/test_tag.py b/tests/test_tag.py index 36dfb108..b30cf592 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -368,18 +368,18 @@ def test_tag_secondary_workbench_link_find(user: UserClient): desktop = Device.query.filter_by( devicehub_id=snapshot['device']['devicehubID'] ).one() - assert ['O48N2'] == [x['id'] for x in device['tags']] + assert [] == [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']) == 0 + assert len(r['items']) == 1 r, _ = user.get( res=Device, query=[('search', 'bar'), ('filter', {'type': ['Computer']})] ) - assert len(r['items']) == 0 + assert len(r['items']) == 1 @pytest.mark.mvp @@ -491,5 +491,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']) == 2 + assert len(computer['items']) == 1 assert len(computer2['items']) == 0 diff --git a/tests/test_workbench.py b/tests/test_workbench.py index f787e502..e7ea80b8 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -179,7 +179,6 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): """Checks the values of the device, components, actions and their relationships of a real pc. """ - # import pdb; pdb.set_trace() s = file('real-eee-1001pxd.snapshot.11') snapshot, _ = user.post(res=em.Snapshot, data=s) pc, _ = user.get(res=Device, item=snapshot['device']['devicehubID']) @@ -192,7 +191,7 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286-14:da:e9:42:f6:7c' ) - assert len(pc['tags']) == 1 + assert len(pc['tags']) == 0 assert pc['networkSpeeds'] == [ 100, 0,