From 5fb1471d9bf0e82f1db390ca1bda17384c8a8318 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Wed, 2 Jan 2019 17:52:43 +0100 Subject: [PATCH] Use type for HID --- ereuse_devicehub/dummy/dummy.py | 2 +- .../files/laptop-with-2-hid.snapshot.11.yaml | 158 ++++++++++++++++++ ereuse_devicehub/resources/device/models.py | 2 +- ereuse_devicehub/resources/device/sync.py | 2 + requirements.txt | 4 +- setup.py | 4 +- tests/test_device.py | 6 +- tests/test_snapshot.py | 2 +- tests/test_workbench.py | 16 +- 9 files changed, 179 insertions(+), 17 deletions(-) create mode 100644 ereuse_devicehub/dummy/files/laptop-with-2-hid.snapshot.11.yaml diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index 2a072c3f..c7b83345 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -128,7 +128,7 @@ class Dummy: i, _ = user.get(res=Device, query=[('search', 'intel')]) assert len(i['items']) == 12 i, _ = user.get(res=Device, query=[('search', 'pc')]) - assert len(i['items']) == 13 + assert len(i['items']) == 14 # Let's create a set of events for the pc device # Make device Ready diff --git a/ereuse_devicehub/dummy/files/laptop-with-2-hid.snapshot.11.yaml b/ereuse_devicehub/dummy/files/laptop-with-2-hid.snapshot.11.yaml new file mode 100644 index 00000000..ea839325 --- /dev/null +++ b/ereuse_devicehub/dummy/files/laptop-with-2-hid.snapshot.11.yaml @@ -0,0 +1,158 @@ +{ + "software": "Workbench", + "endTime": "2018-09-22T19:05:47.005552+00:00", + "device": { + "events": [ + { + "rate": 15.9663, + "type": "BenchmarkRamSysbench", + "elapsed": 16 + }, + { + + "type": "StressTest", + "elapsed": 120 + } + ], + "model": "E627", + "chassis": "Netbook", + "serialNumber": "LXN650207893942DE21601", + "type": "Laptop", + "manufacturer": "eMachines" + }, + "elapsed": 451, + "expectedEvents": [ + "Benchmark", + "TestDataStorage", + "StressTest" + ], + "components": [ + { + "events": [], + "model": "Video WebCam", + "serialNumber": "CN0314-SN30-OV035-VA-R05.00.00", + "type": "SoundCard", + "manufacturer": "SuYin" + }, + { + "events": [], + "model": "SBx00 Azalia", + "serialNumber": null, + "type": "SoundCard", + "manufacturer": "Advanced Micro Devices, Inc. AMD/ATI" + }, + { + "speed": 400.0, + "size": 2048, + "format": "DIMM", + "events": [], + "model": "HYMP125S64CP8-S6", + "interface": "DDR2", + "type": "RamModule", + "manufacturer": null, + "serialNumber": null + }, + { + "speed": 400.0, + "size": 2048, + "format": "DIMM", + "events": [], + "model": "HYMP125S64CP8-S6", + "interface": "DDR2", + "type": "RamModule", + "manufacturer": null, + "serialNumber": null + }, + { + "speed": 0.8, + "address": 64, + "serialNumber": null, + "events": [ + { + "rate": 173.6996, + "type": "BenchmarkProcessorSysbench", + "elapsed": 174 + }, + { + "rate": 3191.96, + "type": "BenchmarkProcessor", + "elapsed": 0 + } + ], + "model": "AMD Athlon Processor TF-20", + "threads": 1, + "cores": 1, + "type": "Processor", + "manufacturer": "Advanced Micro Devices AMD" + }, + { + "events": [], + "model": "AR9285 Wireless Network Adapter", + "serialNumber": "0c:60:76:5f:49:91", + "type": "NetworkAdapter", + "manufacturer": "Qualcomm Atheros", + "wireless": true + }, + { + "speed": 100, + "events": [], + "model": "AR8132 Fast Ethernet", + "serialNumber": "00:26:22:59:a1:56", + "type": "NetworkAdapter", + "manufacturer": "Qualcomm Atheros", + "wireless": false + }, + { + "size": 152627, + "serialNumber": "WD-WX80A8996018", + "events": [ + { + "writeSpeed": 17.8, + "type": "BenchmarkDataStorage", + "elapsed": 20, + "readSpeed": 59.8 + }, + { + "currentPendingSectorCount": 0, + "length": "Short", + "elapsed": 117, + "reallocatedSectorCount": 0, + "powerCycleCount": 2872, + "offlineUncorrectable": 0, + "type": "TestDataStorage", + "lifetime": 2775, + "assessment": true, + "status": "Completed without error" + } + ], + "model": "WDC WD1600BEVT-2", + "interface": "ATA", + "type": "HardDrive", + "manufacturer": "Western Digital" + }, + { + "events": [], + "model": "RS780M Mobility Radeon HD 3200", + "serialNumber": null, + "type": "GraphicCard", + "manufacturer": "Advanced Micro Devices, Inc. AMD/ATI", + "memory": 256.0 + }, + { + "slots": 4, + "firewire": 0, + "events": [], + "model": "E627", + "usb": 3, + "serialNumber": "LXN650207893942DE21601", + "type": "Motherboard", + "manufacturer": "eMachines", + "serial": 1, + "pcmcia": 0 + } + ], + "uuid": "a01eacdb-db01-43ec-b6fb-a9b8cd21492d", + "type": "Snapshot", + "version": "11.0a4", + "closed": false +} diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 4b3ac8c3..1c6e219a 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -86,7 +86,7 @@ class Device(Thing): def __init__(self, **kw) -> None: super().__init__(**kw) with suppress(TypeError): - self.hid = Naming.hid(self.manufacturer, self.serial_number, self.model) + self.hid = Naming.hid(self.type, self.manufacturer, self.model, self.serial_number) @property def events(self) -> list: diff --git a/ereuse_devicehub/resources/device/sync.py b/ereuse_devicehub/resources/device/sync.py index 07c238e2..e0b9085f 100644 --- a/ereuse_devicehub/resources/device/sync.py +++ b/ereuse_devicehub/resources/device/sync.py @@ -105,6 +105,8 @@ class Sync: try: if component.hid: db_component = Device.query.filter_by(hid=component.hid).one() + assert isinstance(db_component, Device), \ + '{} must be a component'.format(db_component) else: # Is there a component similar to ours? db_component = component.similar_one(parent, blacklist) diff --git a/requirements.txt b/requirements.txt index 6d5a32d5..e49631ac 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ click==6.7 click-spinner==0.1.8 colorama==0.3.9 colour==0.1.5 -ereuse-utils==0.4.0b11 +ereuse-utils==0.4.0b13 Flask==1.0.2 Flask-Cors==3.0.6 Flask-SQLAlchemy==2.3.2 @@ -25,7 +25,7 @@ requests==2.19.1 requests-mock==1.5.2 SQLAlchemy==1.2.14 SQLAlchemy-Utils==0.33.6 -teal==0.2.0a31 +teal==0.2.0a32 webargs==4.0.0 Werkzeug==0.14.1 sqlalchemy-citext==1.3.post0 diff --git a/setup.py b/setup.py index 8095ebfa..8f6c261b 100644 --- a/setup.py +++ b/setup.py @@ -29,10 +29,10 @@ setup( long_description=long_description, long_description_content_type='text/markdown', install_requires=[ - 'teal>=0.2.0a31', # teal always first + 'teal>=0.2.0a32', # teal always first 'click', 'click-spinner', - 'ereuse-utils[Naming]>=0.4b11', + 'ereuse-utils[Naming]>=0.4b13', 'hashids', 'marshmallow_enum', 'psycopg2-binary', diff --git a/tests/test_device.py b/tests/test_device.py index d8a5d87f..f3ea0c6a 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -342,7 +342,7 @@ def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags(): db.session.add(Tag(id='foo-1', device=pc1)) pc2 = d.Desktop(**conftest.file('pc-components.db')['device']) pc2.serial_number = 'pc2-serial' - pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model) + pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model, pc2.serial_number) db.session.add(Tag(id='foo-2', device=pc2)) db.session.commit() @@ -366,7 +366,7 @@ def test_sync_execute_register_mismatch_between_tags_and_hid(): db.session.add(Tag(id='foo-1', device=pc1)) pc2 = d.Desktop(**conftest.file('pc-components.db')['device']) pc2.serial_number = 'pc2-serial' - pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model) + pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model, pc2.serial_number) db.session.add(Tag(id='foo-2', device=pc2)) db.session.commit() @@ -406,7 +406,7 @@ def test_get_device(app: Devicehub, user: UserClient): assert 'events_one' not in pc, 'they are internal use only' assert 'author' not in pc assert tuple(c['id'] for c in pc['components']) == (2, 3) - assert pc['hid'] == 'p1ma-p1s-p1mo' + assert pc['hid'] == 'desktop-p1ma-p1mo-p1s' assert pc['model'] == 'p1mo' assert pc['manufacturer'] == 'p1ma' assert pc['serialNumber'] == 'p1s' diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 8dde37ba..ef0e5bc9 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -326,7 +326,7 @@ def test_erase_privacy_standards(user: UserClient): s['components'][0]['events'][0]['severity'] = 'Error' snapshot, _ = user.post(s, res=Snapshot) storage, _ = user.get(res=m.Device, item=storage['id']) - assert storage['hid'] == 'c1mr-c1s-c1ml' + assert storage['hid'] == 'solidstatedrive-c1mr-c1ml-c1s' assert storage['privacy']['type'] == 'EraseSectors' pc, _ = user.get(res=m.Device, item=snapshot['device']['id']) assert pc['privacy'] == [storage['privacy']] diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 57d0fb8a..2b0229c8 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -54,7 +54,7 @@ def test_workbench_server_condensed(user: UserClient): device, _ = user.get(res=Device, item=snapshot['device']['id']) assert device['dataStorageSize'] == 1100 assert device['chassis'] == 'Tower' - assert device['hid'] == 'd1mr-d1s-d1ml' + assert device['hid'] == 'desktop-d1mr-d1ml-d1s' assert device['graphicCardModel'] == device['components'][0]['model'] == 'gc1-1ml' assert device['networkSpeeds'] == [1000, 58] assert device['processorModel'] == device['components'][3]['model'] == 'p1-1ml' @@ -140,7 +140,7 @@ 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'] == 'hewlett-packard-czc0408yjg-hp_compaq_8100_elite_sff' + assert pc['hid'] == 'desktop-hewlett-packard-hp_compaq_8100_elite_sff-czc0408yjg' assert pc['chassis'] == 'Tower' assert set(e['type'] for e in snapshot['events']) == { 'EreusePrice', @@ -179,7 +179,7 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): assert pc['model'] == '1001pxd' assert pc['serialNumber'] == 'b8oaas048286' assert pc['manufacturer'] == 'asustek computer inc.' - assert pc['hid'] == 'asustek_computer_inc-b8oaas048286-1001pxd' + assert pc['hid'] == 'laptop-asustek_computer_inc-1001pxd-b8oaas048286' assert pc['tags'] == [] assert pc['networkSpeeds'] == [100, 0], 'Although it has WiFi we do not know the speed' assert pc['rate'] @@ -200,11 +200,13 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): # assert rate['rating'] > 0 and rate['rating'] != 1 components = snapshot['components'] wifi = components[0] - assert wifi['hid'] == 'qualcomm_atheros-74_2f_68_8b_fd_c8-ar9285_wireless_network_adapter' + 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'] == 'qualcomm_atheros-14_da_e9_42_f6_7c-ar8152_v2_0_fast_ethernet' + 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] @@ -251,7 +253,7 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): assert pc['ramSize'] == ram['size'] == 1024 hdd = components[7] assert hdd['type'] == 'HardDrive' - assert hdd['hid'] == 'hitachi-e2024242cv86hj-hts54322' + assert hdd['hid'] == 'harddrive-hitachi-hts54322-e2024242cv86hj' assert hdd['interface'] == 'ATA' assert hdd['size'] == 238475 hdd, _ = user.get(res=Device, item=hdd['id']) @@ -270,7 +272,7 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): assert erase['severity'] == 'Info' assert hdd['privacy']['type'] == 'EraseBasic' mother = components[8] - assert mother['hid'] == 'asustek_computer_inc-eee0123456789-1001pxd' + assert mother['hid'] == 'motherboard-asustek_computer_inc-1001pxd-eee0123456789' def test_real_custom(user: UserClient):