From 47f5bf69ae595652293a9ac7dfe49dd649fdd736 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 15 Oct 2018 14:20:26 +0200 Subject: [PATCH] Return ranges in AggregateRate --- ereuse_devicehub/resources/event/models.py | 18 ++++++++++++++++++ ereuse_devicehub/resources/event/models.pyi | 16 ++++++++++++++++ ereuse_devicehub/resources/event/schemas.py | 17 +++++++++++++---- tests/test_workbench.py | 2 ++ 4 files changed, 49 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index 4c3e218c..d8e53243 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -456,6 +456,8 @@ class AggregateRate(Rate): kwargs.setdefault('version', StrictVersion('1.0')) super().__init__(*args, **kwargs) + # todo take value from LAST event (manual or workbench) + @property def processor(self): return self.workbench.processor @@ -476,6 +478,22 @@ class AggregateRate(Rate): def bios(self): return self.workbench.bios + @property + def functionality_range(self): + return self.workbench.functionality_range + + @property + def appearance_range(self): + return self.workbench.appearance_range + + @property + def bios_range(self): + return self.workbench.bios_range + + @property + def labelling(self): + return self.workbench.labelling + @classmethod def from_workbench_rate(cls, rate: WorkbenchRate): aggregate = cls() diff --git a/ereuse_devicehub/resources/event/models.pyi b/ereuse_devicehub/resources/event/models.pyi index fbac19e4..e6ea8377 100644 --- a/ereuse_devicehub/resources/event/models.pyi +++ b/ereuse_devicehub/resources/event/models.pyi @@ -199,6 +199,22 @@ class AggregateRate(Rate): def bios(self): return self.workbench.bios + @property + def functionality_range(self): + return self.workbench.functionality_range + + @property + def appearance_range(self): + return self.workbench.appearance_range + + @property + def bios_range(self): + return self.workbench.bios_range + + @property + def labelling(self): + return self.workbench.labelling + @classmethod def from_workbench_rate(cls, rate: WorkbenchRate) -> AggregateRate: pass diff --git a/ereuse_devicehub/resources/event/schemas.py b/ereuse_devicehub/resources/event/schemas.py index 242c8886..56732683 100644 --- a/ereuse_devicehub/resources/event/schemas.py +++ b/ereuse_devicehub/resources/event/schemas.py @@ -99,7 +99,6 @@ class StepRandom(Step): class Rate(EventWithOneDevice): rating = Integer(validate=Range(*RATE_POSITIVE), dump_only=True, - data_key='rating', description=m.Rate.rating.comment) software = EnumField(RatingSoftware, dump_only=True, @@ -107,9 +106,7 @@ class Rate(EventWithOneDevice): version = Version(dump_only=True, description=m.Rate.version.comment) appearance = Integer(validate=Range(-3, 5), dump_only=True) - functionality = Integer(validate=Range(-3, 5), - dump_only=True, - data_key='functionalityScore') + functionality = Integer(validate=Range(-3, 5), dump_only=True) class IndividualRate(Rate): @@ -150,6 +147,18 @@ class AggregateRate(Rate): data_storage = Float(dump_only=True) graphic_card = Float(dump_only=True) bios = EnumField(Bios, dump_only=True) + bios_range = EnumField(Bios, + description=m.WorkbenchRate.bios_range.comment, + data_key='biosRange') + appearance_range = EnumField(AppearanceRange, + required=True, + data_key='appearanceRange', + description=m.ManualRate.appearance_range.comment) + functionality_range = EnumField(FunctionalityRange, + required=True, + data_key='functionalityRange', + description=m.ManualRate.functionality_range.comment) + labelling = Boolean(description=m.ManualRate.labelling.comment) class Price(EventWithOneDevice): diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 0e8efc74..f835ce21 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -62,6 +62,8 @@ def test_workbench_server_condensed(user: UserClient): assert not device['rate']['error'] assert device['rate']['rating'] == 0 assert device['rate']['workbench'] + assert device['rate']['appearanceRange'] == 'A' + assert device['rate']['functionalityRange'] == 'B' assert device['tags'][0]['id'] == 'tag1'