Working Price; working test mobile with imei; update manual rate test

This commit is contained in:
Xavier Bustamante Talavera 2018-11-17 19:22:41 +01:00
parent 9c3de1c258
commit 91beed87ee
7 changed files with 58 additions and 19 deletions

View file

@ -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):

View file

@ -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):

View file

@ -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_'))

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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')