rewrite some tests to rate v2 structure

This commit is contained in:
nad 2019-05-02 17:49:15 +02:00
parent 2108526cec
commit 7bb514d23c
3 changed files with 58 additions and 17 deletions

View File

@ -9,6 +9,6 @@ device:
imei: 35686800-004141-20 imei: 35686800-004141-20
events: events:
- type: TestVisual - type: TestVisual
appearanceRange: A appearanceRange: A
functionalityRange: B functionalityRange: B
labelling: False labelling: False

View File

@ -3,22 +3,25 @@ from distutils.version import StrictVersion
import pytest import pytest
from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.models import Computer, Desktop, HardDrive, Processor, \ from ereuse_devicehub.resources.device.models import Computer, Desktop, HardDrive, Processor, \
RamModule RamModule
from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, \ from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, \
FunctionalityRange FunctionalityRange
from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, \ from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, \
BenchmarkProcessor, EreusePrice, RateComputer, TestVisual BenchmarkProcessor, RateComputer, TestVisual, Snapshot
from ereuse_devicehub.resources.event.rate.workbench.v1_0 import CannotRate
from tests import conftest from tests import conftest
from tests.conftest import file
@pytest.mark.usefixtures(conftest.auth_app_context.__name__) @pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_workbench_rate_db(): def test_workbench_rate_db():
rate = RateComputer(processor=0.1, rate = RateComputer(processor=0.1,
ram=1.0, ram=1.0,
graphic_card=0.1,
data_storage=4.1, data_storage=4.1,
graphic_card=0.1,
version=StrictVersion('1.0'), version=StrictVersion('1.0'),
device=Computer(serial_number='24', chassis=ComputerChassis.Tower)) device=Computer(serial_number='24', chassis=ComputerChassis.Tower))
db.session.add(rate) db.session.add(rate)
@ -64,9 +67,8 @@ def test_rate():
pc.events_one.add(visual_test) pc.events_one.add(visual_test)
rate, price = RateComputer.compute(pc) rate, price = RateComputer.compute(pc)
# TODO why events_one?? how to rewrite correctly this tests?? # events = pc.events
events = pc.events # price = next(e for e in events if isinstance(e, EreusePrice))
price = next(e for e in events if isinstance(e, EreusePrice))
assert price.price == Decimal('92.2001') assert price.price == Decimal('92.2001')
assert price.retailer.standard.amount == Decimal('40.9714') assert price.retailer.standard.amount == Decimal('40.9714')
assert price.platform.standard.amount == Decimal('18.8434') assert price.platform.standard.amount == Decimal('18.8434')
@ -78,3 +80,43 @@ def test_rate():
assert price.platform.warranty2.amount == Decimal('25.4357') assert price.platform.warranty2.amount == Decimal('25.4357')
assert price.refurbisher.warranty2.amount == Decimal('43.7259') assert price.refurbisher.warranty2.amount == Decimal('43.7259')
assert price.warranty2 == Decimal('124.47') assert price.warranty2 == Decimal('124.47')
def test_no_rate_if_no_workbench(user: UserClient):
"""
Checks if compute a rate from snapshot software is not from Workbench
"""
# Upload a basic snapshot
device_no_wb = file('basic.snapshot')
# Change snapshot software source
device_no_wb['software'] = 'Web'
del device_no_wb['uuid']
del device_no_wb['elapsed']
del device_no_wb['components']
# Try to compute rate
user.post(device_no_wb, res=Snapshot)
# How to assert CannotRate Exception
assert CannotRate
def test_no_rate_if_no_visual_test(user: UserClient):
"""
Checks if a rate is calculated from a snapshot without visual test
"""
# Upload a basic snapshot
device = file('basic.snapshot')
# Delete snapshot device events
del device['device']['events']
user.post(device, res=Snapshot)
# How to assert CannotRate Exception
assert CannotRate
def test_no_rate_if_device_is_not_computer(user: UserClient):
"""
Checks if a rate is calculated from a device that is not a computer.
"""
# Upload a basic snapshot of a device type
device = file('keyboard.snapshot')
user.post(device, res=Snapshot)
assert CannotRate

View File

