From 97536c5ce12cc44be56b890b03cdaab5f508aec2 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Sun, 14 Oct 2018 23:56:54 +0200 Subject: [PATCH] Fix bug when device rate is low --- ereuse_devicehub/resources/event/models.py | 12 +- ereuse_devicehub/resources/event/models.pyi | 2 +- tests/files/asus-1001pxd.snapshot.yaml | 134 ++++++++++++++++++++ tests/test_workbench.py | 6 + 4 files changed, 148 insertions(+), 6 deletions(-) create mode 100644 tests/files/asus-1001pxd.snapshot.yaml diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index 4f7f49f1..ea6604bf 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -563,8 +563,9 @@ class EreusePrice(Price): def __init__(self, device, rating_range, role, price) -> None: cls = device.__class__ if device.__class__ != Server else Desktop rate = self.SCHEMA[cls][rating_range] - self.standard = EreusePrice.Type(rate['STD'][role], price) - self.warranty2 = EreusePrice.Type(rate['WR2'][role], price) + self.standard = EreusePrice.Type(rate[self.STANDARD][role], price) + if self.WARRANTY2 in rate: + self.warranty2 = EreusePrice.Type(rate[self.WARRANTY2][role], price) def __init__(self, rating: AggregateRate, **kwargs) -> None: if rating.rating_range == RatingRange.VERY_LOW: @@ -584,9 +585,10 @@ class EreusePrice(Price): self.refurbisher = self._service(self.Service.REFURBISHER) self.retailer = self._service(self.Service.RETAILER) self.platform = self._service(self.Service.PLATFORM) - self.warranty2 = round(self.refurbisher.warranty2.amount - + self.retailer.warranty2.amount - + self.platform.warranty2.amount, 2) + if hasattr(self.refurbisher, 'warranty2'): + self.warranty2 = round(self.refurbisher.warranty2.amount + + self.retailer.warranty2.amount + + self.platform.warranty2.amount, 2) def _service(self, role): return self.Service(self.device, self.rating.rating_range, role, self.price) diff --git a/ereuse_devicehub/resources/event/models.pyi b/ereuse_devicehub/resources/event/models.pyi index 5ef88664..a146c908 100644 --- a/ereuse_devicehub/resources/event/models.pyi +++ b/ereuse_devicehub/resources/event/models.pyi @@ -262,7 +262,7 @@ class EreusePrice(Price): MULTIPLIER = ... # type: Dict class Type: - def __init__(self) -> None: + def __init__(self, percentage, price) -> None: super().__init__() self.amount = ... # type: float self.percentage = ... # type: float diff --git a/tests/files/asus-1001pxd.snapshot.yaml b/tests/files/asus-1001pxd.snapshot.yaml new file mode 100644 index 00000000..2eaf0f43 --- /dev/null +++ b/tests/files/asus-1001pxd.snapshot.yaml @@ -0,0 +1,134 @@ +{ + "closed": true, + "components": [ + { + "events": [], + "manufacturer": "Intel Corporation", + "model": "NM10/ICH7 Family High Definition Audio Controller", + "serialNumber": null, + "type": "SoundCard" + }, + { + "events": [], + "manufacturer": "Azurewave", + "model": "USB 2.0 UVC VGA WebCam", + "serialNumber": "0x0001", + "type": "SoundCard" + }, + { + "events": [], + "format": "DIMM", + "interface": "DDR2", + "manufacturer": null, + "model": null, + "serialNumber": null, + "size": 1024, + "speed": 667.0, + "type": "RamModule" + }, + { + "address": 64, + "cores": 1, + "events": [ + { + "elapsed": 165, + "rate": 164.8342, + "type": "BenchmarkProcessorSysbench" + }, + { + "elapsed": 0, + "rate": 6665.7, + "type": "BenchmarkProcessor" + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Atom CPU N455 @ 1.66GHz", + "serialNumber": null, + "speed": 1.667, + "threads": 2, + "type": "Processor" + }, + { + "events": [ + { + "elapsed": 16, + "readSpeed": 66.2, + "type": "BenchmarkDataStorage", + "writeSpeed": 21.8 + } + ], + "interface": "ATA", + "manufacturer": "Hitachi", + "model": "HTS54322", + "serialNumber": "E2024242CV86HJ", + "size": 238475, + "type": "HardDrive" + }, + { + "events": [], + "manufacturer": "Qualcomm Atheros", + "model": "AR9285 Wireless Network Adapter", + "serialNumber": "74:2f:68:8b:fd:c8", + "type": "NetworkAdapter", + "wireless": true + }, + { + "events": [], + "manufacturer": "Qualcomm Atheros", + "model": "AR8152 v2.0 Fast Ethernet", + "serialNumber": "14:da:e9:42:f6:7c", + "speed": 100, + "type": "NetworkAdapter", + "wireless": false + }, + { + "events": [], + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller", + "serialNumber": null, + "type": "GraphicCard" + }, + { + "events": [], + "firewire": 0, + "manufacturer": "ASUSTeK Computer INC.", + "model": "1001PXD", + "pcmcia": 0, + "serial": 1, + "serialNumber": "Eee0123456789", + "slots": 2, + "type": "Motherboard", + "usb": 5 + } + ], + "device": { + "chassis": "Netbook", + "events": [ + { + "elapsed": 16, + "rate": 15.8978, + "type": "BenchmarkRamSysbench" + }, + { + "appearanceRange": "A", + "biosRange": "A", + "functionalityRange": "A", + "type": "WorkbenchRate" + } + ], + "manufacturer": "ASUSTeK Computer INC.", + "model": "1001PXD", + "serialNumber": "B8OAAS048286", + "type": "Laptop" + }, + "elapsed": 6, + "endTime": "2018-10-14T21:22:14.777235+00:00", + "expectedEvents": [ + "Benchmark" + ], + "software": "Workbench", + "type": "Snapshot", + "uuid": "7dc4d19c-914e-4652-a381-d641325fb9c2", + "version": "11.0a6" +} diff --git a/tests/test_workbench.py b/tests/test_workbench.py index a2a3c8ef..0e8efc74 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -294,3 +294,9 @@ def test_workbench_fixtures(file: pathlib.Path, user: UserClient): user.post(res=em.Snapshot, data=s, status=201 if file.name not in SNAPSHOTS_NEED_ID else NeedsId) + + +def test_workbench_asus_1001pxd_rate_low(user: UserClient): + """Tests an Asus 1001pxd with a low rate.""" + s = file('asus-1001pxd.snapshot') + snapshot, _ = user.post(res=em.Snapshot, data=s)