Merge branch 'testing' into bugfix/79-manual-merge
This commit is contained in:
commit
725e586e85
|
@ -1163,6 +1163,7 @@ class EreusePrice(Price):
|
|||
value agreed by a circuit or platform.
|
||||
"""
|
||||
MULTIPLIER = {
|
||||
Computer: 20,
|
||||
Desktop: 20,
|
||||
Laptop: 30
|
||||
}
|
||||
|
@ -1205,7 +1206,7 @@ class EreusePrice(Price):
|
|||
}
|
||||
}
|
||||
}
|
||||
SCHEMA[Server] = SCHEMA[Desktop]
|
||||
SCHEMA[Server] = SCHEMA[Computer] = SCHEMA[Desktop]
|
||||
|
||||
def __init__(self, device, rating_range, role, price: Decimal) -> None:
|
||||
cls = device.__class__ if device.__class__ != Server else Desktop
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import json
|
||||
import shutil
|
||||
from datetime import datetime
|
||||
from distutils.version import StrictVersion
|
||||
from uuid import UUID
|
||||
|
@ -32,13 +33,17 @@ def save_json(req_json, tmp_snapshots, user):
|
|||
month = now.month
|
||||
day = now.day
|
||||
hour = now.hour
|
||||
minutes = now.min
|
||||
minutes = now.minute
|
||||
|
||||
name_file = f"{year}-{month}-{day}-{hour}-{minutes}_{user}_{uuid}.json"
|
||||
path_name = os.path.join(tmp_snapshots, name_file)
|
||||
path_dir_base = os.path.join(tmp_snapshots, user)
|
||||
path_errors = os.path.join(path_dir_base, 'errors')
|
||||
path_fixeds = os.path.join(path_dir_base, 'fixeds')
|
||||
path_name = os.path.join(path_errors, name_file)
|
||||
|
||||
if not os.path.isdir(tmp_snapshots):
|
||||
os.system('mkdir -p {}'.format(tmp_snapshots))
|
||||
if not os.path.isdir(path_dir_base):
|
||||
os.system(f'mkdir -p {path_errors}')
|
||||
os.system(f'mkdir -p {path_fixeds}')
|
||||
|
||||
with open(path_name, 'w') as snapshot_file:
|
||||
snapshot_file.write(json.dumps(req_json))
|
||||
|
@ -46,12 +51,23 @@ def save_json(req_json, tmp_snapshots, user):
|
|||
return path_name
|
||||
|
||||
|
||||
def move_json(tmp_snapshots, path_name, user):
|
||||
"""
|
||||
This function move the json than it's correct
|
||||
"""
|
||||
path_dir_base = os.path.join(tmp_snapshots, user)
|
||||
if os.path.isfile(path_name):
|
||||
shutil.copy(path_name, path_dir_base)
|
||||
os.remove(path_name)
|
||||
|
||||
|
||||
class ActionView(View):
|
||||
def post(self):
|
||||
"""Posts an action."""
|
||||
json = request.get_json(validate=False)
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_snapshot = save_json(json, tmp_snapshots, g.user.email)
|
||||
json.pop('debug', None)
|
||||
if not json or 'type' not in json:
|
||||
raise ValidationError('Resource needs a type.')
|
||||
# todo there should be a way to better get subclassess resource
|
||||
|
@ -60,13 +76,13 @@ class ActionView(View):
|
|||
a = resource_def.schema.load(json)
|
||||
if json['type'] == Snapshot.t:
|
||||
response = self.snapshot(a, resource_def)
|
||||
os.remove(path_snapshot)
|
||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
||||
return response
|
||||
if json['type'] == VisualTest.t:
|
||||
pass
|
||||
# TODO JN add compute rate with new visual test and old components device
|
||||
if json['type'] == InitTransfer.t:
|
||||
os.remove(path_snapshot)
|
||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
||||
return self.transfer_ownership()
|
||||
Model = db.Model._decl_class_registry.data[json['type']]()
|
||||
action = Model(**a)
|
||||
|
@ -75,7 +91,7 @@ class ActionView(View):
|
|||
ret = self.schema.jsonify(action)
|
||||
ret.status_code = 201
|
||||
db.session.commit()
|
||||
os.remove(path_snapshot)
|
||||
move_json(tmp_snapshots, path_snapshot, g.user.email)
|
||||
return ret
|
||||
|
||||
def one(self, id: UUID):
|
||||
|
|
|
@ -28,7 +28,7 @@ from teal.resource import url_for_resource
|
|||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.resources.enums import BatteryTechnology, CameraFacing, ComputerChassis, \
|
||||
DataStorageInterface, DisplayTech, PrinterTechnology, RamFormat, RamInterface, Severity, TransferState
|
||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing
|
||||
from ereuse_devicehub.resources.models import STR_SM_SIZE, Thing, listener_reset_field_updated_in_actual_time
|
||||
from ereuse_devicehub.resources.user.models import User
|
||||
|
||||
|
||||
|
@ -881,3 +881,6 @@ class Manufacturer(db.Model):
|
|||
'COPY common.manufacturer FROM STDIN (FORMAT csv)',
|
||||
f
|
||||
)
|
||||
|
||||
|
||||
listener_reset_field_updated_in_actual_time(Device)
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
from datetime import datetime, timezone
|
||||
from flask_sqlalchemy import event
|
||||
|
||||
from ereuse_devicehub.db import db
|
||||
|
||||
|
@ -34,3 +35,12 @@ class Thing(db.Model):
|
|||
# to be able to use sorted containers
|
||||
self.created = kwargs.get('created', datetime.now(timezone.utc))
|
||||
super().__init__(**kwargs)
|
||||
|
||||
|
||||
def update_object_timestamp(mapper, connection, thing_obj):
|
||||
""" This function update the stamptime of field updated """
|
||||
thing_obj.updated = datetime.now(timezone.utc)
|
||||
|
||||
def listener_reset_field_updated_in_actual_time(thing_obj):
|
||||
""" This function launch a event than listen like a signal when some object is saved """
|
||||
event.listen(thing_obj, 'before_update', update_object_timestamp, propagate=True)
|
||||
|
|
|
@ -134,6 +134,12 @@ def file(name: str) -> dict:
|
|||
return yaml.load(f)
|
||||
|
||||
|
||||
def file_workbench(name: str) -> dict:
|
||||
"""Opens and parses a YAML file from the ``files`` subdir."""
|
||||
with Path(__file__).parent.joinpath('workbench_files').joinpath(name + '.json').open() as f:
|
||||
return yaml.load(f)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def tag_id(app: Devicehub) -> str:
|
||||
"""Creates a tag and returns its id."""
|
||||
|
|
126
tests/files/basic.snapshot.with_debug.yaml
Normal file
126
tests/files/basic.snapshot.with_debug.yaml
Normal file
|
@ -0,0 +1,126 @@
|
|||
{
|
||||
"elapsed": 4,
|
||||
"type": "Snapshot",
|
||||
"uuid": "0c822fb7-6e51-4781-86cf-994bd306212e",
|
||||
"software": "Workbench",
|
||||
"closed": false,
|
||||
"endTime": "2018-07-05T11:57:17.284891+00:00",
|
||||
"components": [
|
||||
{
|
||||
"type": "NetworkAdapter",
|
||||
"model": "82567LM-3 Gigabit Network Connection",
|
||||
"speed": 1000,
|
||||
"serialNumber": "00:23:24:0d:86:28",
|
||||
"manufacturer": "Intel Corporation",
|
||||
"wireless": false,
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"type": "NetworkAdapter",
|
||||
"model": "82541PI Gigabit Ethernet Controller",
|
||||
"speed": 1000,
|
||||
"serialNumber": "00:0e:0c:b6:f2:91",
|
||||
"manufacturer": "Intel Corporation",
|
||||
"wireless": false,
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"cores": 4,
|
||||
"type": "Processor",
|
||||
"model": "Intel Core2 Quad CPU Q8400 @ 2.66GHz",
|
||||
"speed": 1.9980000000000002,
|
||||
"serialNumber": null,
|
||||
"manufacturer": "Intel Corp.",
|
||||
"actions": [
|
||||
{
|
||||
"elapsed": 0,
|
||||
"rate": 6665.7,
|
||||
"type": "BenchmarkProcessor"
|
||||
}
|
||||
],
|
||||
"address": 64
|
||||
},
|
||||
{
|
||||
"type": "GraphicCard",
|
||||
"model": "4 Series Chipset Integrated Graphics Controller",
|
||||
"serialNumber": null,
|
||||
"manufacturer": "Intel Corporation",
|
||||
"actions": [],
|
||||
"memory": 256.0
|
||||
},
|
||||
{
|
||||
"type": "SoundCard",
|
||||
"model": "82801JD/DO HD Audio Controller",
|
||||
"serialNumber": null,
|
||||
"manufacturer": "Intel Corporation",
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"size": 2048,
|
||||
"interface": "DDR3",
|
||||
"type": "RamModule",
|
||||
"model": "16JTF25664AZ-1G4F",
|
||||
"speed": 1333.0,
|
||||
"serialNumber": "F8482E29",
|
||||
"format": "DIMM",
|
||||
"manufacturer": "JEDEC ID:80 2C",
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"size": 2048,
|
||||
"interface": "DDR3",
|
||||
"type": "RamModule",
|
||||
"model": "16JTF25664AZ-1G4F",
|
||||
"speed": 1333.0,
|
||||
"serialNumber": "62072F30",
|
||||
"format": "DIMM",
|
||||
"manufacturer": "JEDEC ID:80 2C",
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"size": 238475,
|
||||
"interface": "ATA",
|
||||
"type": "HardDrive",
|
||||
"model": "ST3250318AS",
|
||||
"serialNumber": "9VY6HBKE",
|
||||
"manufacturer": "Seagate",
|
||||
"actions": [
|
||||
{
|
||||
"elapsed": 0,
|
||||
"type": "TestDataStorage",
|
||||
"status": "Unspecified Error. Self-test not started.",
|
||||
"severity": "Error",
|
||||
"length": "Short"
|
||||
},
|
||||
{
|
||||
"type": "BenchmarkDataStorage",
|
||||
"elapsed": 16,
|
||||
"readSpeed": 66.2,
|
||||
"writeSpeed": 21.8
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"slots": 0,
|
||||
"pcmcia": 0,
|
||||
"type": "Motherboard",
|
||||
"model": "3646h",
|
||||
"serialNumber": "CZC03217S7",
|
||||
"firewire": 0,
|
||||
"manufacturer": "Hewlett-Packard",
|
||||
"actions": [],
|
||||
"serial": 0,
|
||||
"usb": 8
|
||||
}
|
||||
],
|
||||
"version": "11.0a3",
|
||||
"device": {
|
||||
"type": "Desktop",
|
||||
"model": "HP Compaq 8000 Elite SFF",
|
||||
"chassis": "Tower",
|
||||
"serialNumber": "CZC03217S7",
|
||||
"manufacturer": "Hewlett-Packard",
|
||||
"actions": []
|
||||
},
|
||||
"debug": "123456789 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 1234567890 "
|
||||
}
|
|
@ -238,6 +238,8 @@ def test_generic_action(action_model_state: Tuple[models.Action, states.Trading]
|
|||
device, _ = user.get(res=Device, item=snapshot['device']['id'])
|
||||
assert device['actions'][-1]['id'] == action['id']
|
||||
assert device['physical'] == state.name
|
||||
# Check if the update of device is changed
|
||||
assert snapshot['device']['updated'] != device['updated']
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
|
|
@ -53,7 +53,7 @@ def test_device_model():
|
|||
# Removing a component from pc doesn't delete the component
|
||||
pc.components.remove(net)
|
||||
db.session.commit()
|
||||
pc = d.Device.query.first() # this is the same as querying for d.Desktop directly
|
||||
pc = d.Device.query.filter_by(id=pc.id).first() # this is the same as querying for d.Desktop directly
|
||||
assert pc.components == {graphic}
|
||||
network_adapter = d.NetworkAdapter.query.one()
|
||||
assert network_adapter not in pc.components
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import json
|
||||
import shutil
|
||||
import pytest
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
@ -103,6 +104,25 @@ def test_snapshot_post(user: UserClient):
|
|||
assert rate['snapshot']['id'] == snapshot['id']
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_snapshot_update_timefield_updated(user: UserClient):
|
||||
"""
|
||||
Tests for check if one computer have the time mark updated when one component of it is updated
|
||||
"""
|
||||
computer1 = file('1-device-with-components.snapshot')
|
||||
snapshot = snapshot_and_check(user,
|
||||
computer1,
|
||||
action_types=(BenchmarkProcessor.t,
|
||||
RateComputer.t),
|
||||
perform_second_snapshot=False)
|
||||
computer2 = file('2-second-device-with-components-of-first.snapshot')
|
||||
snapshot_and_check(user, computer2, action_types=('Remove', 'RateComputer'),
|
||||
perform_second_snapshot=False)
|
||||
pc1_id = snapshot['device']['id']
|
||||
pc1, _ = user.get(res=m.Device, item=pc1_id)
|
||||
assert pc1['updated'] != snapshot['device']['updated']
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_snapshot_component_add_remove(user: UserClient):
|
||||
"""Tests adding and removing components and some don't generate HID.
|
||||
|
@ -129,6 +149,7 @@ def test_snapshot_component_add_remove(user: UserClient):
|
|||
perform_second_snapshot=False)
|
||||
pc1_id = snapshot1['device']['id']
|
||||
pc1, _ = user.get(res=m.Device, item=pc1_id)
|
||||
update1_pc1 = pc1['updated']
|
||||
# Parent contains components
|
||||
assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c2s', 'p1c3s')
|
||||
# Components contain parent
|
||||
|
@ -151,6 +172,10 @@ def test_snapshot_component_add_remove(user: UserClient):
|
|||
pc2_id = snapshot2['device']['id']
|
||||
pc1, _ = user.get(res=m.Device, item=pc1_id)
|
||||
pc2, _ = user.get(res=m.Device, item=pc2_id)
|
||||
# Check if the update_timestamp is updated
|
||||
update1_pc2 = pc2['updated']
|
||||
update2_pc1 = pc1['updated']
|
||||
assert update1_pc1 != update2_pc1
|
||||
# PC1
|
||||
assert tuple(c['serialNumber'] for c in pc1['components']) == ('p1c1s', 'p1c3s')
|
||||
assert all(c['parent'] == pc1_id for c in pc1['components'])
|
||||
|
@ -173,6 +198,12 @@ def test_snapshot_component_add_remove(user: UserClient):
|
|||
snapshot_and_check(user, s3, ('Remove', 'RateComputer'), perform_second_snapshot=False)
|
||||
pc1, _ = user.get(res=m.Device, item=pc1_id)
|
||||
pc2, _ = user.get(res=m.Device, item=pc2_id)
|
||||
# Check if the update_timestamp is updated
|
||||
update2_pc2 = pc2['updated']
|
||||
update3_pc1 = pc1['updated']
|
||||
assert not update3_pc1 in [update1_pc1, update2_pc1]
|
||||
assert update1_pc2 != update2_pc2
|
||||
|
||||
# PC1
|
||||
assert {c['serialNumber'] for c in pc1['components']} == {'p1c2s', 'p1c3s'}
|
||||
assert all(c['parent'] == pc1_id for c in pc1['components'])
|
||||
|
@ -213,6 +244,11 @@ def test_snapshot_component_add_remove(user: UserClient):
|
|||
snapshot_and_check(user, s4, ('RateComputer',), perform_second_snapshot=False)
|
||||
pc1, _ = user.get(res=m.Device, item=pc1_id)
|
||||
pc2, _ = user.get(res=m.Device, item=pc2_id)
|
||||
# Check if the update_timestamp is updated
|
||||
update3_pc2 = pc2['updated']
|
||||
update4_pc1 = pc1['updated']
|
||||
assert not update4_pc1 in [update1_pc1, update2_pc1, update3_pc1]
|
||||
assert update3_pc2 == update2_pc2
|
||||
# PC 0: p1c3s, p1c4s. PC1: p2c1s
|
||||
assert {c['serialNumber'] for c in pc1['components']} == {'p1c3s', 'p1c4s'}
|
||||
assert all(c['parent'] == pc1_id for c in pc1['components'])
|
||||
|
@ -483,30 +519,57 @@ def test_pc_2(user: UserClient):
|
|||
@pytest.mark.mvp
|
||||
def test_save_snapshot_in_file(app: Devicehub, user: UserClient):
|
||||
""" This test check if works the function save_snapshot_in_file """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
snapshot_no_hid = file('basic.snapshot.nohid')
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
|
||||
save_json(snapshot_no_hid, tmp_snapshots, user.user['email'])
|
||||
|
||||
uuid = snapshot_no_hid['uuid']
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
|
||||
snapshot = {'software': '', 'version': '', 'uuid': ''}
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
assert not "0001-01-01 00:00:00" in path_snapshot
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_no_hid['software']
|
||||
assert snapshot['version'] == snapshot_no_hid['version']
|
||||
assert snapshot['uuid'] == uuid
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_save_snapshot_with_debug(app: Devicehub, user: UserClient):
|
||||
""" This test check if works the function save_snapshot_in_file """
|
||||
snapshot_file = file('basic.snapshot.with_debug')
|
||||
debug = snapshot_file['debug']
|
||||
user.post(res=Snapshot, data=snapshot_file)
|
||||
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'])
|
||||
|
||||
uuid = snapshot_file['uuid']
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
|
||||
snapshot = {'debug': ''}
|
||||
if files:
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['debug'] == debug
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
|
||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
snapshot_no_hid = file('basic.snapshot.badly_formed')
|
||||
uuid = snapshot_no_hid['uuid']
|
||||
|
||||
|
@ -514,13 +577,13 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
|
|||
with pytest.raises(KeyError):
|
||||
response = user.post(res=Snapshot, data=snapshot_no_hid)
|
||||
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_no_hid['software']
|
||||
assert snapshot['version'] == snapshot_no_hid['version']
|
||||
|
@ -531,6 +594,7 @@ def test_backup_snapshot_with_errors(app: Devicehub, user: UserClient):
|
|||
def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient):
|
||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
snapshot_error = file('failed.snapshot.500.missing-cpu-benchmark')
|
||||
uuid = snapshot_error['uuid']
|
||||
|
||||
|
@ -538,13 +602,13 @@ def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient)
|
|||
with pytest.raises(TypeError):
|
||||
user.post(res=Snapshot, data=snapshot_error)
|
||||
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_error['software']
|
||||
assert snapshot['version'] == snapshot_error['version']
|
||||
|
@ -555,6 +619,7 @@ def test_snapshot_failed_missing_cpu_benchmark(app: Devicehub, user: UserClient)
|
|||
def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient):
|
||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
snapshot_error = file('failed.snapshot.500.missing-hdd-benchmark')
|
||||
uuid = snapshot_error['uuid']
|
||||
|
||||
|
@ -562,13 +627,13 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
|
|||
with pytest.raises(TypeError):
|
||||
user.post(res=Snapshot, data=snapshot_error)
|
||||
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_error['software']
|
||||
assert snapshot['version'] == snapshot_error['version']
|
||||
|
@ -579,6 +644,7 @@ def test_snapshot_failed_missing_hdd_benchmark(app: Devicehub, user: UserClient)
|
|||
def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
|
||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
snapshot_error = file('failed.snapshot.422.null-chassis')
|
||||
uuid = snapshot_error['uuid']
|
||||
|
||||
|
@ -586,13 +652,13 @@ def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
|
|||
with pytest.raises(TypeError):
|
||||
user.post(res=Snapshot, data=snapshot_error)
|
||||
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_error['software']
|
||||
assert snapshot['version'] == snapshot_error['version']
|
||||
|
@ -603,6 +669,7 @@ def test_snapshot_failed_null_chassis(app: Devicehub, user: UserClient):
|
|||
def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient):
|
||||
""" This test check if the file snapshot is create when some snapshot is wrong """
|
||||
tmp_snapshots = app.config['TMP_SNAPSHOTS']
|
||||
path_dir_base = os.path.join(tmp_snapshots, user.user['email'], 'errors')
|
||||
snapshot_error = file('failed.snapshot.422.missing-chassis')
|
||||
uuid = snapshot_error['uuid']
|
||||
|
||||
|
@ -610,13 +677,13 @@ def test_snapshot_failed_missing_chassis(app: Devicehub, user: UserClient):
|
|||
with pytest.raises(TypeError):
|
||||
user.post(res=Snapshot, data=snapshot_error)
|
||||
|
||||
files = [x for x in os.listdir(tmp_snapshots) if uuid in x]
|
||||
files = [x for x in os.listdir(path_dir_base) if uuid in x]
|
||||
if files:
|
||||
path_snapshot = os.path.join(tmp_snapshots, files[0])
|
||||
path_snapshot = os.path.join(path_dir_base, files[0])
|
||||
with open(path_snapshot) as file_snapshot:
|
||||
snapshot = json.loads(file_snapshot.read())
|
||||
|
||||
os.remove(path_snapshot)
|
||||
shutil.rmtree(tmp_snapshots)
|
||||
|
||||
assert snapshot['software'] == snapshot_error['software']
|
||||
assert snapshot['version'] == snapshot_error['version']
|
||||
|
|
|
@ -11,7 +11,7 @@ from ereuse_devicehub.resources.action.models import RateComputer, BenchmarkProc
|
|||
from ereuse_devicehub.resources.device.exceptions import NeedsId
|
||||
from ereuse_devicehub.resources.device.models import Device
|
||||
from ereuse_devicehub.resources.tag.model import Tag
|
||||
from tests.conftest import file
|
||||
from tests.conftest import file, file_workbench
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
|
@ -328,3 +328,8 @@ def test_workbench_asus_1001pxd_rate_low(user: UserClient):
|
|||
def test_david(user: UserClient):
|
||||
s = file('david.lshw.snapshot')
|
||||
snapshot, _ = user.post(res=em.Snapshot, data=s)
|
||||
|
||||
|
||||
def test_eresueprice_computer_type(user: UserClient):
|
||||
s = file_workbench('computer-type.snapshot')
|
||||
snapshot, _ = user.post(res=em.Snapshot, data=s)
|
||||
|
|
135
tests/workbench_files/computer-type.snapshot.json
Normal file
135
tests/workbench_files/computer-type.snapshot.json
Normal file
|
@ -0,0 +1,135 @@
|
|||
{
|
||||
"device": {
|
||||
"manufacturer": "Render",
|
||||
"chassis": "Virtual",
|
||||
"sku": "1234567890",
|
||||
"actions": [
|
||||
{
|
||||
"type": "StressTest",
|
||||
"elapsed": 60,
|
||||
"severity": "Info"
|
||||
},
|
||||
{
|
||||
"type": "BenchmarkRamSysbench",
|
||||
"rate": 47.3516,
|
||||
"elapsed": 47
|
||||
}
|
||||
],
|
||||
"model": "Pinetrail",
|
||||
"serialNumber": "0123456789",
|
||||
"type": "Computer",
|
||||
"version": "Revision A"
|
||||
},
|
||||
"endTime": "2020-09-11T18:59:14.395622+00:00",
|
||||
"closed": true,
|
||||
"components": [
|
||||
{
|
||||
"model": "NM10/ICH7 Family High Definition Audio Controller",
|
||||
"type": "SoundCard",
|
||||
"manufacturer": "Intel Corporation",
|
||||
"serialNumber": null,
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"model": "USB2.0-Camera",
|
||||
"type": "SoundCard",
|
||||
"manufacturer": "Generic",
|
||||
"serialNumber": "200901010001",
|
||||
"actions": []
|
||||
},
|
||||
{
|
||||
"cores": 1,
|
||||
"model": "Intel Atom CPU N455 @ 1.66GHz",
|
||||
"brand": "Atom",
|
||||
"manufacturer": "Intel Corp.",
|
||||
"actions": [
|
||||
{
|
||||
"type": "BenchmarkProcessorSysbench",
|
||||
"rate": 164.4763,
|
||||
"elapsed": 165
|
||||
},
|
||||
{
|
||||
"type": "BenchmarkProcessor",
|
||||
"rate": 6667.6,
|
||||
"elapsed": 0
|
||||
}
|
||||
],
|
||||
"speed": 1.667,
|
||||
"generation": null,
|
||||
"serialNumber": null,
|
||||
"type": "Processor",
|
||||
"address": 64,
|
||||
"threads": 2
|
||||
},
|
||||
{
|
||||
"format": "SODIMM",
|
||||
"manufacturer": "7576aces",
|
||||
"interface": "DDR3",
|
||||
"actions": [],
|
||||
"model": null,
|
||||
"speed": 667.0,
|
||||
"serialNumber": "7A7B7C7D",
|
||||
"type": "RamModule",
|
||||
"size": 1024.0
|
||||
},
|
||||
{
|
||||
"manufacturer": "Toshiba",
|
||||
"interface": "ATA",
|
||||
"serialNumber": "907HT0RKT",
|
||||
"model": "MK1665GS",
|
||||
"actions": [
|
||||
{
|
||||
"type": "BenchmarkDataStorage",
|
||||
"readSpeed": 81.1,
|
||||
"writeSpeed": 24.6,
|
||||
"elapsed": 14
|
||||
},
|
||||
{
|
||||
"reallocatedSectorCount": 47,
|
||||
"powerCycleCount": 147,
|
||||
"assessment": true,
|
||||
"currentPendingSectorCount": 0,
|
||||
"offlineUncorrectable": 0,
|
||||
"elapsed": 114,
|
||||
"status": "Completed without error",
|
||||
"type": "TestDataStorage",
|
||||
"length": "Short",
|
||||
"lifetime": 98,
|
||||
"severity": "Info"
|
||||
}
|
||||
],
|
||||
"type": "HardDrive",
|
||||
"size": 160041.88569599998,
|
||||
"variant": "1M"
|
||||
},
|
||||
{
|
||||
"manufacturer": "Intel Corporation",
|
||||
"serialNumber": null,
|
||||
"model": "Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller",
|
||||
"memory": null,
|
||||
"actions": [],
|
||||
"type": "GraphicCard"
|
||||
},
|
||||
{
|
||||
"firewire": 0,
|
||||
"serial": 1,
|
||||
"actions": [],
|
||||
"model": "Pinetrail",
|
||||
"pcmcia": 0,
|
||||
"serialNumber": "400",
|
||||
"usb": 5,
|
||||
"slots": 0,
|
||||
"manufacturer": "Render",
|
||||
"ramMaxSize": 2,
|
||||
"version": "6.00",
|
||||
"biosDate": "2011-02-28T00:00:00",
|
||||
"type": "Motherboard",
|
||||
"ramSlots": 2
|
||||
}
|
||||
],
|
||||
"elapsed": 11215,
|
||||
"uuid": "426ba7a5-7d73-4555-817e-562cead08e48",
|
||||
"version": "11.0b11",
|
||||
"software": "Workbench",
|
||||
"type": "Snapshot"
|
||||
}
|
Reference in a new issue