From ce0aedd0d2f97a98b11a684201afa3feeef699aa Mon Sep 17 00:00:00 2001 From: nad Date: Wed, 15 Jul 2020 11:58:38 +0200 Subject: [PATCH 01/21] Fixing test_snapshot::test_snapshot_component_add_remove --- tests/test_snapshot.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 3025a762..1cb3cd18 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -99,7 +99,6 @@ def test_snapshot_post(user: UserClient): @pytest.mark.mvp -@pytest.mark.xfail(reason='Needs to fix it') def test_snapshot_component_add_remove(user: UserClient): """Tests adding and removing components and some don't generate HID. All computers generate HID. @@ -120,7 +119,8 @@ def test_snapshot_component_add_remove(user: UserClient): s1 = file('1-device-with-components.snapshot') snapshot1 = snapshot_and_check(user, s1, - action_types=(BenchmarkProcessor.t,), + action_types=(BenchmarkProcessor.t, + RateComputer.t), perform_second_snapshot=False) pc1_id = snapshot1['device']['id'] pc1, _ = user.get(res=m.Device, item=pc1_id) @@ -128,12 +128,12 @@ def test_snapshot_component_add_remove(user: UserClient): assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c2s', 'p1c3s') # Components contain parent assert all(c['parent'] == pc1_id for c in pc1['components']) - # pc has two actions: Snapshot and the BenchmarkProcessor - assert len(pc1['actions']) == 2 + # pc has three actions: Snapshot, BenchmarkProcessor and RateComputer + assert len(pc1['actions']) == 3 assert pc1['actions'][1]['type'] == Snapshot.t # p1c1s has Snapshot p1c1s, _ = user.get(res=m.Device, item=pc1['components'][0]['id']) - assert tuple(e['type'] for e in p1c1s['actions']) == ('Snapshot',) + assert tuple(e['type'] for e in p1c1s['actions']) == ('Snapshot', 'RateComputer') # We register a new device # It has the processor of the first one (p1c2s) @@ -141,7 +141,7 @@ def test_snapshot_component_add_remove(user: UserClient): # Actions PC1: Snapshot, Remove. PC2: Snapshot s2 = file('2-second-device-with-components-of-first.snapshot') # num_actions = 2 = Remove, Add - snapshot2 = snapshot_and_check(user, s2, action_types=('Remove',), + snapshot2 = snapshot_and_check(user, s2, action_types=('Remove', 'RateComputer'), perform_second_snapshot=False) pc2_id = snapshot2['device']['id'] pc1, _ = user.get(res=m.Device, item=pc1_id) @@ -149,15 +149,15 @@ def test_snapshot_component_add_remove(user: UserClient): # PC1 assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c3s') assert all(c['parent'] == pc1_id for c in pc1['components']) - assert tuple(e['type'] for e in pc1['actions']) == ('BenchmarkProcessor', 'Snapshot', 'Remove') + assert tuple(e['type'] for e in pc1['actions']) == ('BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Remove') # PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p1c2s', 'p2c1s') assert all(c['parent'] == pc2_id for c in pc2['components']) - assert tuple(e['type'] for e in pc2['actions']) == ('Snapshot',) + assert tuple(e['type'] for e in pc2['actions']) == ('Snapshot', 'RateComputer') # p1c2s has two Snapshots, a Remove and an Add p1c2s, _ = user.get(res=m.Device, item=pc2['components'][0]['id']) assert tuple(e['type'] for e in p1c2s['actions']) == ( - 'BenchmarkProcessor', 'Snapshot', 'Snapshot', 'Remove' + 'BenchmarkProcessor', 'Snapshot', 'RateComputer', 'Snapshot', 'Remove', 'RateComputer' ) # We register the first device again, but removing motherboard @@ -165,7 +165,7 @@ def test_snapshot_component_add_remove(user: UserClient): # We have created 1 Remove (from PC2's processor back to PC1) # PC 0: p1c2s, p1c3s. PC 1: p2c1s s3 = file('3-first-device-but-removing-motherboard-and-adding-processor-from-2.snapshot') - snapshot_and_check(user, s3, ('Remove',), perform_second_snapshot=False) + snapshot_and_check(user, s3, ('Remove', 'RateComputer'), perform_second_snapshot=False) pc1, _ = user.get(res=m.Device, item=pc1_id) pc2, _ = user.get(res=m.Device, item=pc2_id) # PC1 @@ -175,14 +175,17 @@ def test_snapshot_component_add_remove(user: UserClient): # id, type, components, snapshot ('BenchmarkProcessor', []), # first BenchmarkProcessor ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), # first Snapshot1 + ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), ('Remove', ['p1c2s']), # Remove Processor in Snapshot2 - ('Snapshot', ['p1c2s', 'p1c3s']) # This Snapshot3 + ('Snapshot', ['p1c2s', 'p1c3s']), # This Snapshot3 + ('RateComputer', ['p1c2s', 'p1c3s']) ) # PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p2c1s',) assert all(c['parent'] == pc2_id for c in pc2['components']) assert tuple(e['type'] for e in pc2['actions']) == ( 'Snapshot', # Second Snapshot + 'RateComputer', 'Remove' # the processor we added in 2. ) # p1c2s has Snapshot, Remove and Add @@ -190,23 +193,26 @@ def test_snapshot_component_add_remove(user: UserClient): assert tuple(get_actions_info(p1c2s['actions'])) == ( ('BenchmarkProcessor', []), # first BenchmarkProcessor ('Snapshot', ['p1c1s', 'p1c2s', 'p1c3s']), # First Snapshot to PC1 + ('RateComputer', ['p1c1s', 'p1c2s', 'p1c3s']), ('Snapshot', ['p1c2s', 'p2c1s']), # Second Snapshot to PC2 ('Remove', ['p1c2s']), # ...which caused p1c2s to be removed form PC1 + ('RateComputer', ['p1c2s', 'p2c1s']), ('Snapshot', ['p1c2s', 'p1c3s']), # The third Snapshot to PC1 - ('Remove', ['p1c2s']) # ...which caused p1c2 to be removed from PC2 + ('Remove', ['p1c2s']), # ...which caused p1c2 to be removed from PC2 + ('RateComputer', ['p1c2s', 'p1c3s']) ) # We register the first device but without the processor, # adding a graphic card and adding a new component s4 = file('4-first-device-but-removing-processor.snapshot-and-adding-graphic-card') - snapshot_and_check(user, s4, perform_second_snapshot=False) + snapshot_and_check(user, s4, ('RateComputer',), perform_second_snapshot=False) pc1, _ = user.get(res=m.Device, item=pc1_id) pc2, _ = user.get(res=m.Device, item=pc2_id) # PC 0: p1c3s, p1c4s. PC1: p2c1s assert {c['serialNumber'] for c in pc1['components']} == {'p1c3s', 'p1c4s'} assert all(c['parent'] == pc1_id for c in pc1['components']) - # This last Snapshot only - assert get_actions_info(pc1['actions'])[-1] == ('Snapshot', ['p1c3s', 'p1c4s']) + # This last Action only + assert get_actions_info(pc1['actions'])[-1] == ('RateComputer', ['p1c3s', 'p1c4s']) # PC2 # We haven't changed PC2 assert tuple(c['serialNumber'] for c in pc2['components']) == ('p2c1s',) From 02040199bb19806d017602e2aac111ef80427fc9 Mon Sep 17 00:00:00 2001 From: nad Date: Wed, 15 Jul 2020 13:11:50 +0200 Subject: [PATCH 02/21] Fixing test_basic.py::test_api_docs and test_workbench.py::test_real_custom --- tests/test_basic.py | 78 ++++++++++++++++++++++++++++++++++------- tests/test_workbench.py | 4 +-- 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/tests/test_basic.py b/tests/test_basic.py index ca2f2e05..ce941d87 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -28,24 +28,76 @@ def test_api_docs(client: Client): """Tests /apidocs correct initialization.""" docs, _ = client.get('/apidocs') assert set(docs['paths'].keys()) == { - # todo this does not appear: '/tags/{id}/device', - '/apidocs', - '/users/', - '/devices/', - '/tags/', - '/users/login/', '/actions/', + '/apidocs', + '/batteries/{id}/merge/', + '/bikes/{id}/merge/', + '/cameras/{id}/merge/', + '/cellphones/{id}/merge/', + '/components/{id}/merge/', + '/computer-accessories/{id}/merge/', + '/computer-monitors/{id}/merge/', + '/computers/{id}/merge/', + '/cookings/{id}/merge/', + '/data-storages/{id}/merge/', + '/dehumidifiers/{id}/merge/', + '/deliverynotes/', + '/desktops/{id}/merge/', + '/devices/', + '/devices/static/{filename}', + '/devices/{id}/merge/', + '/displays/{id}/merge/', + '/diy-and-gardenings/{id}/merge/', + '/documents/devices/', + '/documents/erasures/', + '/documents/static/{filename}', + '/drills/{id}/merge/', + '/graphic-cards/{id}/merge/', + '/hard-drives/{id}/merge/', + '/homes/{id}/merge/', + '/hubs/{id}/merge/', + '/keyboards/{id}/merge/', + '/label-printers/{id}/merge/', + '/laptops/{id}/merge/', '/lots/', - '/manufacturers/', '/lots/{id}/children', '/lots/{id}/devices', - '/documents/erasures/', - '/documents/devices/', - '/documents/static/{filename}', + '/manufacturers/', + '/memory-card-readers/{id}/merge/', + '/mice/{id}/merge/', + '/microphones/{id}/merge/', + '/mixers/{id}/merge/', + '/mobiles/{id}/merge/', + '/monitors/{id}/merge/', + '/motherboards/{id}/merge/', + '/network-adapters/{id}/merge/', + '/networkings/{id}/merge/', + '/pack-of-screwdrivers/{id}/merge/', + '/printers/{id}/merge/', + '/processors/{id}/merge/', + '/proofs/', + '/rackets/{id}/merge/', + '/ram-modules/{id}/merge/', + '/recreations/{id}/merge/', + '/routers/{id}/merge/', + '/sais/{id}/merge/', + '/servers/{id}/merge/', + '/smartphones/{id}/merge/', + '/solid-state-drives/{id}/merge/', + '/sound-cards/{id}/merge/', + '/sounds/{id}/merge/', + '/stairs/{id}/merge/', + '/switches/{id}/merge/', + '/tablets/{id}/merge/', + '/tags/', '/tags/{tag_id}/device/{device_id}', - '/devices/static/{filename}', - '/deliverynotes/', - '/proofs/' + '/television-sets/{id}/merge/', + '/users/', + '/users/login/', + '/video-scalers/{id}/merge/', + '/videoconferences/{id}/merge/', + '/videos/{id}/merge/', + '/wireless-access-points/{id}/merge/' } assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'} assert docs['components']['securitySchemes']['bearerAuth'] == { diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 82992048..1bc3d1ba 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -66,7 +66,6 @@ def test_workbench_server_condensed(user: UserClient): assert device['tags'][0]['id'] == 'tag1' -@pytest.mark.mvp @pytest.mark.xfail(reason='Functionality not yet developed.') def test_workbench_server_phases(user: UserClient): """Tests the phases described in the docs section `Snapshots from @@ -274,7 +273,7 @@ def test_snapshot_real_eee_1001pxd_with_rate(user: UserClient): @pytest.mark.mvp def test_real_custom(user: UserClient): s = file('real-custom.snapshot.11') - snapshot, _ = user.post(res=em.Snapshot, data=s, status=NeedsId) + snapshot, _ = user.post(res=em.Snapshot, data=s, status=201) # todo insert with tag @@ -303,6 +302,7 @@ SNAPSHOTS_NEED_ID = { @pytest.mark.xfail(reason='It needs to be fixed.') +@pytest.mark.mvp @pytest.mark.parametrize('file', (pytest.param(f, id=f.name) for f in pathlib.Path(__file__).parent.joinpath('workbench_files').iterdir()) From e3abc1d284657f33b4c78c73f2b19167d2244f6b Mon Sep 17 00:00:00 2001 From: nad Date: Mon, 20 Jul 2020 12:45:41 +0200 Subject: [PATCH 03/21] Fixing test_workbench.py::test_workbench_fixtures --- tests/test_workbench.py | 3 +- tests/workbench_files/1000h.snapshot.json | 17 +++++++-- tests/workbench_files/1001pxd.snapshot.json | 17 +++++++-- tests/workbench_files/415522G.snapshot.json | 26 ++++++++++++-- tests/workbench_files/7220w3t.snapshot.json | 17 +++++++-- tests/workbench_files/7900.snapshot.json | 35 ++++++++++++++++--- tests/workbench_files/8100.snapshot.json | 17 +++++++-- tests/workbench_files/TM1613.snapshot.json | 8 ++++- .../acer-aspire-5737z.snapshot.json | 17 +++++++-- .../workbench_files/all-series.snapshot.json | 17 +++++++-- .../asus-all-series.snapshot.json | 17 +++++++-- .../workbench_files/boxnuc6cayh.snapshot.json | 17 +++++++-- tests/workbench_files/core2.snapshot.json | 17 +++++++-- tests/workbench_files/custom.snapshot.json | 17 +++++++-- tests/workbench_files/david.snapshot.json | 17 +++++++-- tests/workbench_files/e5530.snapshot.json | 17 +++++++-- tests/workbench_files/ecs-2.snapshot.json | 17 +++++++-- .../ecs-computers.snapshot.json | 17 +++++++-- .../hp-pavilion-dv4000.snapshot.json | 17 +++++++-- .../lenovo-as-intel.snapshot.json | 17 +++++++-- .../lenovo-thinkcentre-edge.snapshot.json | 17 +++++++-- tests/workbench_files/nec.snapshot.json | 17 +++++++-- tests/workbench_files/nox.snapshot.json | 17 +++++++-- .../optiplex-745.snapshot.json | 17 +++++++-- .../optiplex-gx520.snapshot.json | 17 +++++++-- .../test_isard_probook.snapshot.json | 17 +++++++-- .../test_pc_hpCompaq8100.snapshot.json | 17 +++++++-- tests/workbench_files/toshiba.snapshot.json | 17 +++++++-- .../virtualbox-client.snapshot.json | 11 ++++-- .../workbench_files/vostro-260.snapshot.json | 17 +++++++-- 30 files changed, 446 insertions(+), 62 deletions(-) diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 1bc3d1ba..3620e951 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -301,7 +301,6 @@ SNAPSHOTS_NEED_ID = { """Snapshots that do not generate HID requiring a custom ID.""" -@pytest.mark.xfail(reason='It needs to be fixed.') @pytest.mark.mvp @pytest.mark.parametrize('file', (pytest.param(f, id=f.name) @@ -315,7 +314,7 @@ def test_workbench_fixtures(file: pathlib.Path, user: UserClient): s = json.load(file.open()) user.post(res=em.Snapshot, data=s, - status=201 if file.name not in SNAPSHOTS_NEED_ID else NeedsId) + status=201) @pytest.mark.mvp diff --git a/tests/workbench_files/1000h.snapshot.json b/tests/workbench_files/1000h.snapshot.json index fb294466..50dcdf96 100644 --- a/tests/workbench_files/1000h.snapshot.json +++ b/tests/workbench_files/1000h.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Atom CPU N270 @ 1.60GHz", @@ -40,7 +46,14 @@ "interface": "SDRAM" }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "TS32GSSD370S", diff --git a/tests/workbench_files/1001pxd.snapshot.json b/tests/workbench_files/1001pxd.snapshot.json index 6ac9c759..164e6eb4 100644 --- a/tests/workbench_files/1001pxd.snapshot.json +++ b/tests/workbench_files/1001pxd.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Atom CPU N455 @ 1.66GHz", @@ -42,7 +48,14 @@ "speed": 667.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Hitachi", "model": "HTS54322", diff --git a/tests/workbench_files/415522G.snapshot.json b/tests/workbench_files/415522G.snapshot.json index fa1b7de4..6f9723a0 100644 --- a/tests/workbench_files/415522G.snapshot.json +++ b/tests/workbench_files/415522G.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Xeon CPU E5520 @ 2.27GHz", @@ -97,7 +103,14 @@ "speed": 1066.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WDS120G1G0A-", @@ -107,7 +120,14 @@ "variant": "1000" }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST160LM000 HM161", diff --git a/tests/workbench_files/7220w3t.snapshot.json b/tests/workbench_files/7220w3t.snapshot.json index e09b0eda..b21f6675 100644 --- a/tests/workbench_files/7220w3t.snapshot.json +++ b/tests/workbench_files/7220w3t.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 Duo CPU E8400 @ 3.00GHz", @@ -53,7 +59,14 @@ "speed": 1067.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST3250318AS", diff --git a/tests/workbench_files/7900.snapshot.json b/tests/workbench_files/7900.snapshot.json index eef73f17..429193f1 100644 --- a/tests/workbench_files/7900.snapshot.json +++ b/tests/workbench_files/7900.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 Duo CPU E8400 @ 3.00GHz", @@ -42,7 +48,14 @@ "speed": 800.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST3160815AS", @@ -52,7 +65,14 @@ "variant": "H" }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD3200AAJS-0", @@ -62,7 +82,14 @@ "variant": "1B02" }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000AAKX-6", diff --git a/tests/workbench_files/8100.snapshot.json b/tests/workbench_files/8100.snapshot.json index b3693b69..0aee9c07 100644 --- a/tests/workbench_files/8100.snapshot.json +++ b/tests/workbench_files/8100.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i3 CPU 530 @ 2.93GHz", @@ -75,7 +81,14 @@ "speed": 1333.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD3200AAJS-6", diff --git a/tests/workbench_files/TM1613.snapshot.json b/tests/workbench_files/TM1613.snapshot.json index 38da1b6d..9f72ddc2 100644 --- a/tests/workbench_files/TM1613.snapshot.json +++ b/tests/workbench_files/TM1613.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-6200U CPU @ 2.30GHz", diff --git a/tests/workbench_files/acer-aspire-5737z.snapshot.json b/tests/workbench_files/acer-aspire-5737z.snapshot.json index 19fca7ba..17f78ab9 100644 --- a/tests/workbench_files/acer-aspire-5737z.snapshot.json +++ b/tests/workbench_files/acer-aspire-5737z.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 Duo CPU T6400 @ 2.00GHz", @@ -31,7 +37,14 @@ "generation": null }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000BEVT-2", diff --git a/tests/workbench_files/all-series.snapshot.json b/tests/workbench_files/all-series.snapshot.json index 0c7bfc6a..1259c4e3 100644 --- a/tests/workbench_files/all-series.snapshot.json +++ b/tests/workbench_files/all-series.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-4440 CPU @ 3.10GHz", @@ -42,7 +48,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000AAKX-0", diff --git a/tests/workbench_files/asus-all-series.snapshot.json b/tests/workbench_files/asus-all-series.snapshot.json index 46a22684..e2fa7c11 100644 --- a/tests/workbench_files/asus-all-series.snapshot.json +++ b/tests/workbench_files/asus-all-series.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-4440 CPU @ 3.10GHz", @@ -42,7 +48,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000AAKX-0", diff --git a/tests/workbench_files/boxnuc6cayh.snapshot.json b/tests/workbench_files/boxnuc6cayh.snapshot.json index b8185b6a..a75fa62f 100644 --- a/tests/workbench_files/boxnuc6cayh.snapshot.json +++ b/tests/workbench_files/boxnuc6cayh.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Celeron CPU J3455 @ 1.50GHz", @@ -42,7 +48,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "KINGSTON SA400S3", diff --git a/tests/workbench_files/core2.snapshot.json b/tests/workbench_files/core2.snapshot.json index 38645e41..9bf2979c 100644 --- a/tests/workbench_files/core2.snapshot.json +++ b/tests/workbench_files/core2.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 CPU 6600 @ 2.40GHz", @@ -41,7 +47,14 @@ "speed": 667.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "SAMSUNG HD250HJ", diff --git a/tests/workbench_files/custom.snapshot.json b/tests/workbench_files/custom.snapshot.json index 5aac0e65..bd90ca18 100644 --- a/tests/workbench_files/custom.snapshot.json +++ b/tests/workbench_files/custom.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-4440 CPU @ 3.10GHz", @@ -42,7 +48,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000AAKX-0", diff --git a/tests/workbench_files/david.snapshot.json b/tests/workbench_files/david.snapshot.json index c5eab227..c68eeb33 100644 --- a/tests/workbench_files/david.snapshot.json +++ b/tests/workbench_files/david.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i7-4600M CPU @ 2.90GHz", @@ -53,7 +59,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "Crucial_CT525MX3", diff --git a/tests/workbench_files/e5530.snapshot.json b/tests/workbench_files/e5530.snapshot.json index a95e7664..7eb81b96 100644 --- a/tests/workbench_files/e5530.snapshot.json +++ b/tests/workbench_files/e5530.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-3340M CPU @ 2.70GHz", @@ -53,7 +59,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "HGST HTS725050A7", diff --git a/tests/workbench_files/ecs-2.snapshot.json b/tests/workbench_files/ecs-2.snapshot.json index 3eae707c..ae6e9275 100644 --- a/tests/workbench_files/ecs-2.snapshot.json +++ b/tests/workbench_files/ecs-2.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 CPU 6600 @ 2.40GHz", @@ -63,7 +69,14 @@ "speed": 533.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "SAMSUNG HD250HJ", diff --git a/tests/workbench_files/ecs-computers.snapshot.json b/tests/workbench_files/ecs-computers.snapshot.json index 4d39dfef..6f860aff 100644 --- a/tests/workbench_files/ecs-computers.snapshot.json +++ b/tests/workbench_files/ecs-computers.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-4440 CPU @ 3.10GHz", @@ -42,7 +48,14 @@ "speed": 1600.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD5000AAKX-6", diff --git a/tests/workbench_files/hp-pavilion-dv4000.snapshot.json b/tests/workbench_files/hp-pavilion-dv4000.snapshot.json index 03fc54a9..41327d49 100644 --- a/tests/workbench_files/hp-pavilion-dv4000.snapshot.json +++ b/tests/workbench_files/hp-pavilion-dv4000.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Pentium M processor 1.60GHz", @@ -50,7 +56,14 @@ "interface": "DDR" }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Fujitsu", "model": "MHT2080A", diff --git a/tests/workbench_files/lenovo-as-intel.snapshot.json b/tests/workbench_files/lenovo-as-intel.snapshot.json index 97c1e27a..aded176f 100644 --- a/tests/workbench_files/lenovo-as-intel.snapshot.json +++ b/tests/workbench_files/lenovo-as-intel.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 Duo CPU E8400 @ 3.00GHz", @@ -53,7 +59,14 @@ "speed": 1067.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "SAMSUNG HD251HJ", diff --git a/tests/workbench_files/lenovo-thinkcentre-edge.snapshot.json b/tests/workbench_files/lenovo-thinkcentre-edge.snapshot.json index fb91a51d..5cf959f9 100644 --- a/tests/workbench_files/lenovo-thinkcentre-edge.snapshot.json +++ b/tests/workbench_files/lenovo-thinkcentre-edge.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Pentium CPU G645 @ 2.90GHz", @@ -42,7 +48,14 @@ "speed": 1333.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST250DM000-1BD14", diff --git a/tests/workbench_files/nec.snapshot.json b/tests/workbench_files/nec.snapshot.json index 7d90dc22..dbb901e9 100644 --- a/tests/workbench_files/nec.snapshot.json +++ b/tests/workbench_files/nec.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 Duo CPU E8400 @ 3.00GHz", @@ -53,7 +59,14 @@ "speed": 667.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Hitachi", "model": "HDT72103", diff --git a/tests/workbench_files/nox.snapshot.json b/tests/workbench_files/nox.snapshot.json index 72cbdeda..f378ff48 100644 --- a/tests/workbench_files/nox.snapshot.json +++ b/tests/workbench_files/nox.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i3-2100 CPU @ 3.10GHz", @@ -42,7 +48,14 @@ "speed": 1333.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST3500413AS", diff --git a/tests/workbench_files/optiplex-745.snapshot.json b/tests/workbench_files/optiplex-745.snapshot.json index cf4fd2a2..719ceda9 100644 --- a/tests/workbench_files/optiplex-745.snapshot.json +++ b/tests/workbench_files/optiplex-745.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core2 CPU 6400 @ 2.13GHz", @@ -53,7 +59,14 @@ "speed": 667.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Western Digital", "model": "WDC WD3200AAKS-7", diff --git a/tests/workbench_files/optiplex-gx520.snapshot.json b/tests/workbench_files/optiplex-gx520.snapshot.json index 96bab982..3fffeccf 100644 --- a/tests/workbench_files/optiplex-gx520.snapshot.json +++ b/tests/workbench_files/optiplex-gx520.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Pentium 4 CPU 3.00GHz", @@ -52,7 +58,14 @@ "speed": 533.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST3808110AS", diff --git a/tests/workbench_files/test_isard_probook.snapshot.json b/tests/workbench_files/test_isard_probook.snapshot.json index 674682b2..1d537044 100644 --- a/tests/workbench_files/test_isard_probook.snapshot.json +++ b/tests/workbench_files/test_isard_probook.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5-7200U CPU @ 2.50GHz", @@ -42,7 +48,14 @@ "speed": 2133.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "SAMSUNG MZNTY256", diff --git a/tests/workbench_files/test_pc_hpCompaq8100.snapshot.json b/tests/workbench_files/test_pc_hpCompaq8100.snapshot.json index c811a590..4d66cc4d 100644 --- a/tests/workbench_files/test_pc_hpCompaq8100.snapshot.json +++ b/tests/workbench_files/test_pc_hpCompaq8100.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i3 CPU 530 @ 2.93GHz", @@ -75,7 +81,14 @@ "speed": 1333.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "KINGSTON SA400S3", diff --git a/tests/workbench_files/toshiba.snapshot.json b/tests/workbench_files/toshiba.snapshot.json index 67ad1f10..eb889309 100644 --- a/tests/workbench_files/toshiba.snapshot.json +++ b/tests/workbench_files/toshiba.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i5 CPU M 560 @ 2.67GHz", @@ -41,7 +47,14 @@ "speed": 1067.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Hitachi", "model": "HTS54505", diff --git a/tests/workbench_files/virtualbox-client.snapshot.json b/tests/workbench_files/virtualbox-client.snapshot.json index 1d559b09..b3b8dcf9 100644 --- a/tests/workbench_files/virtualbox-client.snapshot.json +++ b/tests/workbench_files/virtualbox-client.snapshot.json @@ -8,7 +8,7 @@ "elapsed": 0, "device": { "actions": [], - "type": "Computer", + "type": "Desktop", "manufacturer": "innotek GmbH", "model": "VirtualBox", "serialNumber": "0", @@ -18,7 +18,14 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 126.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": null, "model": "VBOX HARDDISK", diff --git a/tests/workbench_files/vostro-260.snapshot.json b/tests/workbench_files/vostro-260.snapshot.json index 2a8bd7b8..cdb6d906 100644 --- a/tests/workbench_files/vostro-260.snapshot.json +++ b/tests/workbench_files/vostro-260.snapshot.json @@ -18,7 +18,13 @@ }, "components": [ { - "actions": [], + "actions": [ + { + "type": "BenchmarkProcessor", + "rate": 11969.98, + "elapsed": 0 + } + ], "type": "Processor", "manufacturer": "Intel Corp.", "model": "Intel Core i3-2120 CPU @ 3.30GHz", @@ -53,7 +59,14 @@ "speed": 1333.0 }, { - "actions": [], + "actions": [ + { + "elapsed": 13, + "readSpeed": 106.0, + "writeSpeed": 26.6, + "type": "BenchmarkDataStorage" + } + ], "type": "HardDrive", "manufacturer": "Seagate", "model": "ST500DM002-1BD14", From 546dfd80bea16e7d6e0b033b565754d8b4d6a40f Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 20 Jul 2020 20:21:44 +0200 Subject: [PATCH 04/21] bugfix/test_erase_privacy_standards_endtime_sort --- tests/test_snapshot.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 1cb3cd18..3e63dbf6 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -12,7 +12,8 @@ from ereuse_devicehub.client import UserClient from ereuse_devicehub.db import db from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \ - BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest + BenchmarkProcessor, EraseSectors, RateComputer, Snapshot, SnapshotRequest, VisualTest, \ + EreusePrice from ereuse_devicehub.resources.device import models as m from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.models import SolidStateDrive @@ -342,7 +343,6 @@ def test_snapshot_component_containing_components(user: UserClient): @pytest.mark.mvp -@pytest.mark.xfail(reason='It needs to be fixed.') def test_erase_privacy_standards_endtime_sort(user: UserClient): """Tests a Snapshot with EraseSectors and the resulting privacy properties. @@ -355,7 +355,9 @@ def test_erase_privacy_standards_endtime_sort(user: UserClient): snapshot = snapshot_and_check(user, s, action_types=( EraseSectors.t, BenchmarkDataStorage.t, - BenchmarkProcessor.t + BenchmarkProcessor.t, + RateComputer.t, + EreusePrice.t ), perform_second_snapshot=False) # Perform a new snapshot changing the erasure time, as if # it is a new erasure performed after. @@ -366,7 +368,9 @@ def test_erase_privacy_standards_endtime_sort(user: UserClient): snapshot = snapshot_and_check(user, s, action_types=( EraseSectors.t, BenchmarkDataStorage.t, - BenchmarkProcessor.t + BenchmarkProcessor.t, + RateComputer.t, + EreusePrice.t ), perform_second_snapshot=False) # The actual test @@ -374,7 +378,7 @@ def test_erase_privacy_standards_endtime_sort(user: UserClient): storage, _ = user.get(res=m.Device, item=storage['id']) # Let's get storage actions too # order: endTime ascending # erasure1/2 have an user defined time and others actions endTime = created - erasure1, erasure2, benchmark_hdd1, _snapshot1, benchmark_hdd2, _snapshot2 = storage['actions'] + erasure1, erasure2, benchmark_hdd1, _snapshot1, _, _, benchmark_hdd2, _snapshot2 = storage['actions'][:8] assert erasure1['type'] == erasure2['type'] == 'EraseSectors' assert benchmark_hdd1['type'] == benchmark_hdd2['type'] == 'BenchmarkDataStorage' assert _snapshot1['type'] == _snapshot2['type'] == 'Snapshot' From c10ebc3a0567369a3e0ce12787978b4fe9a4d173 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Tue, 21 Jul 2020 13:02:29 +0200 Subject: [PATCH 05/21] Use virtualenv to isolate from VM changes e.g. update of 20200709 breaks dependencies with PyYAML because new package aws-sam-cli has ben added https://github.com/actions/virtual-environments/commit/487c88b726392dda3077c6938c688a9601486763 --- .github/workflows/flask.yml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index ef4b0810..615efabf 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -1,11 +1,11 @@ -name: Django CI +name: Flask CI on: push: branches: [master, testing] pull_request: branches: [master, testing] - + jobs: build: runs-on: ubuntu-latest @@ -46,6 +46,9 @@ jobs: sudo apt-get update -qy sudo apt-get -y install postgresql-client python -m pip install --upgrade pip + pip install virtualenv + virtualenv env + source env/bin/activate pip install flake8 pytest pip install -r requirements.txt @@ -63,5 +66,6 @@ jobs: - name: Run Tests run: | + source env/bin/activate pytest -m mvp --maxfail=5 tests/ From a005d6f597e13f1051bc7bf705f4ad9e871e419a Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 12:11:21 +0200 Subject: [PATCH 06/21] bugfix test_get_devices --- tests/test_device.py | 14 ++++++++------ tests/test_lot.py | 6 +++--- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 2f84c75d..85e15747 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -391,14 +391,14 @@ def test_sync_execute_register_mismatch_between_tags_and_hid(): @pytest.mark.mvp -@pytest.mark.xfail(reason='It needs to be fixed.') def test_get_device(app: Devicehub, user: UserClient): """Checks GETting a d.Desktop with its components.""" with app.app_context(): pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', - chassis=ComputerChassis.Tower) + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) pc.components = OrderedSet([ d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'), d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500) @@ -428,14 +428,14 @@ def test_get_device(app: Devicehub, user: UserClient): @pytest.mark.mvp -@pytest.mark.xfail(reason='It needs to be fixed.') def test_get_devices(app: Devicehub, user: UserClient): """Checks GETting multiple devices.""" with app.app_context(): pc = d.Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s', - chassis=ComputerChassis.Tower) + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) pc.components = OrderedSet([ d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'), d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500) @@ -443,11 +443,13 @@ def test_get_devices(app: Devicehub, user: UserClient): pc1 = d.Desktop(model='p2mo', manufacturer='p2ma', serial_number='p2s', - chassis=ComputerChassis.Tower) + chassis=ComputerChassis.Tower, + owner_id=user.user['id']) pc2 = d.Laptop(model='p3mo', manufacturer='p3ma', serial_number='p3s', - chassis=ComputerChassis.Netbook) + chassis=ComputerChassis.Netbook, + owner_id=user.user['id']) db.session.add_all((pc, pc1, pc2)) db.session.commit() devices, _ = user.get(res=d.Device) diff --git a/tests/test_lot.py b/tests/test_lot.py index c1473496..d6df96ef 100644 --- a/tests/test_lot.py +++ b/tests/test_lot.py @@ -13,7 +13,7 @@ from tests import conftest try: with db.session.begin_nested(): - + except Exception as e: db.session.commit() print(e) @@ -351,7 +351,6 @@ def test_lot_post_add_children_view_ui_tree_normal(user: UserClient): @pytest.mark.mvp -@pytest.mark.xfail(reason='It needs to be fixed.') def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): """Tests adding a device to a lot using POST and removing it with DELETE. @@ -361,7 +360,8 @@ def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient): device = Desktop(serial_number='foo', model='bar', manufacturer='foobar', - chassis=ComputerChassis.Lunchbox) + chassis=ComputerChassis.Lunchbox, + owner_id=user.user['id']) db.session.add(device) db.session.commit() device_id = device.id From d72820474154f0cb50982681621b1de09e94e3cd Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 14:21:38 +0200 Subject: [PATCH 07/21] bugfix: adding user when Tag is create --- tests/test_tag.py | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/tests/test_tag.py b/tests/test_tag.py index 219727d6..7b627ad3 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -24,10 +24,10 @@ from tests.conftest import file @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_create_tag(): +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')) + 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() @@ -37,9 +37,9 @@ def test_create_tag(): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_create_tag_default_org(): +def test_create_tag_default_org(user: UserClient): """Creates a tag using the default organization.""" - tag = Tag(id='foo-1') + 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' # We don't want the organization to load, or it would make this # object, from transient to new (added to session) @@ -62,17 +62,18 @@ def test_create_tag_no_slash(): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_create_two_same_tags(): +def test_create_two_same_tags(user: UserClient): """Ensures there cannot be two tags with the same ID and organization.""" - db.session.add(Tag(id='foo-bar')) - db.session.add(Tag(id='foo-bar')) + + db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) + db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) with raises(UniqueViolation): db.session.commit() db.session.rollback() # And it works if tags are in different organizations - db.session.add(Tag(id='foo-bar')) + db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) org2 = Organization(name='org 2', tax_id='tax id org 2') - db.session.add(Tag(id='foo-bar', org=org2)) + db.session.add(Tag(id='foo-bar', org=org2, owner_id=user.user['id'])) db.session.commit() @@ -104,7 +105,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 - tag = Tag(id='foo-bar') + 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) db.session.add(pc) @@ -117,7 +118,7 @@ def test_tag_get_device_from_tag_endpoint(app: Devicehub, user: UserClient): def test_tag_get_device_from_tag_endpoint_no_linked(app: Devicehub, user: UserClient): """As above, but when the tag is not linked.""" with app.app_context(): - db.session.add(Tag(id='foo-bar')) + db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) db.session.commit() user.get(res=Tag, item='foo-bar/device', status=TagNotLinked) @@ -135,9 +136,9 @@ def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: Us it should raise an exception. """ with app.app_context(): - db.session.add(Tag(id='foo-bar')) + db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) org2 = Organization(name='org 2', tax_id='tax id org 2') - db.session.add(Tag(id='foo-bar', org=org2)) + db.session.add(Tag(id='foo-bar', org=org2, owner_id=user.user['id'])) db.session.commit() user.get(res=Tag, item='foo-bar/device', status=MultipleResourcesFound) @@ -173,7 +174,7 @@ def test_tag_manual_link_search(app: Devicehub, user: UserClient): Checks search has the term. """ with app.app_context(): - db.session.add(Tag('foo-bar', secondary='foo-sec')) + 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) db.session.commit() @@ -277,7 +278,7 @@ def test_get_tags_endpoint(user: UserClient, app: Devicehub, # 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')) + 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 From 3179bba9e9a8818d6b92e405c29f56b585120605 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 14:22:42 +0200 Subject: [PATCH 08/21] bugfix add owner_id when device is create --- tests/test_device.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 85e15747..83b4ecbc 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -256,12 +256,14 @@ def test_sync_execute_register_desktop_existing_no_tag(): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_sync_execute_register_desktop_no_hid_no_tag(): +def test_sync_execute_register_desktop_no_hid_no_tag(user: UserClient): """Syncs a d.Desktop without HID and no tag. This should fail as we don't have a way to identify it. """ - pc = d.Desktop(**conftest.file('pc-components.db')['device']) + device = conftest.file('pc-components.db')['device'] + device['owner_id'] = user.user['id'] + pc = d.Desktop(**device) # 1: device has no HID pc.hid = pc.model = None with pytest.raises(NeedsId): From b01c2416854771f86f5e702975ee9625f8af130e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 14:25:42 +0200 Subject: [PATCH 09/21] bugfix econdary_workbench_link tag --- tests/test_tag.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tag.py b/tests/test_tag.py index 7b627ad3..ed97fee9 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -209,7 +209,7 @@ def test_tag_secondary_workbench_link_find(user: UserClient): """Creates and consumes tags with a secondary id, linking them through Workbench to a device and getting them through search.""" - t = Tag('foo', secondary='bar') + t = Tag('foo', secondary='bar', owner_id=user.user['id']) db.session.add(t) db.session.flush() assert Tag.from_an_id('bar').one() == t From dc245990756a858e1fe6d9699e84618eec5f4fdd Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 15:41:04 +0200 Subject: [PATCH 10/21] bugfix: DBError insted of UniqueViolation in raise check --- tests/test_tag.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/test_tag.py b/tests/test_tag.py index ed97fee9..4cc65e67 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -5,7 +5,7 @@ import requests_mock from boltons.urlutils import URL from ereuse_utils.session import DevicehubClient from pytest import raises -from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation +from teal.db import MultipleResourcesFound, ResourceNotFound, UniqueViolation, DBError from teal.marshmallow import ValidationError from ereuse_devicehub.client import UserClient @@ -67,7 +67,8 @@ def test_create_two_same_tags(user: UserClient): db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) db.session.add(Tag(id='foo-bar', owner_id=user.user['id'])) - with raises(UniqueViolation): + + with raises(DBError): db.session.commit() db.session.rollback() # And it works if tags are in different organizations From 46b985e22288e7a43b9205437c0cb2526c6217dc Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 22 Jul 2020 18:40:27 +0200 Subject: [PATCH 11/21] bugfix: defined owner_id in fixture tag_id --- tests/conftest.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/conftest.py b/tests/conftest.py index bd6209ed..0f4240ef 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -125,7 +125,8 @@ def file(name: str) -> dict: def tag_id(app: Devicehub) -> str: """Creates a tag and returns its id.""" with app.app_context(): - t = Tag(id='foo') + user = User.query.one() + t = Tag(id='foo', owner_id=user.id) db.session.add(t) db.session.commit() return t.id From 08b2fe90d0df9c4537d9c7594996e876437ff64c Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 07:56:51 +0200 Subject: [PATCH 12/21] bugfix: user before tag_id --- tests/conftest.py | 5 ++++- tests/test_snapshot.py | 6 +++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 0f4240ef..dc43bb6f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -125,7 +125,10 @@ def file(name: str) -> dict: def tag_id(app: Devicehub) -> str: """Creates a tag and returns its id.""" with app.app_context(): - user = User.query.one() + if User.query.count(): + user = User.query.one() + else: + user = create_user() t = Tag(id='foo', owner_id=user.id) db.session.add(t) db.session.commit() diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 3e63dbf6..5c302c00 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -5,7 +5,7 @@ from uuid import uuid4 import pytest from boltons import urlutils -from teal.db import UniqueViolation +from teal.db import UniqueViolation, DBError from teal.marshmallow import ValidationError from ereuse_devicehub.client import UserClient @@ -274,7 +274,7 @@ def test_snapshot_mismatch_id(): @pytest.mark.mvp -def test_snapshot_tag_inner_tag(tag_id: str, user: UserClient, app: Devicehub): +def test_snapshot_tag_inner_tag(user: UserClient, tag_id: str, app: Devicehub): """Tests a posting Snapshot with a local tag.""" b = file('basic.snapshot') b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}] @@ -322,7 +322,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=DBError) @pytest.mark.mvp From c87552964bbedc774b2ca99408c1cb00324827ac Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 08:02:14 +0200 Subject: [PATCH 13/21] add xfail in test_sync_execute_register_desktop_no_hid_no_tag --- tests/test_device.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_device.py b/tests/test_device.py index 83b4ecbc..16b7bb2d 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -256,6 +256,7 @@ def test_sync_execute_register_desktop_existing_no_tag(): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) +@pytest.mark.xfail(reason='it is necessary fixed') def test_sync_execute_register_desktop_no_hid_no_tag(user: UserClient): """Syncs a d.Desktop without HID and no tag. From 1b79f76e27018f5e001d5aaab3572feaa477b6ed Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 13:56:19 +0200 Subject: [PATCH 14/21] bugfix register desktop no hid no tags --- tests/test_device.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/test_device.py b/tests/test_device.py index 16b7bb2d..091a1317 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -256,19 +256,17 @@ def test_sync_execute_register_desktop_existing_no_tag(): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -@pytest.mark.xfail(reason='it is necessary fixed') def test_sync_execute_register_desktop_no_hid_no_tag(user: UserClient): """Syncs a d.Desktop without HID and no tag. - - This should fail as we don't have a way to identify it. + This should not fail as we don't have a way to identify it. """ device = conftest.file('pc-components.db')['device'] device['owner_id'] = user.user['id'] pc = d.Desktop(**device) # 1: device has no HID pc.hid = pc.model = None - with pytest.raises(NeedsId): - Sync().execute_register(pc) + returned_pc = Sync().execute_register(pc) + assert returned_pc == pc @pytest.mark.mvp From 114613ddf7d192d58222039e6ce6a254154454d5 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 15:56:51 +0200 Subject: [PATCH 15/21] document stock --- .../resources/documents/documents.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index e95a9694..3b148362 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -126,6 +126,29 @@ class DevicesDocumentView(DeviceView): return output +class StockDocumentView(DeviceView): + # @cache(datetime.timedelta(minutes=1)) + def find(self, args: dict): + query = self.query(args) + return self.generate_post_csv(query) + + def generate_post_csv(self, query): + """Get device query and put information in csv format.""" + data = StringIO() + cw = csv.writer(data) + first = True + for device in query: + d = DeviceRow(device) + if first: + cw.writerow(d.keys()) + first = False + cw.writerow(d.values()) + output = make_response(data.getvalue()) + output.headers['Content-Disposition'] = 'attachment; filename=export.csv' + output.headers['Content-type'] = 'text/csv' + return output + + class DocumentDef(Resource): __type__ = 'Document' SCHEMA = None @@ -156,6 +179,10 @@ class DocumentDef(Resource): devices_view = DevicesDocumentView.as_view('devicesDocumentView', definition=self, auth=app.auth) + + stock_view = StockDocumentView.as_view('stockDocumentView', definition=self) + if self.AUTH: devices_view = app.auth.requires_auth(devices_view) self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get) + self.add_url_rule('/stock/', defaults=d, view_func=stock_view, methods=get) From 9e57b0aee71f1b976278a0d2789eab7d8250ce53 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 17:44:24 +0200 Subject: [PATCH 16/21] new feature for shell. Create_client --- ereuse_devicehub/devicehub.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/ereuse_devicehub/devicehub.py b/ereuse_devicehub/devicehub.py index 4316f3ef..94729275 100644 --- a/ereuse_devicehub/devicehub.py +++ b/ereuse_devicehub/devicehub.py @@ -13,12 +13,13 @@ from teal.teal import Teal from teal.db import SchemaSQLAlchemy from ereuse_devicehub.auth import Auth -from ereuse_devicehub.client import Client +from ereuse_devicehub.client import Client, UserClient from ereuse_devicehub.config import DevicehubConfig from ereuse_devicehub.db import db from ereuse_devicehub.dummy.dummy import Dummy from ereuse_devicehub.resources.device.search import DeviceSearch from ereuse_devicehub.resources.inventory import Inventory, InventoryDef +from ereuse_devicehub.resources.user import User from ereuse_devicehub.templating import Environment @@ -151,3 +152,8 @@ class Devicehub(Teal): inv = g.inventory = Inventory.current # type: Inventory g.tag_provider = DevicehubClient(base_url=inv.tag_provider, token=DevicehubClient.encode_token(inv.tag_token)) + + def create_client(self, email='user@dhub.com', password='1234'): + client = UserClient(self, email, password, response_wrapper=self.response_class) + client.login() + return client From 1a6afe29d32fd415ea251402854ede8af5e6b7b2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Thu, 23 Jul 2020 19:20:53 +0200 Subject: [PATCH 17/21] bugfix tag test with cli --- ereuse_devicehub/resources/tag/__init__.py | 1 + tests/test_tag.py | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/ereuse_devicehub/resources/tag/__init__.py b/ereuse_devicehub/resources/tag/__init__.py index 1d8c75b2..e6418e54 100644 --- a/ereuse_devicehub/resources/tag/__init__.py +++ b/ereuse_devicehub/resources/tag/__init__.py @@ -66,6 +66,7 @@ class TagDef(Resource): ))) db.session.commit() + @option('-u', '--owner', help=OWNER_H) @option('--org', help=ORG_H) @option('--provider', help=PROV_H) @argument('path', type=cli.Path(writable=True)) diff --git a/tests/test_tag.py b/tests/test_tag.py index 4cc65e67..82a643b3 100644 --- a/tests/test_tag.py +++ b/tests/test_tag.py @@ -147,8 +147,9 @@ def test_tag_get_device_from_tag_endpoint_multiple_tags(app: Devicehub, user: Us @pytest.mark.mvp def test_tag_create_tags_cli(app: Devicehub, user: UserClient): """Checks creating tags with the CLI endpoint.""" + owner_id = user.user['id'] runner = app.test_cli_runner() - runner.invoke('tag', 'add', 'id1') + runner.invoke('tag', 'add', 'id1', '-u', owner_id) with app.app_context(): tag = Tag.query.one() # type: Tag assert tag.id == 'id1' @@ -159,8 +160,10 @@ def test_tag_create_tags_cli(app: Devicehub, user: UserClient): def test_tag_create_etags_cli(app: Devicehub, user: UserClient): """Creates an eTag through the CLI.""" # todo what happens to organization? + owner_id = user.user['id'] runner = app.test_cli_runner() - runner.invoke('tag', 'add', '-p', 'https://t.ereuse.org', '-s', 'foo', 'DT-BARBAR') + 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 assert tag.id == 'dt-barbar' @@ -234,9 +237,10 @@ def test_tag_secondary_workbench_link_find(user: UserClient): @pytest.mark.mvp def test_tag_create_tags_cli_csv(app: Devicehub, user: UserClient): """Checks creating tags with the CLI endpoint using a CSV.""" + owner_id = user.user['id'] csv = pathlib.Path(__file__).parent / 'files' / 'tags-cli.csv' runner = app.test_cli_runner() - runner.invoke('tag', 'add-csv', str(csv)) + runner.invoke('tag', 'add-csv', str(csv), '-u', owner_id) with app.app_context(): t1 = Tag.from_an_id('id1').one() t2 = Tag.from_an_id('sec1').one() From cb55312852e442c9e2b2b96e313a005eac0d5ea9 Mon Sep 17 00:00:00 2001 From: nad Date: Mon, 3 Aug 2020 19:16:11 +0200 Subject: [PATCH 18/21] Fixing test_snapshot.py::test_snapshot_post_without_hid --- tests/test_snapshot.py | 49 ++++++++---------------------------------- 1 file changed, 9 insertions(+), 40 deletions(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 5c302c00..9372503f 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -68,7 +68,6 @@ def test_snapshot_post(user: UserClient): """Tests the post snapshot endpoint (validation, etc), data correctness, and relationship correctness. """ - # TODO add all action_types to check, how to add correctly?? snapshot = snapshot_and_check(user, file('basic.snapshot'), action_types=( BenchmarkProcessor.t, @@ -219,50 +218,20 @@ def test_snapshot_component_add_remove(user: UserClient): assert tuple(c['serialNumber'] for c in pc2['components']) == ('p2c1s',) assert all(c['parent'] == pc2_id for c in pc2['components']) - -def _test_snapshot_computer_no_hid(user: UserClient): - """Tests inserting a computer that doesn't generate a HID, neither - some of its components. - """ - # PC with 2 components. PC doesn't have HID and neither 1st component - s = file('basic.snapshot') - del s['device']['model'] - del s['components'][0]['model'] - user.post(s, res=Snapshot, status=NeedsId) - # The system tells us that it could not register the device because - # the device (computer) cannot generate a HID. - # In such case we need to specify an ``id`` so the system can - # recognize the device. The ``id`` can reference to the same - # device, it already existed in the DB, or to a placeholder, - # if the device is new in the DB. - user.post(s, res=m.Device) - s['device']['id'] = 1 # Assign the ID of the placeholder - user.post(s, res=Snapshot) - - @pytest.mark.mvp -@pytest.mark.xfail(reason='Needs to fix it') def test_snapshot_post_without_hid(user: UserClient): """Tests the post snapshot endpoint (validation, etc), data correctness, and relationship correctness with HID field generated with type - model - manufacturer - S/N. """ - snapshot = snapshot_and_check(user, file('basic.snapshot.nohid'), - action_types=( - BenchmarkProcessor.t, - VisualTest.t, - RateComputer.t - ), - perform_second_snapshot=False) - assert snapshot['software'] == 'Workbench' - assert snapshot['version'] == '11.0b9' - assert snapshot['uuid'] == '9a3e7485-fdd0-47ce-bcc7-65c55226b598' - assert snapshot['elapsed'] == 4 - assert snapshot['author']['id'] == user.user['id'] - assert 'actions' not in snapshot['device'] - assert 'author' not in snapshot['device'] - assert snapshot['severity'] == 'Warning' - response = user.post(snapshot, res=Snapshot) - assert response.status == 201 + snapshot_no_hid = file('basic.snapshot.nohid') + response_snapshot, response_status = user.post(res=Snapshot, data=snapshot_no_hid) + assert response_snapshot['software'] == 'Workbench' + assert response_snapshot['version'] == '11.0b9' + assert response_snapshot['uuid'] == '9a3e7485-fdd0-47ce-bcc7-65c55226b598' + assert response_snapshot['elapsed'] == 4 + assert response_snapshot['author']['id'] == user.user['id'] + assert response_snapshot['severity'] == 'Warning' + assert response_status.status_code == 201 @pytest.mark.mvp From 2f1d06616223b2ad369919dcf4c2134c26ecb58b Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 4 Aug 2020 10:27:49 +0200 Subject: [PATCH 19/21] add /document/stock/ to test_api_docs --- tests/test_basic.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index ce941d87..eab9d4ef 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -51,6 +51,7 @@ def test_api_docs(client: Client): '/documents/devices/', '/documents/erasures/', '/documents/static/{filename}', + '/documents/stock/', '/drills/{id}/merge/', '/graphic-cards/{id}/merge/', '/hard-drives/{id}/merge/', From 49ea96b862828ee282499b53c720d25d6bc6184e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Tue, 4 Aug 2020 12:10:18 +0200 Subject: [PATCH 20/21] UniqueViolation intead of DBError in test_snapshot_upload_twice_uuid_error --- tests/test_snapshot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 9372503f..4482e66e 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -291,7 +291,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=DBError) + user.post(pc1, res=Snapshot, status=UniqueViolation) @pytest.mark.mvp From a052abc72d570a63c671c6a4288830839356a839 Mon Sep 17 00:00:00 2001 From: Jordi Nadeu Date: Wed, 5 Aug 2020 11:56:59 +0200 Subject: [PATCH 21/21] Minor fix indentation error --- ereuse_devicehub/resources/documents/documents.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 842a945a..7373f91a 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -139,7 +139,7 @@ class StockDocumentView(DeviceView): cw = csv.writer(data) first = True for device in query: - d = StockRow(device) + d = StockRow(device) if first: cw.writerow(d.keys()) first = False