From 91beed87ee01481eb1da0f5a991b1c5723ebd546 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Sat, 17 Nov 2018 19:22:41 +0100 Subject: [PATCH] Working Price; working test mobile with imei; update manual rate test --- ereuse_devicehub/resources/device/models.py | 2 + ereuse_devicehub/resources/device/schemas.py | 1 + ereuse_devicehub/resources/event/models.py | 6 ++- ereuse_devicehub/resources/event/models.pyi | 6 +-- tests/test_device.py | 10 ----- tests/test_event.py | 44 +++++++++++++++++++- tests/test_snapshot.py | 8 ++-- 7 files changed, 58 insertions(+), 19 deletions(-) diff --git a/ereuse_devicehub/resources/device/models.py b/ereuse_devicehub/resources/device/models.py index 4c77872b..5cf37afe 100644 --- a/ereuse_devicehub/resources/device/models.py +++ b/ereuse_devicehub/resources/device/models.py @@ -406,11 +406,13 @@ class Mobile(Device): def validate_imei(self, _, value: int): if not imei.is_valid(str(value)): raise ValidationError('{} is not a valid imei.'.format(value)) + return value @validates('meid') def validate_meid(self, _, value: str): if not meid.is_valid(value): raise ValidationError('{} is not a valid meid.'.format(value)) + return value class Smartphone(Mobile): diff --git a/ereuse_devicehub/resources/device/schemas.py b/ereuse_devicehub/resources/device/schemas.py index 79f02fe5..b04a7111 100644 --- a/ereuse_devicehub/resources/device/schemas.py +++ b/ereuse_devicehub/resources/device/schemas.py @@ -145,6 +145,7 @@ class Mobile(Device): def convert_check_meid(self, data: dict): if data.get('meid', None): data['meid'] = meid.compact(data['meid']) + return data class Smartphone(Mobile): diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index 5027bc25..2caa7995 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -584,6 +584,9 @@ class ManualRate(IndividualRate): self.functionality_range ) + def ratings(self): + raise NotImplementedError() + class WorkbenchRate(ManualRate): id = Column(UUID(as_uuid=True), ForeignKey(ManualRate.id), primary_key=True) @@ -604,7 +607,8 @@ class WorkbenchRate(ManualRate): """ Computes all the possible rates taking this rating as a model. - Returns a set of ratings, including this one, which is mutated. + Returns a set of ratings, including this one, which is mutated, + and the final :class:`.AggregateRate`. """ from ereuse_devicehub.resources.event.rate.main import main return main(self, **app.config.get_namespace('WORKBENCH_RATE_')) diff --git a/ereuse_devicehub/resources/event/models.pyi b/ereuse_devicehub/resources/event/models.pyi index 7628b8af..9c331a47 100644 --- a/ereuse_devicehub/resources/event/models.pyi +++ b/ereuse_devicehub/resources/event/models.pyi @@ -229,6 +229,9 @@ class ManualRate(IndividualRate): self.functionality_range = ... # type: FunctionalityRange self.aggregate_rate_manual = ... #type: AggregateRate + def ratings(self) -> Set[Rate]: + pass + class WorkbenchRate(ManualRate): processor = ... # type: Column @@ -249,9 +252,6 @@ class WorkbenchRate(ManualRate): self.bios = ... # type: float self.aggregate_rate_workbench = ... #type: AggregateRate - def ratings(self) -> Set[Rate]: - pass - @property def data_storage_range(self): pass diff --git a/tests/test_device.py b/tests/test_device.py index 152857b3..3eeb7adb 100644 --- a/tests/test_device.py +++ b/tests/test_device.py @@ -462,16 +462,6 @@ def test_computer_monitor(): db.session.commit() -@pytest.mark.xfail(reason='Make test') -def test_mobile_meid(): - pass - - -@pytest.mark.xfail(reason='Make test') -def test_mobile_imei(): - pass - - @pytest.mark.xfail(reason='Make test') def test_computer_with_display(): pass diff --git a/tests/test_event.py b/tests/test_event.py index 68824d27..3aaf1c87 100644 --- a/tests/test_event.py +++ b/tests/test_event.py @@ -315,9 +315,21 @@ def test_price_custom(): assert c['price']['id'] == p['id'] -@pytest.mark.xfail(reson='Develop test') -def test_price_custom_client(): +def test_price_custom_client(user: UserClient): """As test_price_custom but creating the price through the API.""" + s = file('basic.snapshot') + snapshot, _ = user.post(s, res=models.Snapshot) + price, _ = user.post({ + 'type': 'Price', + 'price': 25, + 'currency': Currency.EUR.name, + 'device': snapshot['device']['id'] + }, res=models.Event) + assert 25 == price['price'] + assert Currency.EUR.name == price['currency'] + + device, _ = user.get(res=Device, item=price['device']['id']) + assert 25 == device['price']['price'] @pytest.mark.xfail(reson='Develop test') @@ -358,3 +370,31 @@ def test_download_erasure_certificate(): """User can download erasure certificates. We test erasure certificates with: ... todo """ + + +@pytest.mark.xfail(reson='Adapt rate algorithm to re-compute by passing a manual rate.') +def test_manual_rate_after_workbench_rate(user: UserClient): + """Perform a WorkbenchRate and then update the device with a ManualRate. + + Devicehub must make the final rate with the first workbench rate + plus the new manual rate, without considering the appearance / + functionality values of the workbench rate. + """ + s = file('real-hp.snapshot.11') + snapshot, _ = user.post(s, res=models.Snapshot) + device, _ = user.get(res=Device, item=snapshot['device']['id']) + assert 'B' == device['rate']['appearanceRange'] + assert device['rate'] == 1 + user.post({ + 'type': 'ManualRate', + 'device': device['id'], + 'appearanceRange': 'A', + 'functionalityRange': 'A' + }, res=models.Event) + device, _ = user.get(res=Device, item=snapshot['device']['id']) + assert 'A' == device['rate']['appearanceRange'] + + +@pytest.mark.xfail(reson='Develop an algorithm that can make rates only from manual rates') +def test_manual_rate_without_workbench_rate(user: UserClient): + pass diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index c217bf2b..2e8ad343 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -350,10 +350,12 @@ def test_snapshot_computer_monitor(user: UserClient): # todo check that ManualRate has generated an AggregateRate -def test_snapshot_mobile_smartphone(user: UserClient): +def test_snapshot_mobile_smartphone_imei_manual_rate(user: UserClient): s = file('smartphone.snapshot') - snapshot_and_check(user, s, event_types=('ManualRate',)) - # todo check that ManualRate has generated an AggregateRate + snapshot = snapshot_and_check(user, s, event_types=('ManualRate',)) + mobile, _ = user.get(res=m.Device, item=snapshot['device']['id']) + assert mobile['imei'] == 3568680000414120 + # todo check that manual rate has been created @pytest.mark.xfail(reason='Test not developed')