@ -13,11 +13,12 @@ from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device import models as m from ereuse_devicehub.resources.device import models as m
from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import SolidStateDrive
from ereuse_devicehub.resources.device.sync import MismatchBetweenProperties, \ from ereuse_devicehub.resources.device.sync import MismatchBetweenProperties, \
MismatchBetweenTagsAndHid MismatchBetweenTagsAndHid
from ereuse_devicehub.resources.enums import ComputerChassis, SnapshotSoftware from ereuse_devicehub.resources.enums import ComputerChassis, SnapshotSoftware
from ereuse_devicehub.resources.event.models import BenchmarkProcessor, \ from ereuse_devicehub.resources.event.models import BenchmarkProcessor, \
EraseSectors, Event, Snapshot, SnapshotRequest, RateComputer, Rate, TestVisual, BenchmarkDataStorage EraseSectors, Event, Snapshot, SnapshotRequest, RateComputer, TestVisual, BenchmarkDataStorage
from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.tag import Tag
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User
from tests.conftest import file from tests.conftest import file
@ -241,7 +242,6 @@ def test_snapshot_tag_inner_tag(tag_id: str, user: UserClient, app: Devicehub):
b = file('basic.snapshot') b = file('basic.snapshot')
b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}] b['device']['tags'] = [{'type': 'Tag', 'id': tag_id}]
# TODO fix assert fail expected 3 and len(snapshot['events']) == 2; why? need param perform??
snapshot_and_check(user, b, snapshot_and_check(user, b,
event_types=( event_types=(
RateComputer.t, RateComputer.t,
@ -316,19 +316,18 @@ def test_erase_privacy_standards(user: UserClient):
BenchmarkDataStorage.t, BenchmarkDataStorage.t,
BenchmarkProcessor.t BenchmarkProcessor.t
), perform_second_snapshot=True) ), perform_second_snapshot=True)
# TODO fix order snapshot[events] ?? cause change in every execution?? why KeyError?? erase = next(e for e in snapshot['events'] if e['type'] == EraseSectors.t)
assert '2018-06-01T07:12:06+00:00' == snapshot['events'][0]['endTime'] assert '2018-06-01T07:12:06+00:00' == erase['endTime']
storage, *_ = snapshot['components'] storage = next(e for e in snapshot['components'] if e['type'] == SolidStateDrive.t)
assert storage['type'] == 'SolidStateDrive', 'Components must be ordered by input order'
storage, _ = user.get(res=m.Device, item=storage['id']) # Let's get storage events too storage, _ = user.get(res=m.Device, item=storage['id']) # Let's get storage events too
# order: creation time descending # order: creation time ascending
# TODO fix same order for storage['events']?? erasure1, benchmark_data_storage1, _snapshot1, erasure2, benchmark_data_storage2, _snapshot2 = storage['events']
erasure1, benchmark_data_storage1, _snapshot1, benchmark_data_storage2, erasure2, _snapshot2 = storage['events']
assert erasure1['type'] == erasure2['type'] == 'EraseSectors' assert erasure1['type'] == erasure2['type'] == 'EraseSectors'
assert benchmark_data_storage1['type'] == benchmark_data_storage2['type'] == 'BenchmarkDataStorage' assert benchmark_data_storage1['type'] == benchmark_data_storage2['type'] == 'BenchmarkDataStorage'
assert _snapshot1['type'] == _snapshot2['type'] == 'Snapshot' assert _snapshot1['type'] == _snapshot2['type'] == 'Snapshot'
get_snapshot, _ = user.get(res=Event, item=_snapshot2['id']) get_snapshot, _ = user.get(res=Event, item=_snapshot2['id'])
assert get_snapshot['events'][0]['endTime'] == '2018-06-01T07:12:06+00:00' assert get_snapshot['events'][0]['endTime'] == '2018-06-01T07:12:06+00:00'
# TODO events order are different between snapshots
assert snapshot == get_snapshot assert snapshot == get_snapshot
erasure, _ = user.get(res=Event, item=erasure1['id']) erasure, _ = user.get(res=Event, item=erasure1['id'])
assert len(erasure['steps']) == 2 assert len(erasure['steps']) == 2