debug and improve tests about rate v1

This commit is contained in:
nad 2019-05-14 20:32:24 +02:00
parent c19783954e
commit 82bf20ff3d
6 changed files with 272 additions and 161 deletions

View File

@ -1,14 +1,14 @@
Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Registered in,Price,Processor,RAM (GB),Data Storage Size (MB),Rate,Range,Processor Rate,Processor Range,RAM Rate,RAM Range,Data Storage Rate,Data Storage Range,DataStorage 1,DataStorage 1 Manufacturer,DataStorage 1 Model,DataStorage 1 Serial Number,DataStorage 2,DataStorage 2 Manufacturer,DataStorage 2 Model,DataStorage 2 Serial Number,DataStorage 3,DataStorage 3 Manufacturer,DataStorage 3 Model,DataStorage 3 Serial Number,DataStorage 4,DataStorage 4 Manufacturer,DataStorage 4 Model,DataStorage 4 Serial Number,Display 1,Display 1 Manufacturer,Display 1 Model,Display 1 Serial Number,GraphicCard 1,GraphicCard 1 Manufacturer,GraphicCard 1 Model,GraphicCard 1 Serial Number,GraphicCard 1 Memory (MB),GraphicCard 2,GraphicCard 2 Manufacturer,GraphicCard 2 Model,GraphicCard 2 Serial Number,Motherboard 1,Motherboard 1 Manufacturer,Motherboard 1 Model,Motherboard 1 Serial Number,NetworkAdapter 1,NetworkAdapter 1 Manufacturer,NetworkAdapter 1 Model,NetworkAdapter 1 Serial Number,NetworkAdapter 2,NetworkAdapter 2 Manufacturer,NetworkAdapter 2 Model,NetworkAdapter 2 Serial Number,Processor 1,Processor 1 Manufacturer,Processor 1 Model,Processor 1 Serial Number,Processor 1 Number of cores,Processor 1 Speed (GHz),Processor 2,Processor 2 Manufacturer,Processor 2 Model,Processor 2 Serial Number,RamModule 1,RamModule 1 Manufacturer,RamModule 1 Model,RamModule 1 Serial Number,RamModule 1 Size (MB),RamModule 1 Speed (MHz),RamModule 2,RamModule 2 Manufacturer,RamModule 2 Model,RamModule 2 Serial Number,RamModule 3,RamModule 3 Manufacturer,RamModule 3 Model,RamModule 3 Serial Number,RamModule 4,RamModule 4 Manufacturer,RamModule 4 Model,RamModule 4 Serial Number,SoundCard 1,SoundCard 1 Manufacturer,SoundCard 1 Model,SoundCard 1 Serial Number,SoundCard 2,SoundCard 2 Manufacturer,SoundCard 2 Model,SoundCard 2 Serial Number Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Registered in,Price,Processor,RAM (GB),Data Storage Size (MB),Rate,Range,Processor Rate,Processor Range,RAM Rate,RAM Range,Data Storage Rate,Data Storage Range,DataStorage 1,DataStorage 1 Manufacturer,DataStorage 1 Model,DataStorage 1 Serial Number,DataStorage 2,DataStorage 2 Manufacturer,DataStorage 2 Model,DataStorage 2 Serial Number,DataStorage 3,DataStorage 3 Manufacturer,DataStorage 3 Model,DataStorage 3 Serial Number,DataStorage 4,DataStorage 4 Manufacturer,DataStorage 4 Model,DataStorage 4 Serial Number,Display 1,Display 1 Manufacturer,Display 1 Model,Display 1 Serial Number,GraphicCard 1,GraphicCard 1 Manufacturer,GraphicCard 1 Model,GraphicCard 1 Serial Number,GraphicCard 1 Memory (MB),GraphicCard 2,GraphicCard 2 Manufacturer,GraphicCard 2 Model,GraphicCard 2 Serial Number,Motherboard 1,Motherboard 1 Manufacturer,Motherboard 1 Model,Motherboard 1 Serial Number,NetworkAdapter 1,NetworkAdapter 1 Manufacturer,NetworkAdapter 1 Model,NetworkAdapter 1 Serial Number,NetworkAdapter 2,NetworkAdapter 2 Manufacturer,NetworkAdapter 2 Model,NetworkAdapter 2 Serial Number,Processor 1,Processor 1 Manufacturer,Processor 1 Model,Processor 1 Serial Number,Processor 1 Number of cores,Processor 1 Speed (GHz),Processor 2,Processor 2 Manufacturer,Processor 2 Model,Processor 2 Serial Number,RamModule 1,RamModule 1 Manufacturer,RamModule 1 Model,RamModule 1 Serial Number,RamModule 1 Size (MB),RamModule 1 Speed (MHz),RamModule 2,RamModule 2 Manufacturer,RamModule 2 Model,RamModule 2 Serial Number,RamModule 3,RamModule 3 Manufacturer,RamModule 3 Model,RamModule 3 Serial Number,RamModule 4,RamModule 4 Manufacturer,RamModule 4 Model,RamModule 4 Serial Number,SoundCard 1,SoundCard 1 Manufacturer,SoundCard 1 Model,SoundCard 1 Serial Number,SoundCard 2,SoundCard 2 Manufacturer,SoundCard 2 Model,SoundCard 2 Serial Number
Laptop,Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,Wed Mar 6 18:22:05 2019,,intel atom cpu n455 @ 1.66ghz,1024,238475,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium,,,,,,,,,,,,,,,,,,,,,"GraphicCard 5: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None",,,,256,,,,,"Motherboard 10: model 1001pxd, S/N eee0123456789",eee0123456789,eee0123456789,eee0123456789,"NetworkAdapter 2: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8",74:2f:68:8b:fd:c8,74:2f:68:8b:fd:c8,74:2f:68:8b:fd:c8,"NetworkAdapter 3: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c",14:da:e9:42:f6:7c,14:da:e9:42:f6:7c,14:da:e9:42:f6:7c,"Processor 4: model intel atom cpu n455 @ 1.66ghz, S/N None",,,,1,1.667,,,,,"RamModule 8: model None, S/N None",,,,1024,667,,,,,,,,,,,,,"SoundCard 6: model nm10/ich7 family high definition audio controller, S/N None",,,,"SoundCard 7: model usb 2.0 uvc vga webcam, S/N 0x0001",0x0001,0x0001,0x0001 Laptop,Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,Wed Mar 6 18:22:05 2019,,intel atom cpu n455 @ 1.66ghz,1024,238475,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium,,,,,,,,,,,,,,,,,,,,,"GraphicCard 5: model atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller, S/N None",,,,256,,,,,"Motherboard 10: model 1001pxd, S/N eee0123456789",eee0123456789,eee0123456789,eee0123456789,"NetworkAdapter 2: model ar9285 wireless network adapter, S/N 74:2f:68:8b:fd:c8",74:2f:68:8b:fd:c8,74:2f:68:8b:fd:c8,74:2f:68:8b:fd:c8,"NetworkAdapter 3: model ar8152 v2.0 fast ethernet, S/N 14:da:e9:42:f6:7c",14:da:e9:42:f6:7c,14:da:e9:42:f6:7c,14:da:e9:42:f6:7c,"Processor 4: model intel atom cpu n455 @ 1.66ghz, S/N None",,,,1,1.667,,,,,"RamModule 8: model None, S/N None",,,,1024,667,,,,,,,,,,,,,"SoundCard 6: model nm10/ich7 family high definition audio controller, S/N None",,,,"SoundCard 7: model usb 2.0 uvc vga webcam, S/N 0x0001",0x0001,0x0001,0x0001
NetworkAdapter , , , , ,74:2f:68:8b:fd:c8 ,ar9285 wireless network adapter ,qualcomm atheros ,Wed Mar 6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium NetworkAdapter,,,,,74:2f:68:8b:fd:c8,ar9285 wireless network adapter,qualcomm atheros,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
NetworkAdapter , , , , ,14:da:e9:42:f6:7c ,ar8152 v2.0 fast ethernet ,qualcomm atheros ,Wed Mar 6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium NetworkAdapter,,,,,14:da:e9:42:f6:7c,ar8152 v2.0 fast ethernet,qualcomm atheros,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
Processor , , , , , ,intel atom cpu n455 @ 1.66ghz ,intel corp. ,Wed Mar 6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium Processor,,,,,,intel atom cpu n455 @ 1.66ghz,intel corp.,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
GraphicCard , , , , , ,atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller,intel corporation ,Wed Mar 6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium GraphicCard,,,,,,atom processor d4xx/d5xx/n4xx/n5xx integrated graphics controller,intel corporation,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
SoundCard,,,,,,nm10/ich7 family high definition audio controller,intel corporation,Wed Mar 6 18:22:05 2019,,1.73,Very low,1.0,Very low,1.53,Very low,3.76,Medium SoundCard,,,,,,nm10/ich7 family high definition audio controller,intel corporation,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
SoundCard , , , , ,0x0001 ,usb 2.0 uvc vga webcam ,azurewave ,Wed Mar 6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium SoundCard,,,,,0x0001,usb 2.0 uvc vga webcam,azurewave,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
RamModule , , , , , , , ,Wed Mar 6 18:22:05 2019, ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium RamModule,,,,,,,,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
HardDrive , , , , ,e2024242cv86hj ,hts54322 ,hitachi ,Wed Mar6 18:22:05 2019 , ,1.98 ,Very low,1.0 ,Very low,1.53 ,Very low ,3.76 ,Medium HardDrive,,,,,e2024242cv86hj,hts54322,hitachi,Wed Mar6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
Motherboard,,,,,eee0123456789,1001pxd,asustek computer inc.,Wed Mar 6 18:22:05 2019,,1.73,Very low,1.0,Very low,1.53,Very low,3.76,Medium Motherboard,,,,,eee0123456789,1001pxd,asustek computer inc.,Wed Mar 6 18:22:05 2019,,1.98,Very low,1.31,Very low,1.53,Very low,3.76,Medium
Desktop,Microtower,,,,d1s,d1ml,d1mr,Wed Mar 6 18:22:06 2019,,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 12: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 14: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 13: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,, Desktop,Microtower,,,,d1s,d1ml,d1mr,Wed Mar 6 18:22:06 2019,,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 12: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 14: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 13: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,
GraphicCard,,,,,gc1s,gc1ml,gc1mr,Wed Mar 6 18:22:06 2019,,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low GraphicCard,,,,,gc1s,gc1ml,gc1mr,Wed Mar 6 18:22:06 2019,,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low
RamModule,,,,,rm1s,rm1ml,rm1mr,Wed Mar 6 18:22:06 2019,,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low RamModule,,,,,rm1s,rm1ml,rm1mr,Wed Mar 6 18:22:06 2019,,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low

