From 8567c629cb3fb74882e73309ce99113d71748efc Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Thu, 25 Oct 2018 12:36:25 +0200 Subject: [PATCH] Add new fixtures and dummy --- ereuse_devicehub/dummy/dummy.py | 1 + .../dummy/files/oreo.snapshot.yaml | 169 ++++++++++++++++++ ereuse_devicehub/resources/enums.py | 2 +- tests/files/erase-sectors-2-hdd.snapshot.yaml | 11 +- tests/test_snapshot.py | 9 + 5 files changed, 186 insertions(+), 6 deletions(-) create mode 100644 ereuse_devicehub/dummy/files/oreo.snapshot.yaml diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index b984e9c5..472bd652 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -28,6 +28,7 @@ class Dummy: ET = ( ('A0000000000001', 'DT-AAAAA'), ('A0000000000002', 'DT-BBBBB'), + ('A0000000000002', 'DT-CCCCC'), ) """eTags to create.""" ORG = 'eReuse.org CAT', '-t', 'G-60437761', '-c', 'ES' diff --git a/ereuse_devicehub/dummy/files/oreo.snapshot.yaml b/ereuse_devicehub/dummy/files/oreo.snapshot.yaml new file mode 100644 index 00000000..4ceeb12d --- /dev/null +++ b/ereuse_devicehub/dummy/files/oreo.snapshot.yaml @@ -0,0 +1,169 @@ +{ + "uuid": "de4f495e-c58b-40e1-a33e-46ab5e84767e", + "endTime": "2018-10-24T11:03:36.113006+00:00", + "components": [ + { + "speed": 1000, + "manufacturer": "Realtek Semiconductor Co., Ltd.", + "wireless": false, + "model": "RTL8111/8168/8411 PCI Express Gigabit Ethernet Controller", + "serialNumber": "00:26:18:96:dc:af", + "type": "NetworkAdapter", + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "speed": 1333.0, + "manufacturer": null, + "interface": "DDR", + "model": null, + "serialNumber": null, + "type": "RamModule", + "format": "DIMM", + "size": 2048, + "events": [] + }, + { + "manufacturer": "Intel Corporation", + "model": "5 Series/3400 Series Chipset High Definition Audio", + "serialNumber": null, + "type": "SoundCard", + "events": [] + }, + { + "speed": 2.5330000000000004, + "manufacturer": "Intel Corp.", + "cores": 4, + "address": 64, + "model": "Intel Core i7 CPU 860 @ 2.80GHz", + "serialNumber": null, + "type": "Processor", + "threads": 8, + "events": [ + { + "elapsed": 9, + "type": "BenchmarkProcessorSysbench", + "rate": 8.7418 + }, + { + "elapsed": 0, + "type": "BenchmarkProcessor", + "rate": 44937.520000000004 + } + ] + }, + { + "manufacturer": null, + "interface": "ATA", + "model": "SAMSUNG HD103SJ", + "serialNumber": "S246J90Z406422", + "type": "HardDrive", + "size": 953869, + "events": [ + { + "elapsed": 120, + "lifetime": 14298, + "currentPendingSectorCount": 0, + "type": "TestDataStorage", + "status": "Completed without error", + "powerCycleCount": 693, + "assessment": true, + "offlineUncorrectable": 0, + "error": false, + "length": "Short", + "reallocatedSectorCount": 0 + }, + { + "readSpeed": 136.0, + "elapsed": 9, + "type": "BenchmarkDataStorage", + "writeSpeed": 35.0 + } + ] + }, + { + "manufacturer": "NVIDIA Corporation", + "model": "G84 GeForce 8600 GT", + "serialNumber": null, + "type": "GraphicCard", + "memory": 256.0, + "events": [] + }, + { + "firewire": 1, + "manufacturer": "ASUSTeK Computer INC.", + "usb": 2, + "model": "P7P55D", + "serialNumber": "101005570001137", + "type": "Motherboard", + "pcmcia": 0, + "slots": 4, + "serial": 1, + "events": [] + } + ], + "elapsed": 203, + "device": { + "manufacturer": null, + "model": null, + "chassis": "Tower", + "type": "Desktop", + "serialNumber": null, + "events": [ + { + "elapsed": 60, + "type": "StressTest", + "error": false + }, + { + "elapsed": 1, + "type": "BenchmarkRamSysbench", + "rate": 0.8315 + } + ], + "tags": [ + {"id": "A0000000000002", "type": "Tag"} + ] + }, + "version": "11.0a6", + "expectedEvents": [ + "Benchmark", + "TestDataStorage", + "StressTest" + ], + "type": "Snapshot", + "closed": true, + "software": "Workbench" +} diff --git a/ereuse_devicehub/resources/enums.py b/ereuse_devicehub/resources/enums.py index 9b882f46..e116f5a5 100644 --- a/ereuse_devicehub/resources/enums.py +++ b/ereuse_devicehub/resources/enums.py @@ -244,7 +244,7 @@ class ComputerChassis(Enum): Tablet = 'Tablet' Virtual = 'Non-physical device' - def __format__(self, format_spec): + def __str__(self): return inflection.humanize(inflection.underscore(self.value)) diff --git a/tests/files/erase-sectors-2-hdd.snapshot.yaml b/tests/files/erase-sectors-2-hdd.snapshot.yaml index 0fd43f8a..84eb5a9c 100644 --- a/tests/files/erase-sectors-2-hdd.snapshot.yaml +++ b/tests/files/erase-sectors-2-hdd.snapshot.yaml @@ -1,9 +1,9 @@ { "version": "11.0a3", "device": { - "serialNumber": null, - "manufacturer": null, - "model": null, + "serialNumber": 'foo', + "manufacturer": 'bar', + "model": 'baz', "type": "Desktop", "events": [], "chassis": "Tower" @@ -53,7 +53,8 @@ "type": "NetworkAdapter", "events": [], "serialNumber": "f4:6d:04:12:9b:85", - "speed": 1000 + "speed": 1000, + "wireless": false }, { "serialNumber": "WD-WCAV29008961", @@ -86,7 +87,7 @@ "error": true, "currentPendingSectorCount": 1, "powerCycleCount": 1253, - "reallocatedSectorCount": 6, + "reallocatedSectorCount": 15, "type": "TestDataStorage", "status": "Completed: read failure" } diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index afdaa1e9..33e0b93c 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -322,6 +322,15 @@ def test_erase(user: UserClient): assert snapshot['components'][0]['privacy'] == 'EraseSectorsError' +def test_test_data_storage(user: UserClient): + """Tests a Snapshot with EraseSectors.""" + s = file('erase-sectors-2-hdd.snapshot') + snapshot, _ = user.post(res=Snapshot, data=s) + incidence_test = next(ev for ev in snapshot['events'] if ev['reallocatedSectorCount'] == 15) + assert incidence_test['incidence'] + assert incidence_test['description'] == 'Warning: Drive failure expected soon.' + + def test_snapshot_computer_monitor(user: UserClient): s = file('computer-monitor.snapshot') snapshot_and_check(user, s, event_types=('ManualRate',))