Can't render this file because it contains an unexpected character in line 2 and column 1818.

View File

@ -1,15 +1,15 @@
from decimal import Decimal from decimal import Decimal
from distutils.version import StrictVersion from distutils.version import StrictVersion
import math
import pytest import pytest
from ereuse_devicehub.client import UserClient from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \ from ereuse_devicehub.resources.action.models import Action, BenchmarkDataStorage, \
BenchmarkProcessor, RateComputer, Snapshot, VisualTest BenchmarkProcessor, RateComputer, Snapshot, VisualTest
from ereuse_devicehub.resources.action.rate.workbench.v1_0 import CannotRate
from ereuse_devicehub.resources.device.models import Computer, Desktop, Device, HardDrive, \ from ereuse_devicehub.resources.device.models import Computer, Desktop, Device, HardDrive, \
Processor, RamModule Processor, RamModule, SolidStateDrive
from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, \ from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, \
FunctionalityRange FunctionalityRange
from tests import conftest from tests import conftest
@ -28,27 +28,36 @@ def test_workbench_rate_db():
db.session.commit() db.session.commit()
@pytest.mark.xfail(reson='Adapt rate algorithm to re-compute by passing a manual rate.') # TODO JN is necessary this test if in test multiples rates we are checking same case??
def test_manual_rate_after_workbench_rate(user: UserClient): def test_rate_with_multiple_visual_tests(user: UserClient):
"""Perform a WorkbenchRate and then update the device with a ManualRate. """Perform a ComputerRate and then update the device with a new VisualTest.
Devicehub must make the final rate with the first workbench rate Devicehub must make the final rate with the first computer rate
plus the new manual rate, without considering the appearance / plus the new visual test, without considering the appearance /
functionality values of the workbench rate. functionality values of the computer rate.
""" """
s = file('real-hp.snapshot.11') s = file('real-hp.snapshot.11')
snapshot, _ = user.post(s, res=Snapshot) snapshot, _ = user.post(s, res=Snapshot)
device, _ = user.get(res=Device, item=snapshot['device']['id']) device, _ = user.get(res=Device, item=snapshot['device']['id'])
assert 'B' == device['rate']['appearanceRange'] visual_test = next(e for e in reversed(device['actions']) if e['type'] == VisualTest.t)
assert device['rate'] == 1
assert visual_test['appearanceRange'] == 'B'
assert visual_test['functionalityRange'] == 'D'
assert device['rate']['rating'] == 2
# Adding new visual test
user.post({ user.post({
'type': 'ManualRate', 'type': 'VisualTest',
'device': device['id'], 'device': device['id'],
'appearanceRange': 'A', 'appearanceRange': 'A',
'functionalityRange': 'A' 'functionalityRange': 'A'
}, res=Action) }, res=Action)
device, _ = user.get(res=Device, item=snapshot['device']['id']) device, _ = user.get(res=Device, item=snapshot['device']['id'])
assert 'A' == device['rate']['appearanceRange'] visual_test = next(e for e in reversed(device['actions']) if e['type'] == VisualTest.t)
assert visual_test['appearanceRange'] == 'A'
assert visual_test['functionalityRange'] == 'A'
assert device['rate']['rating'] == 3.7
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
@ -71,16 +80,13 @@ def test_price_from_rate():
VisualTest(appearance_range=AppearanceRange.A, VisualTest(appearance_range=AppearanceRange.A,
functionality_range=FunctionalityRange.A, functionality_range=FunctionalityRange.A,
device=pc) device=pc)
rate, price = RateComputer.compute(pc) _, price = RateComputer.compute(pc)
# actions = pc.actions
# price = next(e for e in actions 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')
assert price.refurbisher.standard.amount == Decimal('32.3853') assert price.refurbisher.standard.amount == Decimal('32.3853')
assert price.price >= price.retailer.standard.amount \ assert price.price >= price.retailer.standard.amount + price.platform.standard.amount \
+ price.platform.standard.amount \
+ price.refurbisher.standard.amount + price.refurbisher.standard.amount
assert price.retailer.warranty2.amount == Decimal('55.3085') assert price.retailer.warranty2.amount == Decimal('55.3085')
assert price.platform.warranty2.amount == Decimal('25.4357') assert price.platform.warranty2.amount == Decimal('25.4357')
@ -88,48 +94,44 @@ def test_price_from_rate():
assert price.warranty2 == Decimal('124.47') assert price.warranty2 == Decimal('124.47')
def test_no_rate_if_no_workbench(user: UserClient): def test_when_rate_must_not_compute(user: UserClient):
""" """
Checks if compute a rate from snapshot software is not from Workbench Test to check if rate is computed in case of should not be calculated:
1. Snapshot haven't visual test
2. Snapshot software aren't Workbench
3. Device type are not Computer
...
""" """
# Upload a basic snapshot # Checking case 1
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
s = file('basic.snapshot') s = file('basic.snapshot')
# Delete snapshot device actions # Delete snapshot device actions to delete VisualTest
del s['device']['actions'] del s['device']['actions']
# Post to compute rate and check to didn't do it
snapshot, _ = user.post(s, res=Snapshot)
assert 'rate' not in snapshot['device']
# Checking case 2
s = file('basic.snapshot')
# Change snapshot software source
s['software'] = 'Web'
del s['uuid']
del s['elapsed']
del s['components']
# Post to compute rate and check to didn't do it
snapshot, _ = user.post(s, res=Snapshot)
assert 'rate' not in snapshot['device']
# Checking case 3
s = file('keyboard.snapshot')
# Post to compute rate and check to didn't do it
snapshot, _ = user.post(s, res=Snapshot) snapshot, _ = user.post(s, res=Snapshot)
device, _ = user.get(res=Device, item=snapshot['device']['id'])
# How to assert CannotRate Exception
assert 'rate' not in snapshot['device'] assert 'rate' not in snapshot['device']
def test_no_rate_if_device_is_not_computer(user: UserClient): @pytest.mark.usefixtures(conftest.app_context.__name__)
"""
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
@pytest.mark.xfail(reason='Test not developed')
def test_multiple_rates(user: UserClient): def test_multiple_rates(user: UserClient):
"""Tests submitting two rates from Workbench, """Tests submitting two rates from Workbench,
ensuring that the tests / benchmarks... ensuring that the tests / benchmarks...
@ -138,3 +140,73 @@ def test_multiple_rates(user: UserClient):
This ensures that rates only takes the last version of actions This ensures that rates only takes the last version of actions
and components (in case device has new components, for example). and components (in case device has new components, for example).
""" """
pc = Desktop(chassis=ComputerChassis.Tower)
hdd = HardDrive(size=476940)
hdd.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
cpu = Processor(cores=2, speed=3.4)
cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
pc.components = {
hdd,
RamModule(size=4096, speed=1600),
RamModule(size=2048, speed=1600),
cpu
}
# Add test visual with functionality and appearance range
VisualTest(appearance_range=AppearanceRange.A,
functionality_range=FunctionalityRange.A,
device=pc)
rate1, price1 = RateComputer.compute(pc)
# asserts rate1 ...
# TODO JN is also necessary add asserts for component_range??
assert rate1.data_storage == 4.02
assert rate1.processor == 3.95
assert rate1.ram == 3.8
assert rate1.appearance == 0.3
assert rate1.functionality == 0.4
assert rate1.rating == 4.62
# assert rate1.rating_range == 'High'
# TODO JN better option to get and assert price??
assert price1.price == Decimal('92.4001')
assert math.isclose(rate1.price.price, 92.40, rel_tol=0.001)
hdd = SolidStateDrive(size=476940)
hdd.actions_one.add(BenchmarkDataStorage(read_speed=222, write_speed=169))
cpu = Processor(cores=1, speed=3.0)
cpu.actions_one.add(BenchmarkProcessor(rate=16069.44))
# TODO JN best form to update pc components/benchmarks??
pc.components = {
hdd,
RamModule(size=2048, speed=1067),
RamModule(size=2048, speed=1067),
cpu
}
# Add test visual with functionality and appearance range
VisualTest(appearance_range=AppearanceRange.B,
functionality_range=FunctionalityRange.B,
device=pc)
# asserts pc characteristics/benchmarks/tests change
rate2, price2 = RateComputer.compute(pc)
# asserts rate2 ...
assert rate2.data_storage == 4.27
assert rate2.processor == 3.61
assert rate2.ram == 4.12
assert rate2.appearance == 0
assert rate2.functionality == -0.5
assert rate2.rating == 3.37
# assert rate2.rating_range == 'Medium'
assert rate2.price.price == Decimal('67.4001')
assert math.isclose(price2.price, 67.40, rel_tol=0.001)

View File

@ -1,18 +1,24 @@
""" """
Tests of compute rating for every component in a Device This file test all corner cases when compute score v1.0.
Rates test done:
First test to compute rate for every component in isolation
todo rewrite some corner cases using range(min,max) characteristics
in devices/schemas
Components in Score v1:
-DataStorage -DataStorage
-RamModule -RamModule
-Processor -Processor
Then some test compute rate with all components that use the a1lgorithm
Excluded cases in tests Excluded cases in tests
- No Processor - No Processor
- No indispensable Benchmarks (Processor and Data Storage)
- -
""" """
import math import math
import pytest import pytest
from ereuse_devicehub.resources.action.models import BenchmarkDataStorage, BenchmarkProcessor, \ from ereuse_devicehub.resources.action.models import BenchmarkDataStorage, BenchmarkProcessor, \
@ -21,6 +27,7 @@ from ereuse_devicehub.resources.action.rate.workbench.v1_0 import DataStorageRat
RamRate, RateAlgorithm RamRate, RateAlgorithm
from ereuse_devicehub.resources.device.models import Desktop, HardDrive, Processor, RamModule from ereuse_devicehub.resources.device.models import Desktop, HardDrive, Processor, RamModule
from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, FunctionalityRange from ereuse_devicehub.resources.enums import AppearanceRange, ComputerChassis, FunctionalityRange
from tests import conftest
def test_rate_data_storage_rate(): def test_rate_data_storage_rate():
@ -77,15 +84,13 @@ def test_rate_no_data_storage():
""" """
Test without data storage devices Test without data storage devices
""" """
hdd_null = HardDrive() hdd_null = HardDrive()
hdd_null.actions_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0)) hdd_null.actions_one.add(BenchmarkDataStorage(read_speed=0, write_speed=0))
data_storage_rate = DataStorageRate().compute([hdd_null]) data_storage_rate = DataStorageRate().compute([hdd_null])
assert data_storage_rate is None assert data_storage_rate is None
# RAM MODULE DEVICE TEST
def test_rate_ram_rate(): def test_rate_ram_rate():
""" """
Test to check if compute ram rate have same value than previous score version Test to check if compute ram rate have same value than previous score version
@ -169,8 +174,6 @@ def test_rate_no_ram_module():
assert ram_rate is None assert ram_rate is None
# PROCESSOR DEVICE TEST
def test_rate_processor_rate(): def test_rate_processor_rate():
""" """
Test to check if compute processor rate have same value than previous score version Test to check if compute processor rate have same value than previous score version
@ -208,12 +211,15 @@ def test_rate_processor_rate_2cores():
assert math.isclose(processor_rate, 3.93, rel_tol=0.002) assert math.isclose(processor_rate, 3.93, rel_tol=0.002)
# TODO JN if delete processor default score for benchmark_cpu
def test_rate_processor_with_null_cores(): def test_rate_processor_with_null_cores():
""" """
Test with processor device have null number of cores Test with processor device have null number of cores
""" """
cpu = Processor(cores=None, speed=3.3) cpu = Processor(cores=None, speed=3.3)
cpu.actions_one.add(BenchmarkProcessor()) cpu.actions_one.add(BenchmarkProcessor(rate=0))
processor_rate = ProcessorRate().compute(cpu) processor_rate = ProcessorRate().compute(cpu)
@ -232,12 +238,20 @@ def test_rate_processor_with_null_speed():
assert math.isclose(processor_rate, 1.06, rel_tol=0.001) assert math.isclose(processor_rate, 1.06, rel_tol=0.001)
def test_rate_computer_rate(): # TODO JN add price asserts in rate computers??
""" Test rate v1
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_rate_computer_1193():
"""
Test rate computer characteristics:
- 2 module ram
- processor with 2 cores
Data get it from R score from DH pc with id = 1193
pc_1193 = Computer() pc_1193 = Computer()
price = 92.2 price = 92.2
# add components characteristics of pc with id = 1193
hdd_1969 = HardDrive(size=476940) hdd_1969 = HardDrive(size=476940)
hdd_1969.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8)) hdd_1969.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
ram1 = RamModule(size=4096, speed=1600) ram1 = RamModule(size=4096, speed=1600)
@ -245,67 +259,14 @@ def test_rate_computer_rate():
cpu = Processor(cores=2, speed=3.4) cpu = Processor(cores=2, speed=3.4)
cpu.actions_one.add(BenchmarkProcessor(rate=27136.44)) cpu.actions_one.add(BenchmarkProcessor(rate=27136.44))
pc_1193.components.add(hdd_1969, ram1, ram2, cpu) pc_1193.components.add(hdd_1969, ram1, ram2, cpu)
# add functionality and appearance range rate_pc_1193 = WorkbenchRate(appearance_range=AppearanceRange.A,
rate_pc_1193 = WorkbenchRate(appearance_range=AppearanceRange.A, functionality_range=FunctionalityRange.A) functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 4.02 HDD_rate = 4.02
RAM_rate = 3.79 RAM_rate = 3.79
Processor_rate = 3.95 Processor_rate = 3.95
Rating = 4.61 Rating = 4.61
pc_1201 = Computer()
price = 69.6
hdd_3054 = HardDrive(size=476940)
hdd_3054.actions_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7))
ram1 = RamModule(size=2048, speed=1333)
cpu = Processor(cores=2, speed=3.3)
cpu.actions_one.add(BenchmarkProcessor(rate=26339.48))
pc_1201.components.add(hdd_3054, ram1, cpu)
# add functionality and appearance range
rate_pc_1201 = WorkbenchRate(appearance_range=AppearanceRange.B, functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 4.07
RAM_rate = 2.02
Processor_rate = 3.93
Rating = 3.48
pc_79 = Computer()
price = VeryLow
hdd_81 = HardDrive(size=76319)
hdd_81.actions_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
ram1 = RamModule(size=512, speed=667)
ram2 = RamModule(size=512, speed=800)
ram3 = RamModule(size=512, speed=667)
ram4 = RamModule(size=512, speed=533)
cpu = Processor(cores=1, speed=1.6)
cpu.actions_one.add(BenchmarkProcessor(rate=3192.34))
pc_79.components.add(hdd_81, ram1, ram2, ram3, ram4, cpu)
# add functionality and appearance range
rate_pc_79 = WorkbenchRate(appearance_range=AppearanceRange.C, functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 2.61
RAM_rate = 1.99
Processor_rate = 1
Rating = 1.58
pc_798 = Computer()
price = 50
hdd_1556 = HardDrive(size=152587)
hdd_1556.actions_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))
ram0 = RamModule(size=0, speed=None)
cpu = Processor(cores=2, speed=2.5)
cpu.actions_one.add(BenchmarkProcessor(rate=9974.3))
pc_798.components.add(hdd_1556, ram0, cpu)
# add functionality and appearance range
rate_pc_798 = WorkbenchRate(appearance_range=AppearanceRange.B, functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 3.7
RAM_rate = 1
Processor_rate = 4.09
Rating = 2.5
""" """
# Create a new Computer with components characteristics of pc with id = 1193
pc_test = Desktop(chassis=ComputerChassis.Tower) pc_test = Desktop(chassis=ComputerChassis.Tower)
data_storage = HardDrive(size=476940) data_storage = HardDrive(size=476940)
data_storage.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8)) data_storage.actions_one.add(BenchmarkDataStorage(read_speed=126, write_speed=29.8))
@ -333,7 +294,32 @@ def test_rate_computer_rate():
assert math.isclose(rate_pc.rating, 4.61, rel_tol=0.001) assert math.isclose(rate_pc.rating, 4.61, rel_tol=0.001)
# Create a new Computer with components characteristics of pc with id = 1201
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_rate_computer_1201():
"""
Test rate computer characteristics:
- only 1 module ram
- processor 2 cores
Data get it from R score from DH pc with id = 1201
pc_1201 = Computer()
price = 69.6
hdd_3054 = HardDrive(size=476940)
hdd_3054.actions_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7))
ram1 = RamModule(size=2048, speed=1333)
cpu = Processor(cores=2, speed=3.3)
cpu.actions_one.add(BenchmarkProcessor(rate=26339.48))
pc_1201.components.add(hdd_3054, ram1, cpu)
rate_pc_1201 = WorkbenchRate(appearance_range=AppearanceRange.B,
functionality_range=FunctionalityRange.A)
HDD_rate = 4.07
RAM_rate = 2.02
Processor_rate = 3.93
Rating = 3.48
"""
pc_test = Desktop(chassis=ComputerChassis.Tower) pc_test = Desktop(chassis=ComputerChassis.Tower)
data_storage = HardDrive(size=476940) data_storage = HardDrive(size=476940)
data_storage.actions_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7)) data_storage.actions_one.add(BenchmarkDataStorage(read_speed=158, write_speed=34.7))
@ -360,7 +346,37 @@ def test_rate_computer_rate():
assert math.isclose(rate_pc.rating, 3.48, rel_tol=0.001) assert math.isclose(rate_pc.rating, 3.48, rel_tol=0.001)
# Create a new Computer with components characteristics of pc with id = 79
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_rate_computer_multiple_ram_module():
"""
Test rate computer characteristics:
- only 1 module ram
- processor 2 cores
Data get it from R score from DH pc with id = 79
pc_79 = Computer()
price = VeryLow
hdd_81 = HardDrive(size=76319)
hdd_81.actions_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
ram1 = RamModule(size=512, speed=667)
ram2 = RamModule(size=512, speed=800)
ram3 = RamModule(size=512, speed=667)
ram4 = RamModule(size=512, speed=533)
cpu = Processor(cores=1, speed=1.6)
cpu.actions_one.add(BenchmarkProcessor(rate=3192.34))
pc_79.components.add(hdd_81, ram1, ram2, ram3, ram4, cpu)
# add functionality and appearance range
rate_pc_79 = WorkbenchRate(appearance_range=AppearanceRange.C,
functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 2.61
RAM_rate = 1.99
Processor_rate = 1
Rating = 1.58
"""
pc_test = Desktop(chassis=ComputerChassis.Tower) pc_test = Desktop(chassis=ComputerChassis.Tower)
data_storage = HardDrive(size=76319) data_storage = HardDrive(size=76319)
data_storage.actions_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3)) data_storage.actions_one.add(BenchmarkDataStorage(read_speed=72.2, write_speed=24.3))
@ -389,7 +405,34 @@ def test_rate_computer_rate():
assert rate_pc.rating == 1.57 assert rate_pc.rating == 1.57
# Create a new Computer with components characteristics of pc with id = 798
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
def test_rate_computer_one_ram_module():
"""
Test rate computer characteristics:
- only 1 module ram
- processor 2 cores
Data get it from R score from DH pc with id = 798
pc_798 = Computer()
price = 50
hdd_1556 = HardDrive(size=152587)
hdd_1556.actions_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))
ram0 = RamModule(size=0, speed=None)
cpu = Processor(cores=2, speed=2.5)
cpu.actions_one.add(BenchmarkProcessor(rate=9974.3))
pc_798.components.add(hdd_1556, ram0, cpu)
# add functionality and appearance range
rate_pc_798 = WorkbenchRate(appearance_range=AppearanceRange.B,
functionality_range=FunctionalityRange.A)
# add component rate
HDD_rate = 3.7
RAM_rate = 1
Processor_rate = 4.09
Rating = 2.5
"""
pc_test = Desktop(chassis=ComputerChassis.Tower) pc_test = Desktop(chassis=ComputerChassis.Tower)
data_storage = HardDrive(size=152587) data_storage = HardDrive(size=152587)
data_storage.actions_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4)) data_storage.actions_one.add(BenchmarkDataStorage(read_speed=78.1, write_speed=24.4))

View File

@ -135,15 +135,7 @@ def test_export_keyboard(user: UserClient):
assert fixture_csv[1] == export_csv[1], 'Component information are not equal' assert fixture_csv[1] == export_csv[1], 'Component information are not equal'
@pytest.mark.xfail(reson='Need to develop.') # TODO JN fix why components also have all rate fields
def test_export_multiple_computers(user: UserClient):
"""
Test to export multiples computers devices
"""
pass
@pytest.mark.xfail(reson='Need to debug and rewrite it.')
def test_export_multiple_different_devices(user: UserClient): def test_export_multiple_different_devices(user: UserClient):
""" """
Test a export multiple different device types (like computers, keyboards, monitors, ...) Test a export multiple different device types (like computers, keyboards, monitors, ...)
@ -154,7 +146,6 @@ def test_export_multiple_different_devices(user: UserClient):
snapshot_keyboard, _ = user.post(file('keyboard.snapshot'), res=Snapshot) snapshot_keyboard, _ = user.post(file('keyboard.snapshot'), res=Snapshot)
snapshot_monitor, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) snapshot_monitor, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot)
# need query param??
csv_str, _ = user.get(res=documents.DocumentDef.t, csv_str, _ = user.get(res=documents.DocumentDef.t,
item='devices/', item='devices/',
accept='text/csv') accept='text/csv')
@ -178,3 +169,11 @@ def test_export_multiple_different_devices(user: UserClient):
fixture_csv[i] = fixture_csv[i][:8] + fixture_csv[i][9:] fixture_csv[i] = fixture_csv[i][:8] + fixture_csv[i][9:]
assert fixture_csv[i] == export_csv[i], 'Some fields are not equal' assert fixture_csv[i] == export_csv[i], 'Some fields are not equal'
@pytest.mark.xfail(reason='Debug why rate computed correctly but when get info change value')
def test_temp_rate_rating(user: UserClient):
snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot)
from ereuse_devicehub.resources.device.models import Device
device, _ = user.get(res=Device, item=snapshot['device']['id'])
assert device['rate']['rating'] == 1.98

View File

@ -127,9 +127,7 @@ def test_snapshot_component_add_remove(user: UserClient):
# Components contain parent # Components contain parent
assert all(c['parent'] == pc1_id for c in pc1['components']) assert all(c['parent'] == pc1_id for c in pc1['components'])
# pc has two actions: Snapshot and the BenchmarkProcessor # pc has two actions: Snapshot and the BenchmarkProcessor
# TODO change assert to len(pc1['actions']) == 2 cause we add BenchmarkProcessor action
assert len(pc1['actions']) == 2 assert len(pc1['actions']) == 2
# TODO pc1['actions'][0]['type'] == BenchmarkProcessor.t
assert pc1['actions'][1]['type'] == Snapshot.t assert pc1['actions'][1]['type'] == Snapshot.t
# p1c1s has Snapshot # p1c1s has Snapshot
p1c1s, _ = user.get(res=m.Device, item=pc1['components'][0]['id']) p1c1s, _ = user.get(res=m.Device, item=pc1['components'][0]['id'])
@ -384,11 +382,10 @@ def test_test_data_storage(user: UserClient):
assert incidence_test['severity'] == 'Error' assert incidence_test['severity'] == 'Error'
# TODO change to RateMonitor
@pytest.mark.xfail(reason='Not implemented yet, new rate is need it') @pytest.mark.xfail(reason='Not implemented yet, new rate is need it')
def test_snapshot_computer_monitor(user: UserClient): def test_snapshot_computer_monitor(user: UserClient):
s = file('computer-monitor.snapshot') s = file('computer-monitor.snapshot')
snapshot_and_check(user, s, action_types=('ManualRate',)) snapshot_and_check(user, s, action_types=('RateMonitor',))
# todo check that ManualRate has generated an AggregateRate # todo check that ManualRate has generated an AggregateRate
@ -398,7 +395,6 @@ def test_snapshot_mobile_smartphone_imei_manual_rate(user: UserClient):
snapshot = snapshot_and_check(user, s, action_types=('VisualTest',)) snapshot = snapshot_and_check(user, s, action_types=('VisualTest',))
mobile, _ = user.get(res=m.Device, item=snapshot['device']['id']) mobile, _ = user.get(res=m.Device, item=snapshot['device']['id'])
assert mobile['imei'] == 3568680000414120 assert mobile['imei'] == 3568680000414120
# todo check that manual rate has been created
@pytest.mark.xfail(reason='Test not developed') @pytest.mark.xfail(reason='Test not developed')
@ -484,11 +480,10 @@ def snapshot_and_check(user: UserClient,
return snapshot return snapshot
# TODO change to which Rate??
@pytest.mark.xfail(reason='Not implemented yet, new rate is need it') @pytest.mark.xfail(reason='Not implemented yet, new rate is need it')
def test_snapshot_keyboard(user: UserClient): def test_snapshot_keyboard(user: UserClient):
s = file('keyboard.snapshot') s = file('keyboard.snapshot')
snapshot = snapshot_and_check(user, s, action_types=('ManualRate',)) snapshot = snapshot_and_check(user, s, action_types=('VisualTest',))
keyboard = snapshot['device'] keyboard = snapshot['device']
assert keyboard['layout'] == 'ES' assert keyboard['layout'] == 'ES'

View File

@ -9,6 +9,7 @@ import pytest
from ereuse_devicehub.client import UserClient from ereuse_devicehub.client import UserClient
from ereuse_devicehub.resources.action import models as em from ereuse_devicehub.resources.action import models as em
from ereuse_devicehub.resources.action.models import VisualTest, RateComputer
from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.device.models import Device
from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tag.model import Tag
@ -61,8 +62,9 @@ def test_workbench_server_condensed(user: UserClient):
assert device['rate']['closed'] assert device['rate']['closed']
assert device['rate']['severity'] == 'Info' assert device['rate']['severity'] == 'Info'
assert device['rate']['rating'] == 0 assert device['rate']['rating'] == 0
assert device['rate']['type'] == 'RateComputer' assert device['rate']['type'] == RateComputer.t
assert device['actions'][2]['type'] == 'VisualTest' # TODO JN why haven't same order in actions??
assert device['actions'][2]['type'] == VisualTest.t
assert device['actions'][2]['appearanceRange'] == 'A' assert device['actions'][2]['appearanceRange'] == 'A'
assert device['actions'][2]['functionalityRange'] == 'B' assert device['actions'][2]['functionalityRange'] == 'B'
assert device['tags'][0]['id'] == 'tag1' assert device['tags'][0]['id'] == 'tag1'