From f4418fc72a0267b5feebdc93f0f58089031442c3 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 11 Oct 2018 17:51:58 +0200 Subject: [PATCH 01/23] Add reports files, init report commit --- ereuse_devicehub/resources/device/views.py | 112 +++++++++++++++--- ereuse_devicehub/resources/device/x.py | 8 -- .../resources/reports/__init__.py | 0 ereuse_devicehub/resources/reports/reports.py | 39 ++++++ 4 files changed, 134 insertions(+), 25 deletions(-) delete mode 100644 ereuse_devicehub/resources/device/x.py create mode 100644 ereuse_devicehub/resources/reports/__init__.py create mode 100644 ereuse_devicehub/resources/reports/reports.py diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 61993ab0..0b88dd8a 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -1,4 +1,6 @@ import datetime +import itertools +from collections import OrderedDict import marshmallow from flask import current_app as app, render_template, request @@ -13,9 +15,11 @@ from teal.resource import View from ereuse_devicehub import auth from ereuse_devicehub.db import db from ereuse_devicehub.resources import search -from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer +from ereuse_devicehub.resources.device.definitions import ComponentDef +from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \ + RamModule, Processor, DataStorage from ereuse_devicehub.resources.device.search import DeviceSearch -from ereuse_devicehub.resources.event.models import Rate +from ereuse_devicehub.resources.event.models import Rate, Event from ereuse_devicehub.resources.lot.models import Lot, LotDevice from ereuse_devicehub.resources.tag.model import Tag @@ -119,21 +123,95 @@ class DeviceView(View): search.Search.rank(properties, search_p) + search.Search.rank(tags, search_p) ) query = query.filter(*args['filter']).order_by(*args['sort']) - devices = query.paginate(page=args['page'], per_page=30) # type: Pagination - ret = { - 'items': self.schema.dump(devices.items, many=True, nested=1), - # todo pagination should be in Header like github - # https://developer.github.com/v3/guides/traversing-with-pagination/ - 'pagination': { - 'page': devices.page, - 'perPage': devices.per_page, - 'total': devices.total, - 'previous': devices.prev_num, - 'next': devices.next_num - }, - 'url': request.path - } - return jsonify(ret) + if args['format']: + ... + return self.spreadsheet(query) + else: + devices = query.paginate(page=args['page'], per_page=30) # type: Pagination + ret = { + 'items': self.schema.dump(devices.items, many=True, nested=1), + # todo pagination should be in Header like github + # https://developer.github.com/v3/guides/traversing-with-pagination/ + 'pagination': { + 'page': devices.page, + 'perPage': devices.per_page, + 'total': devices.total, + 'previous': devices.prev_num, + 'next': devices.next_num + }, + 'url': request.path + } + return jsonify(ret) + + def spreadsheet(self, query): + devices = [] + for device in query: + d = DeviceRow(device) + devices.append(d) + + titles = [name for name in devices[0].keys()] + + rest = [[value for value in row.values()] for row in devices] + + +class DeviceRow(OrderedDict): + NUMS = { + Processor.t: 1 + } + + def __init__(self, device: Device) -> None: + super().__init__() + self.device = device + self['Type'] = device.t + if isinstance(device, Computer): + self['Chassis'] = device.chassis + self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' + for i, tag in zip(range(1, 3), device.tags): + self['Tag {}'.format(i)] = format(tag) + self['Serial Number'] = device.serial_number + self['Price'] = device.price + self['Model'] = device.model + self['Manu...'] = device.manufacturer + self['Regsitered in '] = device.created + if isinstance(device, Computer): + self['Processor'] = device.processor_model + self['RAM (GB)'] = device.ram_size + self['Size (MB)'] = device.data_storage_size + rate = device.rate # type: Rate + if rate: + self['Rate'] = rate.rating + self['Range'] = rate.rating_range + self['Processor Rate'] = rate.processor_rate + self['RAM Rate'] = rate.ram_rate + self['Data Storage Rate'] = rate.data_storage_rate + # New Update fields (necessaris?) + # Origin note = Id-Donació + # Target note = Id-Receptor + # Partner = cadena de custodia (cadena de noms dels agents(entitas) implicats) [int] + # Margin = percentatges de com es repeteix els guanys del preu de venta del dispositiu. [int] + # Id invoice = id de la factura + if isinstance(device, Computer): + self.components() + + + def components(self): + assert isinstance(self.device, Computer) + for type in app.resources[Component.t].subresources_types: # type: str + max = self.NUMS.get(type, 4) + i = 1 + for component in (r for r in self.device.components if r.type == type): + self.fill_component(type, i, component) + i += 1 + if i >= max: + break + while i < max: + self.fill_component(type, i) + i += 1 + + + def fill_component(self, type, i, component = None): + self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' + if isinstance(component, DataStorage): + self['{} {} Compliance'.format()] = component.compliance class ManufacturerView(View): diff --git a/ereuse_devicehub/resources/device/x.py b/ereuse_devicehub/resources/device/x.py deleted file mode 100644 index e2d203a3..00000000 --- a/ereuse_devicehub/resources/device/x.py +++ /dev/null @@ -1,8 +0,0 @@ -import csv -import json - -with open('manufacturers.csv', 'w') as o: - writer = csv.writer(o) - with open('manufacturers.json') as i: - for x in json.load(i): - writer.writerow([x['name'], x['url'], x['logo'] if x.get('logo', None) else None]) diff --git a/ereuse_devicehub/resources/reports/__init__.py b/ereuse_devicehub/resources/reports/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/ereuse_devicehub/resources/reports/reports.py b/ereuse_devicehub/resources/reports/reports.py new file mode 100644 index 00000000..ae96ecf1 --- /dev/null +++ b/ereuse_devicehub/resources/reports/reports.py @@ -0,0 +1,39 @@ +from typing import Set + +from sqlalchemy import func + +from ereuse_devicehub.db import db +from ereuse_devicehub.resources.device.models import Device +from ereuse_devicehub.resources.event.models import Price, Event, Trade + +ids = {1,2,3} + + +def export(devices_id: Set[str]): + # todo get the last event of device + last_event = Event.end_time. + + devices = Device.id.in_(ids) + + total_value_query = db.session.query(Price, func.sum(Price.price).label('total'))\ + .filter(devices)\ + .join(Price.device)\ + .filter(last_event) + + # todo hacer query para obtener el price + + query(func.max(end_time)).join(Price.devices).filter(Device_id==id).ordey_by(Price.end_time).limit() + + total_price_query = query() + + value = total_value_query.one() + value['total'] + + # + db.session.query(Price, (Price.price / total_value_query).label('asdfas')) + + trade_orgs_q = db.session.query(Trade, func.sum(Trade.org_id)).filter(devices).join(Trade.devices).filter(last_event) + + # execute query + value = trade_orgs_q.scalar() + From e92f64d88dd8056b31b0d63ac2fb4dddcf9da2e5 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 11 Oct 2018 18:19:33 +0200 Subject: [PATCH 02/23] Add test_reports file --- tests/test_reports.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/test_reports.py diff --git a/tests/test_reports.py b/tests/test_reports.py new file mode 100644 index 00000000..832df0be --- /dev/null +++ b/tests/test_reports.py @@ -0,0 +1,16 @@ +from ereuse_devicehub.client import UserClient +from ereuse_devicehub.resources.device.models import Device +from ereuse_devicehub.resources.event.models import Snapshot +from tests.conftest import file + + +def test_export(user: UserClient): + snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) + device_id = snapshot['device']['id'] + + + + spreadsheet, _ = user.get(res=Device, accept='text/csv') + csv.reader() + assert + # import csv mirar com la lib python treballa From 40d3529221fcdfbcf4518516563de420dd3fe37c Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 18 Oct 2018 17:36:14 +0200 Subject: [PATCH 03/23] Add test assert csv --- tests/test_reports.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/tests/test_reports.py b/tests/test_reports.py index 832df0be..e9048d4f 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -1,16 +1,22 @@ +import csv + +import pytest + from ereuse_devicehub.client import UserClient from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.event.models import Snapshot from tests.conftest import file -def test_export(user: UserClient): +def test_export_endpoint(user: UserClient): snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - device_id = snapshot['device']['id'] + # device_id = snapshot['device']['id'] + device_type = snapshot['device']['type'] + csv_list, _ = user.get(res=Device, accept='text/csv') + read_csv = csv.reader(csv_list, delimiter=',') + dates = [] + for row in read_csv: + date = row[0] + dates.append(date) - - - spreadsheet, _ = user.get(res=Device, accept='text/csv') - csv.reader() - assert - # import csv mirar com la lib python treballa + assert dates[1] == device_type, 'Device type are not equal' From 654edf35a1b21fafdc2a41af3174c9e3f3b6d9cf Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 18 Oct 2018 18:16:49 +0200 Subject: [PATCH 04/23] Add if in find 'text/csv' --- ereuse_devicehub/resources/device/views.py | 55 ++++++++++++++-------- tests/test_reports.py | 1 - 2 files changed, 36 insertions(+), 20 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index bb3d8fb0..a1b28c3a 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -1,9 +1,11 @@ +import csv import datetime -import itertools + +from io import StringIO from collections import OrderedDict import marshmallow -from flask import current_app as app, render_template, request +from flask import current_app as app, render_template, request, make_response from flask.json import jsonify from flask_sqlalchemy import Pagination from marshmallow import fields, fields as f, validate as v @@ -15,7 +17,7 @@ from teal.resource import View from ereuse_devicehub import auth from ereuse_devicehub.db import db from ereuse_devicehub.resources import search -from ereuse_devicehub.resources.device.definitions import ComponentDef +# from ereuse_devicehub.resources.device.definitions import ComponentDef from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \ RamModule, Processor, DataStorage from ereuse_devicehub.resources.device.search import DeviceSearch @@ -124,9 +126,8 @@ class DeviceView(View): search.Search.rank(properties, search_p) + search.Search.rank(tags, search_p) ) query = query.filter(*args['filter']).order_by(*args['sort']) - if args['format']: - ... - return self.spreadsheet(query) + if 'text/csv' in request.accept_mimetypes: + return self.generate_post_csv(query) else: devices = query.paginate(page=args['page'], per_page=30) # type: Pagination ret = { @@ -144,14 +145,29 @@ class DeviceView(View): } return jsonify(ret) - def spreadsheet(self, query): + def generate_post_csv(self, query): + """ + Get device query and put information in csv format + :param query: + :return: + """ devices = [] for device in query: d = DeviceRow(device) devices.append(d) - titles = [name for name in devices[0].keys()] + - rest = [[value for value in row.values()] for row in devices] + keys = [name for name in devices[0].keys()] + # writer_csv = csv.DictWriter(devices, fieldnames='') + values = [[value for value in row.values()] for row in devices] + # devices = str(re.sub('\[|\]', '', str(devices))) # convert to a string; remove brackets + data = StringIO() + cw = csv.writer(data) + cw.writerow(keys) + cw.writerows(values) + output = make_response(data.getvalue()) + output.headers["Content-Disposition"] = "attachment; filename=export.csv" + output.headers["Content-type"] = "text/csv" + return output class DeviceRow(OrderedDict): @@ -171,20 +187,23 @@ class DeviceRow(OrderedDict): self['Serial Number'] = device.serial_number self['Price'] = device.price self['Model'] = device.model - self['Manu...'] = device.manufacturer - self['Regsitered in '] = device.created + self['Manufacturer'] = device.manufacturer + self['Registered in '] = device.created if isinstance(device, Computer): self['Processor'] = device.processor_model self['RAM (GB)'] = device.ram_size self['Size (MB)'] = device.data_storage_size - rate = device.rate # type: Rate + rate = device.rate if rate: self['Rate'] = rate.rating self['Range'] = rate.rating_range - self['Processor Rate'] = rate.processor_rate - self['RAM Rate'] = rate.ram_rate - self['Data Storage Rate'] = rate.data_storage_rate - # New Update fields (necessaris?) + self['Processor Rate'] = rate.processor + self['Processor Range'] = rate.workbench.processor_range + self['RAM Rate'] = rate.ram + self['RAM Range'] = rate.workbench.ram_range + self['Data Storage Rate'] = rate.data_storage + self['Data Storage Range'] = rate.workbench.data_storage_range + # New Update fields # Origin note = Id-Donació # Target note = Id-Receptor # Partner = cadena de custodia (cadena de noms dels agents(entitas) implicats) [int] @@ -193,10 +212,9 @@ class DeviceRow(OrderedDict): if isinstance(device, Computer): self.components() - def components(self): assert isinstance(self.device, Computer) - for type in app.resources[Component.t].subresources_types: # type: str + for type in app.resources[Component.t].subresources_types: # type: str max = self.NUMS.get(type, 4) i = 1 for component in (r for r in self.device.components if r.type == type): @@ -208,7 +226,6 @@ class DeviceRow(OrderedDict): self.fill_component(type, i) i += 1 - def fill_component(self, type, i, component = None): self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' if isinstance(component, DataStorage): diff --git a/tests/test_reports.py b/tests/test_reports.py index e9048d4f..a2b6b2f5 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -10,7 +10,6 @@ from tests.conftest import file def test_export_endpoint(user: UserClient): snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - # device_id = snapshot['device']['id'] device_type = snapshot['device']['type'] csv_list, _ = user.get(res=Device, accept='text/csv') read_csv = csv.reader(csv_list, delimiter=',') From 50a365b4bf8421b2aa061eb60d6c882a5aca073a Mon Sep 17 00:00:00 2001 From: JNadeu Date: Tue, 23 Oct 2018 17:36:53 +0200 Subject: [PATCH 05/23] add basic.csv file to use in test_reports --- tests/files/basic.csv | 5 +++++ tests/test_reports.py | 33 +++++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 tests/files/basic.csv diff --git a/tests/files/basic.csv b/tests/files/basic.csv new file mode 100644 index 00000000..d360e99a --- /dev/null +++ b/tests/files/basic.csv @@ -0,0 +1,5 @@ +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Price,Model,Manufacturer,Registered in ,Processor,RAM (GB),Size (MB),Rate,Range,Processor Rate,Processor Range,RAM Rate,RAM Range,Data Storage Rate,Data Storage Range,Component 1 Serial Number,Component 2 Serial Number,Component 3 Serial Number,RamModule 1 Serial Number,RamModule 2 Serial Number,RamModule 3 Serial Number,GraphicCard 1 Serial Number,GraphicCard 2 Serial Number,GraphicCard 3 Serial Number,Motherboard 1 Serial Number,Motherboard 2 Serial Number,Motherboard 3 Serial Number,SoundCard 1 Serial Number,SoundCard 2 Serial Number,SoundCard 3 Serial Number,Display 1 Serial Number,Display 2 Serial Number,Display 3 Serial Number,NetworkAdapter 1 Serial Number,NetworkAdapter 2 Serial Number,NetworkAdapter 3 Serial Number,DataStorage 1 Serial Number,DataStorage 2 Serial Number,DataStorage 3 Serial Number,SolidStateDrive 1 Serial Number,SolidStateDrive 2 Serial Number,SolidStateDrive 3 Serial Number,HardDrive 1 Serial Number,HardDrive 2 Serial Number,HardDrive 3 Serial Number,Processor 1 Serial Number +Desktop,ComputerChassis.Microtower,,,,d1s,,d1ml,d1mr,2018-10-22 12:53:17.180047+02:00,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,rm1s,,,gc1s,,,,,,,,,,,,,,,,,,,,,,,,p1s +GraphicCard,,,,gc1s,,gc1ml,gc1mr,2018-10-22 12:53:17.163571+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low +RamModule,,,,rm1s,,rm1ml,rm1mr,2018-10-22 12:53:17.168983+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low +Processor,,,,p1s,,p1ml,p1mr,2018-10-22 12:53:17.173623+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low \ No newline at end of file diff --git a/tests/test_reports.py b/tests/test_reports.py index a2b6b2f5..13951548 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -1,6 +1,9 @@ import csv +from io import StringIO +from pathlib import Path import pytest +# [(t, l) for t,l in zip(test_csv[0], list_csv[0]) if t != l] from ereuse_devicehub.client import UserClient from ereuse_devicehub.resources.device.models import Device @@ -10,12 +13,26 @@ from tests.conftest import file def test_export_endpoint(user: UserClient): snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - device_type = snapshot['device']['type'] - csv_list, _ = user.get(res=Device, accept='text/csv') - read_csv = csv.reader(csv_list, delimiter=',') - dates = [] - for row in read_csv: - date = row[0] - dates.append(date) + # device_type = snapshot['device']['type'] + csv_str, _ = user.get(res=Device, accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + test_csv = list(obj_csv) + with Path(__file__).parent.joinpath('files').joinpath('testcsv.csv').open() as csv_file: + obj_csv = csv.reader(csv_file) + list_csv = list(obj_csv) + assert test_csv == list_csv, 'Csv files are different' - assert dates[1] == device_type, 'Device type are not equal' +def test_export_empty(user: UserClient): + """ + Test to check works correctly exporting csv without any information + """ + pass + + +def test_export_full_snaphsot(user: UserClient): + """ + Test a export device with all fields + :return: + """ + pass From cfc5c33f3971172ccf12f0db1a4eec240e5c5843 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Tue, 23 Oct 2018 18:59:58 +0200 Subject: [PATCH 06/23] add erase reports fields --- ereuse_devicehub/resources/device/views.py | 81 ++++++++++++++++------ 1 file changed, 61 insertions(+), 20 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 4ce2bf8c..014e51c2 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -151,24 +151,71 @@ class DeviceView(View): :param query: :return: """ - devices = [] - for device in query: - d = DeviceRow(device) - devices.append(d) - - keys = [name for name in devices[0].keys()] - # writer_csv = csv.DictWriter(devices, fieldnames='') - values = [[value for value in row.values()] for row in devices] - # devices = str(re.sub('\[|\]', '', str(devices))) # convert to a string; remove brackets data = StringIO() cw = csv.writer(data) - cw.writerow(keys) - cw.writerows(values) + first = True + for device in query: + d = DeviceRow(device) + if first: + cw.writerow(name for name in d.keys()) + first = False + cw.writerow(v for v in d.values()) output = make_response(data.getvalue()) - output.headers["Content-Disposition"] = "attachment; filename=export.csv" - output.headers["Content-type"] = "text/csv" + output.headers['Content-Disposition'] = 'attachment; filename=export.csv' + output.headers['Content-type'] = 'text/csv' return output + def generate_erase_certificate(self, query): + data = StringIO() + cw = csv.writer(data) + first = True + for device in query: + d = DeviceRow(device) + if first: + cw.writerow(name for name in d.keys()) + first = False + cw.writerow(v for v in d.values()) + # cw = csv.DictWriter(d, fieldnames=keys) + output = make_response(data.getvalue()) + output.headers['Content-Disposition'] = 'attachment; filename=export.csv' + output.headers['Content-type'] = 'text/csv' + return output + + +class EraseDataStorage(OrderedDict): + def __init__(self, device: Device) -> None: + super().__init__() + self.device = device + + + # General Information + self['Organization'] = device.org + self['Date report'] = datetime.time() + self['Erase Information'] = device.org + 'ha borrado los siguientes discos acorde a ..' + eraseType + # Devices information for row {TABLE} + self['Computer Serial Number'] = device.serial_number + self['Computer Tag'] = device.tags + self['DataStorage Serial Number'] = device.components.data_storage.serial_number + self['Erase Date'] = device.event.erase.event_date + self['Erase Status'] = device.event.erase.privacy + self['Erase Type'] = device.event.erase.type + # For each DataStorage + self['DataStorage Serial Number'] = device.components.data_storage.serial_number + self['DataStorage Model'] = device.components.data_storage.model + self['DataStorage Manufacturer'] = device.components.data_storage.manufacturer + self['DataStorage Size (MB)'] = device.data_storage_size + self['Erase Date'] = device.event.erase.event_date + self['Erase Status'] = device.components.data_storage.privacy + # Erase information + self['Tool used to erase'] = device.erase_tool + self['Steps'] = device.events.erase.steps + self['Elapsed time'] = device.events.erase.erase_time + self['Final clean with zeros'] = 'Yes|No' + # Optional more computer info + self['Computer Serial Number'] = device.serial_number + self['Computer Model'] = device.model + self['Computer Manufacturer'] = device.manufacturer + self['Computer Tag'] = device.tags class DeviceRow(OrderedDict): NUMS = { @@ -180,7 +227,7 @@ class DeviceRow(OrderedDict): self.device = device self['Type'] = device.t if isinstance(device, Computer): - self['Chassis'] = device.chassis + self['Chassis'] = device.chassis. self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' for i, tag in zip(range(1, 3), device.tags): self['Tag {}'.format(i)] = format(tag) @@ -203,12 +250,6 @@ class DeviceRow(OrderedDict): self['RAM Range'] = rate.workbench.ram_range self['Data Storage Rate'] = rate.data_storage self['Data Storage Range'] = rate.workbench.data_storage_range - # New Update fields - # Origin note = Id-Donació - # Target note = Id-Receptor - # Partner = cadena de custodia (cadena de noms dels agents(entitas) implicats) [int] - # Margin = percentatges de com es repeteix els guanys del preu de venta del dispositiu. [int] - # Id invoice = id de la factura if isinstance(device, Computer): self.components() From c299656f053c3a62ba95f218d583e8db5895566b Mon Sep 17 00:00:00 2001 From: JNadeu Date: Wed, 24 Oct 2018 21:09:54 +0200 Subject: [PATCH 07/23] Add fixtures csv files and exports tests --- .../resources/reports/__init__.py | 0 ereuse_devicehub/resources/reports/reports.py | 39 ------- tests/files/basic.csv | 7 +- tests/files/computer-monitor.csv | 2 + tests/files/full-real-eee.csv | 2 + tests/files/keyboard.csv | 2 + tests/test_reports.py | 107 +++++++++++++++--- 7 files changed, 101 insertions(+), 58 deletions(-) delete mode 100644 ereuse_devicehub/resources/reports/__init__.py delete mode 100644 ereuse_devicehub/resources/reports/reports.py create mode 100644 tests/files/computer-monitor.csv create mode 100644 tests/files/full-real-eee.csv create mode 100644 tests/files/keyboard.csv diff --git a/ereuse_devicehub/resources/reports/__init__.py b/ereuse_devicehub/resources/reports/__init__.py deleted file mode 100644 index e69de29b..00000000 diff --git a/ereuse_devicehub/resources/reports/reports.py b/ereuse_devicehub/resources/reports/reports.py deleted file mode 100644 index ae96ecf1..00000000 --- a/ereuse_devicehub/resources/reports/reports.py +++ /dev/null @@ -1,39 +0,0 @@ -from typing import Set - -from sqlalchemy import func - -from ereuse_devicehub.db import db -from ereuse_devicehub.resources.device.models import Device -from ereuse_devicehub.resources.event.models import Price, Event, Trade - -ids = {1,2,3} - - -def export(devices_id: Set[str]): - # todo get the last event of device - last_event = Event.end_time. - - devices = Device.id.in_(ids) - - total_value_query = db.session.query(Price, func.sum(Price.price).label('total'))\ - .filter(devices)\ - .join(Price.device)\ - .filter(last_event) - - # todo hacer query para obtener el price - - query(func.max(end_time)).join(Price.devices).filter(Device_id==id).ordey_by(Price.end_time).limit() - - total_price_query = query() - - value = total_value_query.one() - value['total'] - - # - db.session.query(Price, (Price.price / total_value_query).label('asdfas')) - - trade_orgs_q = db.session.query(Trade, func.sum(Trade.org_id)).filter(devices).join(Trade.devices).filter(last_event) - - # execute query - value = trade_orgs_q.scalar() - diff --git a/tests/files/basic.csv b/tests/files/basic.csv index d360e99a..4d01b6dd 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,5 +1,2 @@ -Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Price,Model,Manufacturer,Registered in ,Processor,RAM (GB),Size (MB),Rate,Range,Processor Rate,Processor Range,RAM Rate,RAM Range,Data Storage Rate,Data Storage Range,Component 1 Serial Number,Component 2 Serial Number,Component 3 Serial Number,RamModule 1 Serial Number,RamModule 2 Serial Number,RamModule 3 Serial Number,GraphicCard 1 Serial Number,GraphicCard 2 Serial Number,GraphicCard 3 Serial Number,Motherboard 1 Serial Number,Motherboard 2 Serial Number,Motherboard 3 Serial Number,SoundCard 1 Serial Number,SoundCard 2 Serial Number,SoundCard 3 Serial Number,Display 1 Serial Number,Display 2 Serial Number,Display 3 Serial Number,NetworkAdapter 1 Serial Number,NetworkAdapter 2 Serial Number,NetworkAdapter 3 Serial Number,DataStorage 1 Serial Number,DataStorage 2 Serial Number,DataStorage 3 Serial Number,SolidStateDrive 1 Serial Number,SolidStateDrive 2 Serial Number,SolidStateDrive 3 Serial Number,HardDrive 1 Serial Number,HardDrive 2 Serial Number,HardDrive 3 Serial Number,Processor 1 Serial Number -Desktop,ComputerChassis.Microtower,,,,d1s,,d1ml,d1mr,2018-10-22 12:53:17.180047+02:00,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,rm1s,,,gc1s,,,,,,,,,,,,,,,,,,,,,,,,p1s -GraphicCard,,,,gc1s,,gc1ml,gc1mr,2018-10-22 12:53:17.163571+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low -RamModule,,,,rm1s,,rm1ml,rm1mr,2018-10-22 12:53:17.168983+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low -Processor,,,,p1s,,p1ml,p1mr,2018-10-22 12:53:17.173623+02:00,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low \ No newline at end of file +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Display 2,Display 2 Manufacturer,Display 2 Model,Display 2 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 1 Size,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 +Desktop,ComputerChassis.Microtower,,,,d1s,d1ml,d1mr,,Wed Oct 24 20:19:44 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, diff --git a/tests/files/computer-monitor.csv b/tests/files/computer-monitor.csv new file mode 100644 index 00000000..26213062 --- /dev/null +++ b/tests/files/computer-monitor.csv @@ -0,0 +1,2 @@ +Type,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in +ComputerMonitor,,,,cn0fp446728728541c8s,1707fpf,dell,,Wed Oct 24 20:57:18 2018 diff --git a/tests/files/full-real-eee.csv b/tests/files/full-real-eee.csv new file mode 100644 index 00000000..73e70f71 --- /dev/null +++ b/tests/files/full-real-eee.csv @@ -0,0 +1,2 @@ +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Display 2,Display 2 Manufacturer,Display 2 Model,Display 2 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,Motherboard 1 Slots,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 1 Size,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,ComputerChassis.Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,,Wed Oct 24 20:42:19 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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 diff --git a/tests/files/keyboard.csv b/tests/files/keyboard.csv new file mode 100644 index 00000000..dd279133 --- /dev/null +++ b/tests/files/keyboard.csv @@ -0,0 +1,2 @@ +Type,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in +Keyboard,,,,bar,foo,baz,,Wed Oct 24 21:01:48 2018 diff --git a/tests/test_reports.py b/tests/test_reports.py index 13951548..13ab4327 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -2,37 +2,116 @@ import csv from io import StringIO from pathlib import Path -import pytest -# [(t, l) for t,l in zip(test_csv[0], list_csv[0]) if t != l] - from ereuse_devicehub.client import UserClient from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.event.models import Snapshot from tests.conftest import file -def test_export_endpoint(user: UserClient): +def test_export_basic_snapshot(user: UserClient): + """ + Test export device information in a csv file + """ snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - # device_type = snapshot['device']['type'] csv_str, _ = user.get(res=Device, accept='text/csv') f = StringIO(csv_str) obj_csv = csv.reader(f, f) - test_csv = list(obj_csv) - with Path(__file__).parent.joinpath('files').joinpath('testcsv.csv').open() as csv_file: + export_csv = list(obj_csv) + # Open fixture csv and transform to list + with Path(__file__).parent.joinpath('files').joinpath('basic.csv').open() as csv_file: obj_csv = csv.reader(csv_file) - list_csv = list(obj_csv) - assert test_csv == list_csv, 'Csv files are different' + fixture_csv = list(obj_csv) + + # Pop(datetime) field d[1x][9] + fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] + export_csv[1] = export_csv[1][:9] + export_csv[1][10:] + + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' + assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' + + +def test_export_full_snapshot(user: UserClient): + """ + Test a export device with all information and a lot of components + """ + snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) + csv_str, _ = user.get(res=Device, accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + export_csv = list(obj_csv) + # Open fixture csv and transform to list + with Path(__file__).parent.joinpath('files').joinpath('full-real-eee.csv').open() as csv_file: + obj_csv = csv.reader(csv_file) + fixture_csv = list(obj_csv) + + # todo one pop for each devices + # One pop(datetime) fields d[1x][9] + fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] + export_csv[1] = export_csv[1][:9] + export_csv[1][10:] + + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' + assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' + def test_export_empty(user: UserClient): """ - Test to check works correctly exporting csv without any information + Test to check works correctly exporting csv without any information (no snapshot) """ - pass + csv_str, _ = user.get(res=Device, accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + export_csv = list(obj_csv) + + assert len(export_csv) == 0, 'Csv is not empty' -def test_export_full_snaphsot(user: UserClient): +def test_export_computer_monitor(user: UserClient): """ - Test a export device with all fields - :return: + Test a export device type computer monitor """ + snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) + csv_str, _ = user.get(res=Device, accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + export_csv = list(obj_csv) + # Open fixture csv and transform to list + with Path(__file__).parent.joinpath('files').joinpath('computer-monitor.csv').open() as csv_file: + obj_csv = csv.reader(csv_file) + fixture_csv = list(obj_csv) + + # One pop(datetime) fields + fixture_csv[1] = fixture_csv[1][:8] + export_csv[1] = export_csv[1][:8] + + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' + assert fixture_csv[1] == export_csv[1], 'Component information are not equal' + + +def test_export_keyboard(user: UserClient): + """ + Test a export device type keyboard + """ + snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot) + csv_str, _ = user.get(res=Device, accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + export_csv = list(obj_csv) + # Open fixture csv and transform to list + with Path(__file__).parent.joinpath('files').joinpath('keyboard.csv').open() as csv_file: + obj_csv = csv.reader(csv_file) + fixture_csv = list(obj_csv) + + # One pop(datetime) fields + fixture_csv[1] = fixture_csv[1][:8] + export_csv[1] = export_csv[1][:8] + + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' + assert fixture_csv[1] == export_csv[1], 'Component information are not equal' + + +def test_export_multiple_devices(user: UserClient): + """ + Test a export multiple devices with different components and information + """ + # todo test multiple devices pass From e17352879a922c00b16895979ddc10c08a7a3656 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Wed, 24 Oct 2018 21:11:32 +0200 Subject: [PATCH 08/23] Add generic export computer --- ereuse_devicehub/resources/device/views.py | 105 ++++++++++++++++----- 1 file changed, 81 insertions(+), 24 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 014e51c2..bc99e349 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -19,7 +19,7 @@ from ereuse_devicehub.db import db from ereuse_devicehub.resources import search # from ereuse_devicehub.resources.device.definitions import ComponentDef from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \ - RamModule, Processor, DataStorage + RamModule, Processor, DataStorage, GraphicCard, Motherboard, Display, NetworkAdapter, SoundCard from ereuse_devicehub.resources.device.search import DeviceSearch from ereuse_devicehub.resources.event.models import Rate, Event from ereuse_devicehub.resources.lot.models import Lot, LotDevice @@ -154,18 +154,25 @@ class DeviceView(View): data = StringIO() cw = csv.writer(data) first = True + # todo fix if only export components for device in query: + # if not isinstance(device, Component): d = DeviceRow(device) if first: cw.writerow(name for name in d.keys()) + cw.writerow(v for v in d.values()) first = False - cw.writerow(v for v in d.values()) + elif isinstance(device, Computer): + cw.writerow(v for v in d.values()) output = make_response(data.getvalue()) output.headers['Content-Disposition'] = 'attachment; filename=export.csv' output.headers['Content-type'] = 'text/csv' return output - def generate_erase_certificate(self, query): + +""" Export Erased Certificate Code + + def generate_erased_certificate(self, query): data = StringIO() cw = csv.writer(data) first = True @@ -187,7 +194,6 @@ class EraseDataStorage(OrderedDict): super().__init__() self.device = device - # General Information self['Organization'] = device.org self['Date report'] = datetime.time() @@ -216,30 +222,39 @@ class EraseDataStorage(OrderedDict): self['Computer Model'] = device.model self['Computer Manufacturer'] = device.manufacturer self['Computer Tag'] = device.tags +""" + class DeviceRow(OrderedDict): NUMS = { - Processor.t: 1 + Display.t: 2, + Processor.t: 2, + GraphicCard.t: 2, + Motherboard.t: 1, + NetworkAdapter.t: 2, + SoundCard.t: 2 } def __init__(self, device: Device) -> None: super().__init__() self.device = device + # General information about device self['Type'] = device.t if isinstance(device, Computer): - self['Chassis'] = device.chassis. + self['Chassis'] = device.chassis self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' for i, tag in zip(range(1, 3), device.tags): self['Tag {}'.format(i)] = format(tag) self['Serial Number'] = device.serial_number - self['Price'] = device.price self['Model'] = device.model self['Manufacturer'] = device.manufacturer - self['Registered in '] = device.created + # self['State'] = device.last_event_of() + self['Price'] = device.price + self['Registered in'] = format(device.created, '%c') if isinstance(device, Computer): self['Processor'] = device.processor_model self['RAM (GB)'] = device.ram_size - self['Size (MB)'] = device.data_storage_size + self['Storage Size (MB)'] = device.data_storage_size rate = device.rate if rate: self['Rate'] = rate.rating @@ -250,27 +265,69 @@ class DeviceRow(OrderedDict): self['RAM Range'] = rate.workbench.ram_range self['Data Storage Rate'] = rate.data_storage self['Data Storage Range'] = rate.workbench.data_storage_range + # More specific information about components if isinstance(device, Computer): self.components() - def components(self): - assert isinstance(self.device, Computer) - for type in app.resources[Component.t].subresources_types: # type: str - max = self.NUMS.get(type, 4) - i = 1 - for component in (r for r in self.device.components if r.type == type): - self.fill_component(type, i, component) - i += 1 - if i >= max: - break - while i < max: - self.fill_component(type, i) - i += 1 - def fill_component(self, type, i, component = None): + def components(self): + """ + Function to get all components information of a device + """ + assert isinstance(self.device, Computer) + # todo put an input specific order (non alphabetic) + for type in sorted(app.resources[Component.t].subresources_types): # type: str + max = self.NUMS.get(type, 4) + if type not in ['Component', 'HardDrive', 'SolidStateDrive']: + i = 1 + for component in (r for r in self.device.components if r.type == type): + self.fill_component(type, i, component) + i += 1 + if i > max: + break + while i <= max: + self.fill_component(type, i) + i += 1 + + def fill_component(self, type, i, component=None): + """ + Function to put specific information of components in OrderedDict (csv) + :param type: type of component + :param component: device.components + """ + self['{} {}'.format(type, i)] = format(component) if component else '' + self['{} {} Manufacturer'.format(type, i)] = component.serial_number if component else '' + self['{} {} Model'.format(type, i)] = component.serial_number if component else '' self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' + + """ Particular fields for component GraphicCard """ + if isinstance(component, GraphicCard): + self['{} {} Memory (MB)'.format(type, i)] = component.memory + + """ Particular fields for component DataStorage.t -> (HardDrive, SolidStateDrive) """ if isinstance(component, DataStorage): - self['{} {} Compliance'.format()] = component.compliance + self['{} {} Size (MB)'.format(type, i)] = component.size + self['{} {} Privacy'.format(type, i)] = component.privacy + + # todo decide if is relevant more info about Motherboard + """ Particular fields for component Motherboard """ + if isinstance(component, Motherboard): + self['{} {} Slots'.format(type, i)] = component.slots + + """ Particular fields for component Processor """ + if isinstance(component, Processor): + self['{} {} Number of cores'.format(type, i)] = component.cores + self['{} {} Speed (GHz)'.format(type, i)] = component.speed + + """ Particular fields for component RamModule """ + if isinstance(component, RamModule): + self['{} {} Size (MB)'.format(type, i)] = component.size + self['{} {} Speed (MHz)'.format(type, i)] = component.speed + self['{} {} Size'.format(type, i)] = component.size + + # todo add Display size, ... + # todo add NetworkAdapter speedLink? + # todo add some ComputerAccessories class ManufacturerView(View): From 73c79fc827f5ec879fca68da4c32baa8ad1df076 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 25 Oct 2018 12:39:33 +0200 Subject: [PATCH 09/23] Add todo in tests rate and workbench --- tests/test_rate_workbench_v1.py | 3 ++- tests/test_workbench.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/test_rate_workbench_v1.py b/tests/test_rate_workbench_v1.py index da4a0a09..98aac008 100644 --- a/tests/test_rate_workbench_v1.py +++ b/tests/test_rate_workbench_v1.py @@ -217,6 +217,7 @@ def test_rate_processor_with_null_cores(): processor_rate = ProcessorRate().compute(cpu, WorkbenchRate()) + # todo result is not 1 != 1.376 .. check what's wrong assert processor_rate == 1, 'ProcessorRate returns incorrect value(rate)' @@ -230,7 +231,7 @@ def test_rate_processor_with_null_speed(): processor_rate = ProcessorRate().compute(cpu, WorkbenchRate()) - assert processor_rate == 1.06, 'ProcessorRate returns incorrect value(rate)' + assert round(processor_rate, 2) == 1.06, 'ProcessorRate returns incorrect value(rate)' def test_rate_computer_rate(): diff --git a/tests/test_workbench.py b/tests/test_workbench.py index 1b1b7f2a..0cee280a 100644 --- a/tests/test_workbench.py +++ b/tests/test_workbench.py @@ -193,6 +193,7 @@ def test_snapshot_real_eee_1001pxd(user: UserClient): assert rate['type'] == 'AggregateRate' assert rate['biosRange'] == 'C' assert rate['appearance'] > 0 + # todo check why rate func is not > 0 is 0 assert rate['functionality'] > 0 assert rate['rating'] > 0 and rate['rating'] != 1 components = snapshot['components'] From 81051e9951ac34c542907bb17a256c0ad6fe4f9f Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 25 Oct 2018 12:40:58 +0200 Subject: [PATCH 10/23] Add assert 'Register in' is a date --- tests/test_reports.py | 52 +++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/tests/test_reports.py b/tests/test_reports.py index 13ab4327..feb216d0 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -1,4 +1,5 @@ import csv +from datetime import datetime from io import StringIO from pathlib import Path @@ -13,7 +14,9 @@ def test_export_basic_snapshot(user: UserClient): Test export device information in a csv file """ snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, accept='text/csv') + csv_str, _ = user.get(res=Device, + accept='text/csv', + query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) @@ -22,10 +25,12 @@ def test_export_basic_snapshot(user: UserClient): obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - # Pop(datetime) field d[1x][9] + assert isinstance(datetime.strptime(export_csv[1][9], '%c'), datetime), \ + 'Register in field is not a datetime' fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] export_csv[1] = export_csv[1][:9] + export_csv[1][10:] + # Pop dates fields from csv lists to compare them assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' @@ -35,17 +40,22 @@ def test_export_full_snapshot(user: UserClient): Test a export device with all information and a lot of components """ snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) - csv_str, _ = user.get(res=Device, accept='text/csv') + csv_str, _ = user.get(res=Device, + accept='text/csv', + query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) # Open fixture csv and transform to list - with Path(__file__).parent.joinpath('files').joinpath('full-real-eee.csv').open() as csv_file: + with Path(__file__).parent.joinpath('files').joinpath('real-eee-1001pxd.csv').open() \ + as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - # todo one pop for each devices - # One pop(datetime) fields d[1x][9] + assert isinstance(datetime.strptime(export_csv[1][9], '%c'), datetime), \ + 'Register in field is not a datetime' + + # Pop dates fields from csv lists to compare them fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] export_csv[1] = export_csv[1][:9] + export_csv[1][10:] @@ -70,16 +80,19 @@ def test_export_computer_monitor(user: UserClient): Test a export device type computer monitor """ snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, accept='text/csv') + csv_str, _ = user.get(res=Device, + accept='text/csv', + query=[('filter', {'type': ['ComputerMonitor']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) # Open fixture csv and transform to list - with Path(__file__).parent.joinpath('files').joinpath('computer-monitor.csv').open() as csv_file: + with Path(__file__).parent.joinpath('files').joinpath('computer-monitor.csv').open() \ + as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - # One pop(datetime) fields + # Pop dates fields from csv lists to compare them fixture_csv[1] = fixture_csv[1][:8] export_csv[1] = export_csv[1][:8] @@ -92,7 +105,9 @@ def test_export_keyboard(user: UserClient): Test a export device type keyboard """ snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, accept='text/csv') + csv_str, _ = user.get(res=Device, + accept='text/csv', + query=[('filter', {'type': ['Keyboard']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) @@ -101,7 +116,7 @@ def test_export_keyboard(user: UserClient): obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - # One pop(datetime) fields + # Pop dates fields from csv lists to compare them fixture_csv[1] = fixture_csv[1][:8] export_csv[1] = export_csv[1][:8] @@ -113,5 +128,18 @@ def test_export_multiple_devices(user: UserClient): """ Test a export multiple devices with different components and information """ - # todo test multiple devices + pass + + +def test_export_only_components(user: UserClient): + """ + Test a export only components + """ + pass + + +def test_export_computers__and_components(user: UserClient): + """ + Test a export multiple devices (computers and independent components) + """ pass From 9b265d27e844b7e09713843d4f36acc861837aa0 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 25 Oct 2018 12:44:24 +0200 Subject: [PATCH 11/23] Clean code export csv --- ereuse_devicehub/resources/device/views.py | 61 +--------------------- 1 file changed, 1 insertion(+), 60 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index bc99e349..5b40c0c8 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -151,28 +151,6 @@ class DeviceView(View): :param query: :return: """ - data = StringIO() - cw = csv.writer(data) - first = True - # todo fix if only export components - for device in query: - # if not isinstance(device, Component): - d = DeviceRow(device) - if first: - cw.writerow(name for name in d.keys()) - cw.writerow(v for v in d.values()) - first = False - elif isinstance(device, Computer): - cw.writerow(v for v in d.values()) - output = make_response(data.getvalue()) - output.headers['Content-Disposition'] = 'attachment; filename=export.csv' - output.headers['Content-type'] = 'text/csv' - return output - - -""" Export Erased Certificate Code - - def generate_erased_certificate(self, query): data = StringIO() cw = csv.writer(data) first = True @@ -182,52 +160,15 @@ class DeviceView(View): cw.writerow(name for name in d.keys()) first = False cw.writerow(v for v in d.values()) - # cw = csv.DictWriter(d, fieldnames=keys) output = make_response(data.getvalue()) output.headers['Content-Disposition'] = 'attachment; filename=export.csv' output.headers['Content-type'] = 'text/csv' return output -class EraseDataStorage(OrderedDict): - def __init__(self, device: Device) -> None: - super().__init__() - self.device = device - - # General Information - self['Organization'] = device.org - self['Date report'] = datetime.time() - self['Erase Information'] = device.org + 'ha borrado los siguientes discos acorde a ..' + eraseType - # Devices information for row {TABLE} - self['Computer Serial Number'] = device.serial_number - self['Computer Tag'] = device.tags - self['DataStorage Serial Number'] = device.components.data_storage.serial_number - self['Erase Date'] = device.event.erase.event_date - self['Erase Status'] = device.event.erase.privacy - self['Erase Type'] = device.event.erase.type - # For each DataStorage - self['DataStorage Serial Number'] = device.components.data_storage.serial_number - self['DataStorage Model'] = device.components.data_storage.model - self['DataStorage Manufacturer'] = device.components.data_storage.manufacturer - self['DataStorage Size (MB)'] = device.data_storage_size - self['Erase Date'] = device.event.erase.event_date - self['Erase Status'] = device.components.data_storage.privacy - # Erase information - self['Tool used to erase'] = device.erase_tool - self['Steps'] = device.events.erase.steps - self['Elapsed time'] = device.events.erase.erase_time - self['Final clean with zeros'] = 'Yes|No' - # Optional more computer info - self['Computer Serial Number'] = device.serial_number - self['Computer Model'] = device.model - self['Computer Manufacturer'] = device.manufacturer - self['Computer Tag'] = device.tags -""" - - class DeviceRow(OrderedDict): NUMS = { - Display.t: 2, + Display.t: 1, Processor.t: 2, GraphicCard.t: 2, Motherboard.t: 1, From 78121d39b960017ed9e86234a9e4b98fc1aa8e22 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Thu, 25 Oct 2018 13:39:28 +0200 Subject: [PATCH 12/23] Update fixtures csv files --- tests/files/basic.csv | 4 ++-- tests/files/full-real-eee.csv | 2 -- tests/files/real-eee-1001pxd.csv | 2 ++ 3 files changed, 4 insertions(+), 4 deletions(-) delete mode 100644 tests/files/full-real-eee.csv create mode 100644 tests/files/real-eee-1001pxd.csv diff --git a/tests/files/basic.csv b/tests/files/basic.csv index 4d01b6dd..8e5381b0 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ -Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Display 2,Display 2 Manufacturer,Display 2 Model,Display 2 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 1 Size,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 -Desktop,ComputerChassis.Microtower,,,,d1s,d1ml,d1mr,,Wed Oct 24 20:19:44 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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 1 Size,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 +Desktop,ComputerChassis.Microtower,,,,d1s,d1ml,d1mr,,Thu Oct 25 10:24:30 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, diff --git a/tests/files/full-real-eee.csv b/tests/files/full-real-eee.csv deleted file mode 100644 index 73e70f71..00000000 --- a/tests/files/full-real-eee.csv +++ /dev/null @@ -1,2 +0,0 @@ -Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Display 2,Display 2 Manufacturer,Display 2 Model,Display 2 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,Motherboard 1 Slots,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 1 Size,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,ComputerChassis.Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,,Wed Oct 24 20:42:19 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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 diff --git a/tests/files/real-eee-1001pxd.csv b/tests/files/real-eee-1001pxd.csv new file mode 100644 index 00000000..77bdf39b --- /dev/null +++ b/tests/files/real-eee-1001pxd.csv @@ -0,0 +1,2 @@ +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Motherboard 1 Slots,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 1 Size,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,ComputerChassis.Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,,Thu Oct 25 10:26:02 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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 From 3e636ea2c9eb26d157f251bd4cecfd582c6d4319 Mon Sep 17 00:00:00 2001 From: JNadeu Date: Tue, 13 Nov 2018 17:58:26 +0100 Subject: [PATCH 13/23] fix reports test and fixtures --- ereuse_devicehub/resources/device/views.py | 9 +++++++-- tests/files/basic.csv | 2 +- tests/files/real-eee-1001pxd.csv | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index 2ebef9bb..ba26873e 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -1,11 +1,14 @@ +import csv import datetime +from io import StringIO import marshmallow -from flask import current_app as app, render_template, request +from flask import current_app as app, render_template, request, make_response from flask.json import jsonify from flask_sqlalchemy import Pagination from marshmallow import fields, fields as f, validate as v from sqlalchemy.orm import aliased +from sqlalchemy.util import OrderedDict from teal import query from teal.cache import cache from teal.resource import View @@ -14,7 +17,9 @@ from ereuse_devicehub import auth from ereuse_devicehub.db import db from ereuse_devicehub.query import SearchQueryParser from ereuse_devicehub.resources import search -from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer +from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \ + Display, Processor, GraphicCard, Motherboard, NetworkAdapter, DataStorage, RamModule, \ + SoundCard from ereuse_devicehub.resources.device.search import DeviceSearch from ereuse_devicehub.resources.event.models import Rate from ereuse_devicehub.resources.lot.models import LotDeviceDescendants diff --git a/tests/files/basic.csv b/tests/files/basic.csv index 8e5381b0..db045b6d 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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 1 Size,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 -Desktop,ComputerChassis.Microtower,,,,d1s,d1ml,d1mr,,Thu Oct 25 10:24:30 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, +Desktop,Microtower,,,,d1s,d1ml,d1mr,,Tue Nov 13 17:20:42 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, diff --git a/tests/files/real-eee-1001pxd.csv b/tests/files/real-eee-1001pxd.csv index 77bdf39b..2debf295 100644 --- a/tests/files/real-eee-1001pxd.csv +++ b/tests/files/real-eee-1001pxd.csv @@ -1,2 +1,2 @@ Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Motherboard 1 Slots,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 1 Size,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,ComputerChassis.Netbook,,,,b8oaas048286,1001pxd,asustek computer inc.,,Thu Oct 25 10:26:02 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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.,,Thu Oct 25 10:26:02 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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 From 32e696c57cc3a86d72c0b88404099121851b3230 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Wed, 13 Feb 2019 18:59:14 +0100 Subject: [PATCH 14/23] Fix rate related issues --- ereuse_devicehub/db.py | 1 + ereuse_devicehub/resources/event/models.py | 45 +++-- ereuse_devicehub/resources/event/rate/main.py | 7 +- ...sktop-9644w8n-lenovo-0169622.snapshot.yaml | 121 +++++++++++++ ...k-hewlett-packard-cnd52270fw.snapshot.yaml | 170 ++++++++++++++++++ tests/test_snapshot.py | 11 ++ 6 files changed, 337 insertions(+), 18 deletions(-) create mode 100644 tests/files/desktop-9644w8n-lenovo-0169622.snapshot.yaml create mode 100644 tests/files/laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot.yaml diff --git a/ereuse_devicehub/db.py b/ereuse_devicehub/db.py index 5fc091cb..b82e714f 100644 --- a/ereuse_devicehub/db.py +++ b/ereuse_devicehub/db.py @@ -36,6 +36,7 @@ class SQLAlchemy(SchemaSQLAlchemy): # manually import them all the time UUID = postgresql.UUID CIText = citext.CIText + PSQL_INT_MAX = 2147483648 def drop_all(self, bind='__all__', app=None, common_schema=True): """A faster nuke-like option to drop everything.""" diff --git a/ereuse_devicehub/resources/event/models.py b/ereuse_devicehub/resources/event/models.py index cad8f8ee..946a97b8 100644 --- a/ereuse_devicehub/resources/event/models.py +++ b/ereuse_devicehub/resources/event/models.py @@ -593,7 +593,12 @@ class Rate(JoinedWithOneDeviceMixin, EventWithOneDevice): plus the ``WorkbenchRate`` from 1. """ rating = Column(Float(decimal_return_scale=2), check_range('rating', *RATE_POSITIVE)) - rating.comment = """The rating for the content.""" + rating.comment = """The rating for the content. + + This value is automatically set by rating algorithms. In case that + no algorithm is defined per the device and type of rate, this + value is None. + """ software = Column(DBEnum(RatingSoftware)) software.comment = """The algorithm used to produce this rating.""" version = Column(StrictVersionType) @@ -604,8 +609,7 @@ class Rate(JoinedWithOneDeviceMixin, EventWithOneDevice): @property def rating_range(self) -> RatingRange: - if self.rating: - return RatingRange.from_score(self.rating) + return RatingRange.from_score(self.rating) if self.rating else None @declared_attr def __mapper_args__(cls): @@ -782,13 +786,12 @@ class AggregateRate(Rate): @classmethod def from_workbench_rate(cls, rate: WorkbenchRate): - aggregate = cls() - aggregate.rating = rate.rating - aggregate.software = rate.software - aggregate.appearance = rate.appearance - aggregate.functionality = rate.functionality - aggregate.device = rate.device - aggregate.workbench = rate + aggregate = cls(rating=rate.rating, + software=rate.software, + appearance=rate.appearance, + functionality=rate.functionality, + device=rate.device, + workbench=rate) return aggregate @@ -836,7 +839,7 @@ class Price(JoinedWithOneDeviceMixin, EventWithOneDevice): @classmethod def to_price(cls, value: Union[Decimal, float], rounding=ROUND) -> Decimal: """Returns a Decimal value with the correct scale for Price.price.""" - if isinstance(value, float): + if isinstance(value, (float, int)): value = Decimal(value) # equation from marshmallow.fields.Decimal return value.quantize(Decimal((0, (1,), -cls.SCALE)), rounding=rounding) @@ -920,8 +923,8 @@ class EreusePrice(Price): self.warranty2 = EreusePrice.Type(rate[self.WARRANTY2][role], price) def __init__(self, rating: AggregateRate, **kwargs) -> None: - if rating.rating_range == RatingRange.VERY_LOW: - raise ValueError('Cannot compute price for Range.VERY_LOW') + if not rating.rating_range or rating.rating_range == RatingRange.VERY_LOW: + raise InvalidRangeForPrice() # We pass ROUND_UP strategy so price is always greater than what refurbisher... amounts price = self.to_price(rating.rating * self.MULTIPLIER[rating.device.__class__], ROUND_UP) super().__init__(rating=rating, @@ -993,7 +996,7 @@ class TestDataStorage(Test): assessment = Column(Boolean) reallocated_sector_count = Column(SmallInteger) power_cycle_count = Column(SmallInteger) - reported_uncorrectable_errors = Column(SmallInteger) + _reported_uncorrectable_errors = Column('reported_uncorrectable_errors', Integer) command_timeout = Column(Integer) current_pending_sector_count = Column(SmallInteger) offline_uncorrectable = Column(SmallInteger) @@ -1021,6 +1024,16 @@ class TestDataStorage(Test): t += self.description return t + @property + def reported_uncorrectable_errors(self): + return self._reported_uncorrectable_errors + + @reported_uncorrectable_errors.setter + def reported_uncorrectable_errors(self, value): + # There is no value for a stratospherically big number + self._reported_uncorrectable_errors = min(value, db.PSQL_INT_MAX) + + class StressTest(Test): """The act of stressing (putting to the maximum capacity) @@ -1401,3 +1414,7 @@ def update_parent(target: Union[EraseBasic, Test, Install], device: Device, _, _ target.parent = None if isinstance(device, Component): target.parent = device.parent + + +class InvalidRangeForPrice(ValueError): + pass diff --git a/ereuse_devicehub/resources/event/rate/main.py b/ereuse_devicehub/resources/event/rate/main.py index 69213ba7..d8879bd9 100644 --- a/ereuse_devicehub/resources/event/rate/main.py +++ b/ereuse_devicehub/resources/event/rate/main.py @@ -4,8 +4,8 @@ from typing import Set, Union from ereuse_devicehub.resources.device.models import Device from ereuse_devicehub.resources.enums import RatingSoftware -from ereuse_devicehub.resources.event.models import AggregateRate, EreusePrice, Rate, \ - WorkbenchRate +from ereuse_devicehub.resources.event.models import AggregateRate, EreusePrice, \ + InvalidRangeForPrice, Rate, WorkbenchRate from ereuse_devicehub.resources.event.rate.workbench import v1_0 RATE_TYPES = { @@ -72,7 +72,6 @@ def main(rating_model: WorkbenchRate, if soft == software and vers == version: aggregation = AggregateRate.from_workbench_rate(rating) events.add(aggregation) - with suppress(ValueError): - # We will have exception if range == VERY_LOW + with suppress(InvalidRangeForPrice): # We will have exception if range == VERY_LOW events.add(EreusePrice(aggregation)) return events diff --git a/tests/files/desktop-9644w8n-lenovo-0169622.snapshot.yaml b/tests/files/desktop-9644w8n-lenovo-0169622.snapshot.yaml new file mode 100644 index 00000000..f5cf71f7 --- /dev/null +++ b/tests/files/desktop-9644w8n-lenovo-0169622.snapshot.yaml @@ -0,0 +1,121 @@ +{ + "closed": true, + "components": [ + { + "events": [], + "manufacturer": "Intel Corporation", + "model": "NM10/ICH7 Family High Definition Audio Controller", + "serialNumber": null, + "type": "SoundCard" + }, + { + "events": [], + "manufacturer": "Broadcom Inc. and subsidiaries", + "model": "NetLink BCM5786 Gigabit Ethernet PCI Express", + "serialNumber": "00:1a:6b:5e:7f:10", + "speed": 1000, + "type": "NetworkAdapter", + "wireless": false + }, + { + "events": [], + "format": "DIMM", + "interface": "DDR", + "manufacturer": null, + "model": null, + "serialNumber": null, + "size": 1024, + "speed": 133.0, + "type": "RamModule" + }, + { + "events": [], + "format": "DIMM", + "interface": "DDR", + "manufacturer": null, + "model": null, + "serialNumber": null, + "size": 1024, + "speed": 133.0, + "type": "RamModule" + }, + { + "address": 64, + "events": [ + { + "elapsed": 33, + "rate": 32.9274, + "type": "BenchmarkProcessorSysbench" + }, + { + "elapsed": 0, + "rate": 8771.5, + "type": "BenchmarkProcessor" + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core2 Duo CPU E4500 @ 2.20GHz", + "serialNumber": null, + "speed": 1.1, + "threads": 2, + "type": "Processor" + }, + { + "events": [], + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "82946GZ/GL Integrated Graphics Controller", + "serialNumber": null, + "type": "GraphicCard" + }, + { + "events": [], + "firewire": 0, + "manufacturer": "LENOVO", + "model": "LENOVO", + "pcmcia": 0, + "serial": 1, + "serialNumber": null, + "slots": 0, + "type": "Motherboard", + "usb": 5 + } + ], + "device": { + "chassis": "Microtower", + "events": [ + { + "appearanceRange": "D", + "biosRange": "E", + "functionalityRange": "D", + "type": "WorkbenchRate" + }, + { + "elapsed": 300, + "severity": "Info", + "type": "StressTest" + }, + { + "elapsed": 2, + "rate": 1.4968, + "type": "BenchmarkRamSysbench" + } + ], + "manufacturer": "LENOVO", + "model": "9644W8N", + "serialNumber": "0169622", + "type": "Desktop" + }, + "elapsed": 338, + "endTime": "2019-02-13T11:57:31.378330+00:00", + "expectedEvents": [ + "Benchmark", + "TestDataStorage", + "StressTest", + "Install" + ], + "software": "Workbench", + "type": "Snapshot", + "uuid": "d7904bd3-7d0f-4918-86b1-e21bfab738f9", + "version": "11.0b5" +} diff --git a/tests/files/laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot.yaml b/tests/files/laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot.yaml new file mode 100644 index 00000000..4824615a --- /dev/null +++ b/tests/files/laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot.yaml @@ -0,0 +1,170 @@ +{ + "closed": true, + "components": [ + { + "events": [], + "manufacturer": "Qualcomm Atheros", + "model": "QCA9565 / AR9565 Wireless Network Adapter", + "serialNumber": "ac:e0:10:c2:e3:ac", + "type": "NetworkAdapter", + "wireless": true + }, + { + "events": [], + "manufacturer": "Realtek Semiconductor Co., Ltd.", + "model": "RTL810xE PCI Express Fast Ethernet controller", + "serialNumber": "30:8d:99:25:6c:d9", + "speed": 100, + "type": "NetworkAdapter", + "wireless": false + }, + { + "events": [], + "manufacturer": "Advanced Micro Devices, Inc. AMD/ATI", + "model": "Kabini HDMI/DP Audio", + "serialNumber": null, + "type": "SoundCard" + }, + { + "events": [], + "manufacturer": "Chicony Electronics Co.,Ltd.", + "model": "HP Webcam", + "serialNumber": "0x0001", + "type": "SoundCard" + }, + { + "events": [], + "manufacturer": "Advanced Micro Devices, Inc. AMD", + "model": "FCH Azalia Controller", + "serialNumber": null, + "type": "SoundCard" + }, + { + "events": [], + "format": "SODIMM", + "interface": "DDR3", + "manufacturer": "Hynix", + "model": "HMT451S6AFR8A-PB", + "serialNumber": "11743764", + "size": 4096, + "speed": 667.0, + "type": "RamModule" + }, + { + "address": 64, + "cores": 2, + "events": [ + { + "elapsed": 0, + "rate": 3992.32, + "type": "BenchmarkProcessor" + }, + { + "elapsed": 65, + "rate": 65.3007, + "type": "BenchmarkProcessorSysbench" + } + ], + "manufacturer": "Advanced Micro Devices AMD", + "model": "AMD E1-2100 APU with Radeon HD Graphics", + "serialNumber": null, + "speed": 0.9, + "threads": 2, + "type": "Processor" + }, + { + "events": [ + { + "elapsed": 12, + "readSpeed": 90.0, + "type": "BenchmarkDataStorage", + "writeSpeed": 30.7 + }, + { + "assessment": true, + "commandTimeout": 1341, + "currentPendingSectorCount": 0, + "elapsed": 113, + "length": "Short", + "lifetime": 1782, + "offlineUncorrectable": 0, + "powerCycleCount": 806, + "reallocatedSectorCount": 224, + "reportedUncorrectableErrors": 9961472, + "severity": "Info", + "status": "Completed without error", + "type": "TestDataStorage" + }, + { + "address": 32, + "elapsed": 690, + "name": "LinuxMint-19-x86-es-2018-12.fsa", + "severity": "Info", + "type": "Install" + } + ], + "interface": "ATA", + "manufacturer": null, + "model": "HGST HTS545050A7", + "serialNumber": "TE85134N34LNSN", + "size": 476940, + "type": "HardDrive" + }, + { + "events": [], + "manufacturer": "Advanced Micro Devices, Inc. AMD/ATI", + "memory": 256.0, + "model": "Kabini Radeon HD 8210", + "serialNumber": null, + "type": "GraphicCard" + }, + { + "events": [], + "firewire": 0, + "manufacturer": "Hewlett-Packard", + "model": "21F7", + "pcmcia": 0, + "serial": 1, + "serialNumber": "PEHERF41U8P9TV", + "slots": 0, + "type": "Motherboard", + "usb": 5 + } + ], + "device": { + "chassis": "Netbook", + "events": [ + { + "appearanceRange": "A", + "functionalityRange": "A", + "type": "WorkbenchRate" + }, + { + "elapsed": 300, + "severity": "Info", + "type": "StressTest" + }, + { + "elapsed": 6, + "rate": 5.8783, + "type": "BenchmarkRamSysbench" + } + ], + "manufacturer": "Hewlett-Packard", + "model": "HP 255 G3 Notebook", + "serialNumber": "CND52270FW", + "type": "Laptop" + }, + "elapsed": 1194, + "endTime": "2019-02-13T10:13:50.535387+00:00", + "expectedEvents": [ + "Benchmark", + "TestDataStorage", + "StressTest", + "Install" + ], + "software": "Workbench", + "type": "Snapshot", + "uuid": "ca564895-567e-4ac2-9a0d-2d1402528687", + "version": "11.0b5" +} diff --git a/tests/test_snapshot.py b/tests/test_snapshot.py index 2b7ac98d..ce7b5f37 100644 --- a/tests/test_snapshot.py +++ b/tests/test_snapshot.py @@ -453,3 +453,14 @@ def test_snapshot_keyboard(user: UserClient): snapshot = snapshot_and_check(user, s, event_types=('ManualRate',)) keyboard = snapshot['device'] assert keyboard['layout'] == 'ES' + + +def test_pc_rating_rate_none(user: UserClient): + """Tests a Snapshot with EraseSectors.""" + s = file('desktop-9644w8n-lenovo-0169622.snapshot') + snapshot, _ = user.post(res=Snapshot, data=s) + + +def test_pc_2(user: UserClient): + s = file('laptop-hp_255_g3_notebook-hewlett-packard-cnd52270fw.snapshot') + snapshot, _ = user.post(res=Snapshot, data=s) From 07e8be829e0a8ff1ebc4da060be835d8467fc84c Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 18 Feb 2019 12:43:50 +0100 Subject: [PATCH 15/23] Unify Snapshot's POST view with Devicehub's; bugfixes --- ereuse_devicehub/resources/event/__init__.py | 5 +- ereuse_devicehub/resources/event/views.py | 31 +- ereuse_devicehub/resources/user/models.py | 5 + file.json | 2546 +++++++++++++++++ requirements.txt | 2 +- setup.py | 2 +- .../1-device-with-components.snapshot.yaml | 27 +- ...ice-with-components-of-first.snapshot.yaml | 19 +- ...-and-adding-processor-from-2.snapshot.yaml | 21 +- ...ssor.snapshot-and-adding-graphic-card.yaml | 19 +- tests/test_basic.py | 1 - tests/test_db.py | 30 + 12 files changed, 2647 insertions(+), 61 deletions(-) create mode 100644 file.json create mode 100644 tests/test_db.py diff --git a/ereuse_devicehub/resources/event/__init__.py b/ereuse_devicehub/resources/event/__init__.py index 2acc7fd9..a9f12950 100644 --- a/ereuse_devicehub/resources/event/__init__.py +++ b/ereuse_devicehub/resources/event/__init__.py @@ -4,7 +4,7 @@ from teal.resource import Converters, Resource from ereuse_devicehub.resources.device.sync import Sync from ereuse_devicehub.resources.event import schemas -from ereuse_devicehub.resources.event.views import EventView, SnapshotView +from ereuse_devicehub.resources.event.views import EventView class EventDef(Resource): @@ -90,13 +90,14 @@ class InstallDef(EventDef): class SnapshotDef(EventDef): - VIEW = SnapshotView + VIEW = None SCHEMA = schemas.Snapshot def __init__(self, app, import_name=__name__.split('.')[0], static_folder=None, static_url_path=None, template_folder=None, url_prefix=None, subdomain=None, url_defaults=None, root_path=None, cli_commands: Iterable[Tuple[Callable, str or None]] = tuple()): + url_prefix = '/{}'.format(EventDef.resource) super().__init__(app, import_name, static_folder, static_url_path, template_folder, url_prefix, subdomain, url_defaults, root_path, cli_commands) self.sync = Sync() diff --git a/ereuse_devicehub/resources/event/views.py b/ereuse_devicehub/resources/event/views.py index 0d6e846c..e0247bfe 100644 --- a/ereuse_devicehub/resources/event/views.py +++ b/ereuse_devicehub/resources/event/views.py @@ -12,14 +12,21 @@ from ereuse_devicehub.resources.device.models import Component, Computer from ereuse_devicehub.resources.enums import SnapshotSoftware from ereuse_devicehub.resources.event.models import Event, Snapshot, WorkbenchRate +SUPPORTED_WORKBENCH = StrictVersion('11.0') + class EventView(View): def post(self): """Posts an event.""" json = request.get_json(validate=False) - if 'type' not in json: + if not json or 'type' not in json: raise ValidationError('Resource needs a type.') - e = app.resources[json['type']].schema.load(json) + # todo there should be a way to better get subclassess resource + # defs + resource_def = app.resources[json['type']] + e = resource_def.schema.load(json) + if json['type'] == Snapshot.t: + return self.snapshot(e, resource_def) Model = db.Model._decl_class_registry.data[json['type']]() event = Model(**e) db.session.add(event) @@ -34,25 +41,20 @@ class EventView(View): event = Event.query.filter_by(id=id).one() return self.schema.jsonify(event) - -SUPPORTED_WORKBENCH = StrictVersion('11.0') - - -class SnapshotView(View): - def post(self): + def snapshot(self, snapshot_json: dict, resource_def): """ Performs a Snapshot. See `Snapshot` section in docs for more info. """ - s = request.get_json() # Note that if we set the device / components into the snapshot # model object, when we flush them to the db we will flush # snapshot, and we want to wait to flush snapshot at the end - device = s.pop('device') # type: Computer - components = s.pop('components') \ - if s['software'] == SnapshotSoftware.Workbench else None # type: List[Component] - snapshot = Snapshot(**s) + device = snapshot_json.pop('device') # type: Computer + components = None + if snapshot_json['software'] == SnapshotSoftware.Workbench: + components = snapshot_json.pop('components') # type: List[Component] + snapshot = Snapshot(**snapshot_json) # Remove new events from devices so they don't interfere with sync events_device = set(e for e in device.events_one) @@ -62,10 +64,9 @@ class SnapshotView(View): for component in components: component.events_one.clear() - # noinspection PyArgumentList assert not device.events_one assert all(not c.events_one for c in components) if components else True - db_device, remove_events = self.resource_def.sync.run(device, components) + db_device, remove_events = resource_def.sync.run(device, components) snapshot.device = db_device snapshot.events |= remove_events | events_device # Set events to snapshot # commit will change the order of the components by what diff --git a/ereuse_devicehub/resources/user/models.py b/ereuse_devicehub/resources/user/models.py index da5555dd..b471724a 100644 --- a/ereuse_devicehub/resources/user/models.py +++ b/ereuse_devicehub/resources/user/models.py @@ -24,6 +24,7 @@ class User(Thing): backref=db.backref('users', lazy=True, collection_class=set), secondary=lambda: UserInventory.__table__, collection_class=set) + # todo set restriction that user has, at least, one active db def __init__(self, email, password=None, inventories=None) -> None: @@ -41,6 +42,10 @@ class User(Thing): def __repr__(self) -> str: return ''.format(self) + @property + def type(self) -> str: + return self.__class__.__name__ + @property def individual(self): """The individual associated for this database, or None.""" diff --git a/file.json b/file.json new file mode 100644 index 00000000..a3c144bd --- /dev/null +++ b/file.json @@ -0,0 +1,2546 @@ +{ + "attempts": 0, + "ip": "192.168.2.143", + "names": [], + "snapshots": [ + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "f4585175-fce5-4347-b65b-154ec41c2e64", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7574 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24743.88 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6765 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.6319270000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "237810AC", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2378107D", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 135.0, + "writingSpeed": 21.1 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:14:28", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:46:39", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:00:34", + "startingTime": "2019-02-15T10:00:34", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:14:28", + "startingTime": "2019-02-15T11:14:28", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APCX0R", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 21357, + "passedLifetime": 21357, + "powerCycleCount": 1397, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:c4:b8", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:19:47", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTXF17", + "type": "Desktop" + }, + "elapsed": "2:31:23", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "5883bda1-87c5-42b2-909b-2df42f304dc2", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.757 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24743.84 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6805 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.5999510000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9 1", + "serialNumber": "23789D4E", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23789D6B", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 136.0, + "writingSpeed": 22.0 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T10:24:23", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:51:29", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:07:09", + "startingTime": "2019-02-15T10:07:09", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T10:24:23", + "startingTime": "2019-02-15T10:24:23", + "success": false + } + ], + "success": false + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APDN6M", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 42137, + "passedLifetime": 42137, + "powerCycleCount": 1949, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:97:be", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T09:24:49", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWK56", + "type": "Desktop" + }, + "elapsed": "1:36:25", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "0ff1b0f5-2386-44bc-9d80-761c17271bd4", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7567 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24743.8 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6986 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.599761 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "CT51264BA160B.C16F", + "serialNumber": "A31DB3D2", + "size": 4096, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "CT51264BA160B.C16F", + "serialNumber": "A4168D04", + "size": 4096, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 136.0, + "writingSpeed": 20.7 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:21:10", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:51:39", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:06:26", + "startingTime": "2019-02-15T10:06:26", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:21:10", + "startingTime": "2019-02-15T11:21:10", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APB9Q2", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 46742, + "passedLifetime": 46742, + "powerCycleCount": 1263, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 1, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:99:e9", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:21:32", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWZ24", + "type": "Desktop" + }, + "elapsed": "2:33:03", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "9a70d5cc-ea7c-4197-a087-4ac17c2c5f2b", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7573 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24740.4 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6766 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.5999510000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "072BD846", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "072BD7B6", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 126.0, + "writingSpeed": 19.7 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:31:12", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:51:20", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:11:21", + "startingTime": "2019-02-15T10:11:21", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:31:12", + "startingTime": "2019-02-15T11:31:12", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2AA624X", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 1, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 37924, + "passedLifetime": 37924, + "powerCycleCount": 1760, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 1, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:c8:38", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:31:23", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTXT20", + "type": "Desktop" + }, + "elapsed": "2:43:24", + "inventory": { + "elapsed": "0:00:27" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "cc1d3699-29ee-4863-8dc0-89973d7a8d45", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7625 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.96 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6795 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.624926 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23780FF4", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23780FE5", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 132.0, + "writingSpeed": 20.7 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:18:30", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:44:08", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:01:22", + "startingTime": "2019-02-15T10:01:22", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:18:30", + "startingTime": "2019-02-15T11:18:30", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2AAC2K5", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 22514, + "passedLifetime": 22514, + "powerCycleCount": 769, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:cb:4b", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:25:57", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTXF58", + "type": "Desktop" + }, + "elapsed": "2:37:54", + "inventory": { + "elapsed": "0:00:27" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "4485fa87-bd30-46ce-ab92-b5e913bec675", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7268 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.24 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6768 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.5999510000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "237814B7", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "237816BB", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 136.0, + "writingSpeed": 20.5 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:18:43", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:50:36", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:04:42", + "startingTime": "2019-02-15T10:04:42", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:18:43", + "startingTime": "2019-02-15T11:18:43", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APGZS7", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 31232, + "passedLifetime": 31232, + "powerCycleCount": 1013, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:9d:cb", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:20:07", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTVY71", + "type": "Desktop" + }, + "elapsed": "2:31:39", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "deac0a5f-11d4-4699-b998-93ed458eb7ac", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7552 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.24 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6785 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.599761 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2377FA0D", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2377FED7", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 132.0, + "writingSpeed": 21.4 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T12:23:58", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T09:50:47", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T11:07:25", + "startingTime": "2019-02-15T11:07:25", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T12:23:58", + "startingTime": "2019-02-15T12:23:58", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2ANQ1Y5", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 40927, + "passedLifetime": 40927, + "powerCycleCount": 1099, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:b8:9c", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:25:09", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWA58", + "type": "Desktop" + }, + "elapsed": "2:36:42", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "53465692-c696-4287-80c4-6ff16fda9974", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7122 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.12 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.701 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.599761 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23789432", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2378940D", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 142.0, + "writingSpeed": 22.2 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:13:59", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:50:05", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:02:56", + "startingTime": "2019-02-15T10:02:56", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:13:59", + "startingTime": "2019-02-15T11:13:59", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APBGND", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 34082, + "passedLifetime": 34082, + "powerCycleCount": 448, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:98:8d", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:15:52", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWY73", + "type": "Desktop" + }, + "elapsed": "2:27:27", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "3d184ebb-e74f-4432-9709-169c2b082d29", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7566 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24741.12 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6868 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.5999510000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "09E3CE28", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "41B61358", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 137.0, + "writingSpeed": 20.1 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:23:14", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:54:06", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:08:41", + "startingTime": "2019-02-15T10:08:41", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:23:14", + "startingTime": "2019-02-15T11:23:14", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2AA652D", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 15924, + "passedLifetime": 15924, + "powerCycleCount": 537, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:c9:3d", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:20:44", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWV65", + "type": "Desktop" + }, + "elapsed": "2:32:40", + "inventory": { + "elapsed": "0:00:27" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "50d26e0a-037a-4f30-8960-9278cbbf53c6", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7044 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24743.64 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6799 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.624926 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2377EDC3", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2377EDAC", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 130.0, + "writingSpeed": 21.1 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:17:04", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:45:34", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:01:20", + "startingTime": "2019-02-15T10:01:20", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:17:04", + "startingTime": "2019-02-15T11:17:04", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2A7LN8P", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 39961, + "passedLifetime": 39961, + "powerCycleCount": 774, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:c7:32", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:22:54", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTXF36", + "type": "Desktop" + }, + "elapsed": "2:35:03", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "8caee209-77f6-4fa8-b5c0-31a456fc51c2", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7585 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.92 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6772 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.628521 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "41135B58", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "41015B58", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 135.0, + "writingSpeed": 20.7 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:15:56", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:49:26", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:02:44", + "startingTime": "2019-02-15T10:02:44", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:15:56", + "startingTime": "2019-02-15T11:15:56", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2AAC5F9", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 46073, + "passedLifetime": 46073, + "powerCycleCount": 789, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:a6:04", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:18:04", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTXP55", + "type": "Desktop" + }, + "elapsed": "2:30:02", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "e5ba685b-d96a-4f20-b6de-cdaff62b0ea9", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7441 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24744.32 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6824 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.604681 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "237803F7", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "237809F2", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 129.0, + "writingSpeed": 20.6 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:27:13", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:45:54", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:06:38", + "startingTime": "2019-02-15T10:06:38", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:27:13", + "startingTime": "2019-02-15T11:27:13", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APCY9M", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 20662, + "passedLifetime": 20662, + "powerCycleCount": 1688, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:a1:0c", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:32:50", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWY30", + "type": "Desktop" + }, + "elapsed": "2:44:51", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "e075afda-11bb-4927-a10c-f216b4d411cb", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7624 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.16 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.7953 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.5999510000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Micron", + "model": "8KTF25664AZ-1G4M1", + "serialNumber": "E688B4A9", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Micron", + "model": "8KTF25664AZ-1G4M1", + "serialNumber": "E688B4B5", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 138.0, + "writingSpeed": 21.8 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:19:39", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:52:33", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:06:21", + "startingTime": "2019-02-15T10:06:21", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:19:39", + "startingTime": "2019-02-15T11:19:39", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APS51G", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 1, + "CurrentPendingSectorCount": 1720, + "OfflineUncorrectable": 1720, + "assessment": true, + "error": true, + "firstError": 976773072, + "lifetime": 53765, + "passedLifetime": 53765, + "powerCycleCount": 1041, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 201, + "status": "Completed: read failure", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "44:37:e6:90:af:e7", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:20:10", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "S4FVYG2", + "type": "Desktop" + }, + "elapsed": "2:30:54", + "inventory": { + "elapsed": "0:00:28" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 3, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "19c1e1d8-c135-4dbb-bfd5-b9453b8cc6e9", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7615 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24743.84 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.7073 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.6001400000000001 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9 1", + "serialNumber": "23789D4E", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23789D6B", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 136.0, + "writingSpeed": 22.0 + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2APDN6M", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 42139, + "passedLifetime": 42139, + "powerCycleCount": 1949, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:97:be", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T09:29:22", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWK56", + "type": "Desktop" + }, + "elapsed": "0:03:30", + "inventory": { + "elapsed": "0:00:25" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "8e0882c2-dbae-499c-abe9-426e8ec788c8", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.7507 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24746.64 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.7038 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.601086 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "09E7CE28", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Undefined", + "model": "RMR1810EC58E8F1333", + "serialNumber": "0902CF28", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 133.0, + "writingSpeed": 20.5 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:20:32", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:50:54", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:05:49", + "startingTime": "2019-02-15T10:05:49", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:20:32", + "startingTime": "2019-02-15T11:20:32", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "W2AAC2QB", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 38491, + "passedLifetime": 38491, + "powerCycleCount": 802, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:ca:b6", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:21:13", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWV63", + "type": "Desktop" + }, + "elapsed": "2:33:10", + "inventory": { + "elapsed": "0:00:26" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + }, + { + "@type": "devices:Snapshot", + "_error": null, + "_phases": 4, + "_saved": null, + "_totalPhases": 4, + "_uploaded": null, + "_uuid": "e2341753-6484-4a95-9e30-dd61e13f60ef", + "automatic": true, + "benchmarks": [ + { + "@type": "BenchmarkRamSysbench", + "score": 0.704 + } + ], + "components": [ + { + "@type": "Processor", + "address": 64, + "benchmarks": [ + { + "@type": "BenchmarkProcessor", + "score": 24738.16 + }, + { + "@type": "BenchmarkProcessorSysbench", + "score": 8.6803 + } + ], + "manufacturer": "Intel Corp.", + "model": "Intel Core i5-2400 CPU @ 3.10GHz", + "numberOfCores": 4, + "serialNumber": null, + "speed": 1.599572 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "23788693", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "RamModule", + "manufacturer": "Samsung", + "model": "M378B5773DH0-CH9", + "serialNumber": "2378867E", + "size": 2048, + "speed": 1333.0 + }, + { + "@type": "HardDrive", + "benchmark": { + "@type": "BenchmarkHardDrive", + "readingSpeed": 96.8, + "writingSpeed": 18.2 + }, + "erasure": { + "@type": "EraseBasic", + "cleanWithZeros": true, + "endingTime": "2019-02-15T11:24:37", + "secureRandomSteps": 1, + "startingTime": "2019-02-15T08:51:22", + "steps": [ + { + "@type": "Zeros", + "endingTime": "2019-02-15T10:08:10", + "startingTime": "2019-02-15T10:08:10", + "success": true + }, + { + "@type": "Random", + "endingTime": "2019-02-15T11:24:37", + "startingTime": "2019-02-15T11:24:37", + "success": true + } + ], + "success": true + }, + "interface": "ata\n", + "manufacturer": "Seagate", + "model": "ST500DM002-1BD14", + "serialNumber": "Z2ANQ0F2", + "size": 476940, + "test": { + "@type": "TestHardDrive", + "CommandTimeout": 0, + "CurrentPendingSectorCount": 0, + "OfflineUncorrectable": 0, + "assessment": true, + "error": false, + "firstError": null, + "lifetime": 29050, + "passedLifetime": 29050, + "powerCycleCount": 738, + "reallocatedSectorCount": 0, + "reportedUncorrectableErrors": 0, + "status": "Completed without error", + "type": "Short offline" + }, + "type": "HDD" + }, + { + "@type": "GraphicCard", + "manufacturer": "Intel Corporation", + "memory": 256.0, + "model": "2nd Generation Core Processor Family Integrated Graphics Controller", + "serialNumber": null + }, + { + "@type": "Motherboard", + "connectors": { + "firewire": 0, + "pcmcia": 0, + "serial": 1, + "usb": 2 + }, + "manufacturer": "LENOVO", + "model": null, + "serialNumber": "INVALID", + "totalSlots": 4, + "usedSlots": 2 + }, + { + "@type": "NetworkAdapter", + "manufacturer": "Intel Corporation", + "model": "82579LM Gigabit Network Connection", + "serialNumber": "cc:52:af:45:98:41", + "speed": 1000 + }, + { + "@type": "SoundCard", + "manufacturer": "Intel Corporation", + "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", + "serialNumber": null + } + ], + "date": "2019-02-15T10:24:53", + "device": { + "@type": "Computer", + "manufacturer": "LENOVO", + "model": "7072A37", + "serialNumber": "PBTWK83", + "type": "Desktop" + }, + "elapsed": "2:36:50", + "inventory": { + "elapsed": "0:00:29" + }, + "snapshotSoftware": "Workbench", + "tests": [ + { + "@type": "StressTest", + "elapsed": "0:02:00", + "success": true + } + ], + "version": "10.0b8" + } + ], + "usbs": [] +} diff --git a/requirements.txt b/requirements.txt index bf9d37e1..83c08615 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ requests[security]==2.19.1 requests-mock==1.5.2 SQLAlchemy==1.2.17 SQLAlchemy-Utils==0.33.11 -teal==0.2.0a36 +teal==0.2.0a37 webargs==4.0.0 Werkzeug==0.14.1 sqlalchemy-citext==1.3.post0 diff --git a/setup.py b/setup.py index fb53a90d..4d539e4f 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( long_description=long_description, long_description_content_type='text/markdown', install_requires=[ - 'teal>=0.2.0a36', # teal always first + 'teal>=0.2.0a37', # teal always first 'click', 'click-spinner', 'ereuse-utils[naming, test, session, cli]>=0.4b21', diff --git a/tests/files/1-device-with-components.snapshot.yaml b/tests/files/1-device-with-components.snapshot.yaml index 97b0dc98..afc0ce20 100644 --- a/tests/files/1-device-with-components.snapshot.yaml +++ b/tests/files/1-device-with-components.snapshot.yaml @@ -5,20 +5,21 @@ device: type: Desktop chassis: Tower components: -- manufacturer: p1c1m - serialNumber: p1c1s - type: Motherboard -- manufacturer: p1c2m - serialNumber: p1c2s - model: p1c2 - speed: 1.23 - cores: 2 - type: Processor -- manufacturer: p1c3m - serialNumber: p1c3s - type: GraphicCard - memory: 1.5 + - manufacturer: p1c1m + serialNumber: p1c1s + type: Motherboard + - manufacturer: p1c2m + serialNumber: p1c2s + model: p1c2 + speed: 1.23 + cores: 2 + type: Processor + - manufacturer: p1c3m + serialNumber: p1c3s + type: GraphicCard + memory: 1.5 elapsed: 25 software: Workbench uuid: 76860eca-c3fd-41f6-a801-6af7bd8cf832 version: '11.0' +type: Snapshot diff --git a/tests/files/2-second-device-with-components-of-first.snapshot.yaml b/tests/files/2-second-device-with-components-of-first.snapshot.yaml index 5062da56..0ff6c2b0 100644 --- a/tests/files/2-second-device-with-components-of-first.snapshot.yaml +++ b/tests/files/2-second-device-with-components-of-first.snapshot.yaml @@ -5,16 +5,17 @@ device: type: Desktop chassis: Microtower components: -- manufacturer: p2c1m - serialNumber: p2c1s - type: Motherboard -- manufacturer: p1c2m - serialNumber: p1c2s - model: p1c2 - speed: 1.23 - cores: 2 - type: Processor + - manufacturer: p2c1m + serialNumber: p2c1s + type: Motherboard + - manufacturer: p1c2m + serialNumber: p1c2s + model: p1c2 + speed: 1.23 + cores: 2 + type: Processor elapsed: 25 software: Workbench uuid: f2e02261-87a1-4a50-b9b7-92c0e476e5f2 version: '11.0' +type: Snapshot diff --git a/tests/files/3-first-device-but-removing-motherboard-and-adding-processor-from-2.snapshot.yaml b/tests/files/3-first-device-but-removing-motherboard-and-adding-processor-from-2.snapshot.yaml index bdf72b37..2a3ea83b 100644 --- a/tests/files/3-first-device-but-removing-motherboard-and-adding-processor-from-2.snapshot.yaml +++ b/tests/files/3-first-device-but-removing-motherboard-and-adding-processor-from-2.snapshot.yaml @@ -5,17 +5,18 @@ device: type: Desktop chassis: Microtower components: -- manufacturer: p1c2m - serialNumber: p1c2s - model: p1c2 - type: Processor - cores: 2 - speed: 1.23 -- manufacturer: p1c3m - serialNumber: p1c3s - type: GraphicCard - memory: 1.5 + - manufacturer: p1c2m + serialNumber: p1c2s + model: p1c2 + type: Processor + cores: 2 + speed: 1.23 + - manufacturer: p1c3m + serialNumber: p1c3s + type: GraphicCard + memory: 1.5 elapsed: 30 software: Workbench uuid: 3be271b6-5ef4-47d8-8237-5e1133eebfc6 version: '11.0' +type: Snapshot diff --git a/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml b/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml index 463f9b20..ba20cc28 100644 --- a/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml +++ b/tests/files/4-first-device-but-removing-processor.snapshot-and-adding-graphic-card.yaml @@ -5,16 +5,17 @@ device: type: Desktop chassis: Tower components: -- manufacturer: p1c4m - serialNumber: p1c4s - type: NetworkAdapter - speed: 1000 - wireless: False -- manufacturer: p1c3m - serialNumber: p1c3s - type: GraphicCard - memory: 1.5 + - manufacturer: p1c4m + serialNumber: p1c4s + type: NetworkAdapter + speed: 1000 + wireless: False + - manufacturer: p1c3m + serialNumber: p1c3s + type: GraphicCard + memory: 1.5 elapsed: 25 software: Workbench uuid: fd007eb4-48e3-454a-8763-169491904c6e version: '11.0' +type: Snapshot diff --git a/tests/test_basic.py b/tests/test_basic.py index e1f3daab..711dbf92 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -21,7 +21,6 @@ def test_api_docs(client: Client): '/users/', '/devices/', '/tags/', - '/snapshots/', '/users/login/', '/events/', '/lots/', diff --git a/tests/test_db.py b/tests/test_db.py new file mode 100644 index 00000000..e5c24510 --- /dev/null +++ b/tests/test_db.py @@ -0,0 +1,30 @@ +import datetime +from uuid import UUID + +from teal.db import UniqueViolation + + +def test_unique_violation(): + class IntegrityErrorMock: + def __init__(self) -> None: + self.params = { + 'uuid': UUID('f5efd26e-8754-46bc-87bf-fbccc39d60d9'), + 'version': '11.0', + 'software': 'Workbench', 'elapsed': datetime.timedelta(0, 4), + 'expected_events': None, + 'id': UUID('dbdef3d8-2cac-48cb-adb8-419bc3e59687') + } + + def __str__(self): + return """(psycopg2.IntegrityError) duplicate key value violates unique constraint "snapshot_uuid_key" + DETAIL: Key (uuid)=(f5efd26e-8754-46bc-87bf-fbccc39d60d9) already exists. + [SQL: 'INSERT INTO snapshot (uuid, version, software, elapsed, expected_events, id) + VALUES (%(uuid)s, %(version)s, %(software)s, %(elapsed)s, CAST(%(expected_events)s + AS snapshotexpectedevents[]), %(id)s)'] [parameters: {'uuid': UUID('f5efd26e-8754-46bc-87bf-fbccc39d60d9'), + 'version': '11.0', 'software': 'Workbench', 'elapsed': datetime.timedelta(0, 4), 'expected_events': None, + 'id': UUID('dbdef3d8-2cac-48cb-adb8-419bc3e59687')}] (Background on this error at: http://sqlalche.me/e/gkpj)""" + + u = UniqueViolation(IntegrityErrorMock()) + assert u.constraint == 'snapshot_uuid_key' + assert u.field_name == 'uuid' + assert u.field_value == UUID('f5efd26e-8754-46bc-87bf-fbccc39d60d9') From aa3b7aed7f9a8560c802edb325498c962fcc4326 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 18 Feb 2019 19:53:20 +0100 Subject: [PATCH 16/23] Delete unwanted file --- file.json | 2546 ----------------------------------------------------- 1 file changed, 2546 deletions(-) delete mode 100644 file.json diff --git a/file.json b/file.json deleted file mode 100644 index a3c144bd..00000000 --- a/file.json +++ /dev/null @@ -1,2546 +0,0 @@ -{ - "attempts": 0, - "ip": "192.168.2.143", - "names": [], - "snapshots": [ - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "f4585175-fce5-4347-b65b-154ec41c2e64", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7574 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24743.88 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6765 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.6319270000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "237810AC", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2378107D", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 135.0, - "writingSpeed": 21.1 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:14:28", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:46:39", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:00:34", - "startingTime": "2019-02-15T10:00:34", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:14:28", - "startingTime": "2019-02-15T11:14:28", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APCX0R", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 21357, - "passedLifetime": 21357, - "powerCycleCount": 1397, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:c4:b8", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:19:47", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTXF17", - "type": "Desktop" - }, - "elapsed": "2:31:23", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "5883bda1-87c5-42b2-909b-2df42f304dc2", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.757 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24743.84 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6805 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.5999510000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9 1", - "serialNumber": "23789D4E", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23789D6B", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 136.0, - "writingSpeed": 22.0 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T10:24:23", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:51:29", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:07:09", - "startingTime": "2019-02-15T10:07:09", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T10:24:23", - "startingTime": "2019-02-15T10:24:23", - "success": false - } - ], - "success": false - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APDN6M", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 42137, - "passedLifetime": 42137, - "powerCycleCount": 1949, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:97:be", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T09:24:49", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWK56", - "type": "Desktop" - }, - "elapsed": "1:36:25", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "0ff1b0f5-2386-44bc-9d80-761c17271bd4", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7567 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24743.8 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6986 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.599761 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "CT51264BA160B.C16F", - "serialNumber": "A31DB3D2", - "size": 4096, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "CT51264BA160B.C16F", - "serialNumber": "A4168D04", - "size": 4096, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 136.0, - "writingSpeed": 20.7 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:21:10", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:51:39", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:06:26", - "startingTime": "2019-02-15T10:06:26", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:21:10", - "startingTime": "2019-02-15T11:21:10", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APB9Q2", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 46742, - "passedLifetime": 46742, - "powerCycleCount": 1263, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 1, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:99:e9", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:21:32", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWZ24", - "type": "Desktop" - }, - "elapsed": "2:33:03", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "9a70d5cc-ea7c-4197-a087-4ac17c2c5f2b", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7573 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24740.4 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6766 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.5999510000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "072BD846", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "072BD7B6", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 126.0, - "writingSpeed": 19.7 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:31:12", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:51:20", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:11:21", - "startingTime": "2019-02-15T10:11:21", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:31:12", - "startingTime": "2019-02-15T11:31:12", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2AA624X", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 1, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 37924, - "passedLifetime": 37924, - "powerCycleCount": 1760, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 1, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:c8:38", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:31:23", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTXT20", - "type": "Desktop" - }, - "elapsed": "2:43:24", - "inventory": { - "elapsed": "0:00:27" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "cc1d3699-29ee-4863-8dc0-89973d7a8d45", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7625 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.96 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6795 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.624926 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23780FF4", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23780FE5", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 132.0, - "writingSpeed": 20.7 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:18:30", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:44:08", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:01:22", - "startingTime": "2019-02-15T10:01:22", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:18:30", - "startingTime": "2019-02-15T11:18:30", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2AAC2K5", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 22514, - "passedLifetime": 22514, - "powerCycleCount": 769, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:cb:4b", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:25:57", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTXF58", - "type": "Desktop" - }, - "elapsed": "2:37:54", - "inventory": { - "elapsed": "0:00:27" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "4485fa87-bd30-46ce-ab92-b5e913bec675", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7268 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.24 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6768 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.5999510000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "237814B7", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "237816BB", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 136.0, - "writingSpeed": 20.5 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:18:43", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:50:36", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:04:42", - "startingTime": "2019-02-15T10:04:42", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:18:43", - "startingTime": "2019-02-15T11:18:43", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APGZS7", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 31232, - "passedLifetime": 31232, - "powerCycleCount": 1013, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:9d:cb", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:20:07", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTVY71", - "type": "Desktop" - }, - "elapsed": "2:31:39", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "deac0a5f-11d4-4699-b998-93ed458eb7ac", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7552 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.24 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6785 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.599761 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2377FA0D", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2377FED7", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 132.0, - "writingSpeed": 21.4 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T12:23:58", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T09:50:47", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T11:07:25", - "startingTime": "2019-02-15T11:07:25", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T12:23:58", - "startingTime": "2019-02-15T12:23:58", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2ANQ1Y5", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 40927, - "passedLifetime": 40927, - "powerCycleCount": 1099, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:b8:9c", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:25:09", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWA58", - "type": "Desktop" - }, - "elapsed": "2:36:42", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "53465692-c696-4287-80c4-6ff16fda9974", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7122 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.12 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.701 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.599761 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23789432", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2378940D", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 142.0, - "writingSpeed": 22.2 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:13:59", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:50:05", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:02:56", - "startingTime": "2019-02-15T10:02:56", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:13:59", - "startingTime": "2019-02-15T11:13:59", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APBGND", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 34082, - "passedLifetime": 34082, - "powerCycleCount": 448, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:98:8d", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:15:52", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWY73", - "type": "Desktop" - }, - "elapsed": "2:27:27", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "3d184ebb-e74f-4432-9709-169c2b082d29", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7566 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24741.12 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6868 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.5999510000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "09E3CE28", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "41B61358", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 137.0, - "writingSpeed": 20.1 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:23:14", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:54:06", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:08:41", - "startingTime": "2019-02-15T10:08:41", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:23:14", - "startingTime": "2019-02-15T11:23:14", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2AA652D", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 15924, - "passedLifetime": 15924, - "powerCycleCount": 537, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:c9:3d", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:20:44", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWV65", - "type": "Desktop" - }, - "elapsed": "2:32:40", - "inventory": { - "elapsed": "0:00:27" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "50d26e0a-037a-4f30-8960-9278cbbf53c6", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7044 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24743.64 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6799 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.624926 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2377EDC3", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2377EDAC", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 130.0, - "writingSpeed": 21.1 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:17:04", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:45:34", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:01:20", - "startingTime": "2019-02-15T10:01:20", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:17:04", - "startingTime": "2019-02-15T11:17:04", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2A7LN8P", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 39961, - "passedLifetime": 39961, - "powerCycleCount": 774, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:c7:32", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:22:54", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTXF36", - "type": "Desktop" - }, - "elapsed": "2:35:03", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "8caee209-77f6-4fa8-b5c0-31a456fc51c2", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7585 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.92 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6772 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.628521 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "41135B58", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "41015B58", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 135.0, - "writingSpeed": 20.7 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:15:56", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:49:26", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:02:44", - "startingTime": "2019-02-15T10:02:44", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:15:56", - "startingTime": "2019-02-15T11:15:56", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2AAC5F9", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 46073, - "passedLifetime": 46073, - "powerCycleCount": 789, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:a6:04", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:18:04", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTXP55", - "type": "Desktop" - }, - "elapsed": "2:30:02", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "e5ba685b-d96a-4f20-b6de-cdaff62b0ea9", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7441 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24744.32 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6824 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.604681 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "237803F7", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "237809F2", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 129.0, - "writingSpeed": 20.6 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:27:13", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:45:54", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:06:38", - "startingTime": "2019-02-15T10:06:38", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:27:13", - "startingTime": "2019-02-15T11:27:13", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APCY9M", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 20662, - "passedLifetime": 20662, - "powerCycleCount": 1688, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:a1:0c", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:32:50", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWY30", - "type": "Desktop" - }, - "elapsed": "2:44:51", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "e075afda-11bb-4927-a10c-f216b4d411cb", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7624 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.16 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.7953 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.5999510000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Micron", - "model": "8KTF25664AZ-1G4M1", - "serialNumber": "E688B4A9", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Micron", - "model": "8KTF25664AZ-1G4M1", - "serialNumber": "E688B4B5", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 138.0, - "writingSpeed": 21.8 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:19:39", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:52:33", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:06:21", - "startingTime": "2019-02-15T10:06:21", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:19:39", - "startingTime": "2019-02-15T11:19:39", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APS51G", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 1, - "CurrentPendingSectorCount": 1720, - "OfflineUncorrectable": 1720, - "assessment": true, - "error": true, - "firstError": 976773072, - "lifetime": 53765, - "passedLifetime": 53765, - "powerCycleCount": 1041, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 201, - "status": "Completed: read failure", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "44:37:e6:90:af:e7", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:20:10", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "S4FVYG2", - "type": "Desktop" - }, - "elapsed": "2:30:54", - "inventory": { - "elapsed": "0:00:28" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 3, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "19c1e1d8-c135-4dbb-bfd5-b9453b8cc6e9", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7615 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24743.84 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.7073 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.6001400000000001 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9 1", - "serialNumber": "23789D4E", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23789D6B", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 136.0, - "writingSpeed": 22.0 - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2APDN6M", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 42139, - "passedLifetime": 42139, - "powerCycleCount": 1949, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:97:be", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T09:29:22", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWK56", - "type": "Desktop" - }, - "elapsed": "0:03:30", - "inventory": { - "elapsed": "0:00:25" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "8e0882c2-dbae-499c-abe9-426e8ec788c8", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.7507 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24746.64 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.7038 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.601086 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "09E7CE28", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Undefined", - "model": "RMR1810EC58E8F1333", - "serialNumber": "0902CF28", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 133.0, - "writingSpeed": 20.5 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:20:32", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:50:54", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:05:49", - "startingTime": "2019-02-15T10:05:49", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:20:32", - "startingTime": "2019-02-15T11:20:32", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "W2AAC2QB", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 38491, - "passedLifetime": 38491, - "powerCycleCount": 802, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:ca:b6", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:21:13", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWV63", - "type": "Desktop" - }, - "elapsed": "2:33:10", - "inventory": { - "elapsed": "0:00:26" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - }, - { - "@type": "devices:Snapshot", - "_error": null, - "_phases": 4, - "_saved": null, - "_totalPhases": 4, - "_uploaded": null, - "_uuid": "e2341753-6484-4a95-9e30-dd61e13f60ef", - "automatic": true, - "benchmarks": [ - { - "@type": "BenchmarkRamSysbench", - "score": 0.704 - } - ], - "components": [ - { - "@type": "Processor", - "address": 64, - "benchmarks": [ - { - "@type": "BenchmarkProcessor", - "score": 24738.16 - }, - { - "@type": "BenchmarkProcessorSysbench", - "score": 8.6803 - } - ], - "manufacturer": "Intel Corp.", - "model": "Intel Core i5-2400 CPU @ 3.10GHz", - "numberOfCores": 4, - "serialNumber": null, - "speed": 1.599572 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "23788693", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "RamModule", - "manufacturer": "Samsung", - "model": "M378B5773DH0-CH9", - "serialNumber": "2378867E", - "size": 2048, - "speed": 1333.0 - }, - { - "@type": "HardDrive", - "benchmark": { - "@type": "BenchmarkHardDrive", - "readingSpeed": 96.8, - "writingSpeed": 18.2 - }, - "erasure": { - "@type": "EraseBasic", - "cleanWithZeros": true, - "endingTime": "2019-02-15T11:24:37", - "secureRandomSteps": 1, - "startingTime": "2019-02-15T08:51:22", - "steps": [ - { - "@type": "Zeros", - "endingTime": "2019-02-15T10:08:10", - "startingTime": "2019-02-15T10:08:10", - "success": true - }, - { - "@type": "Random", - "endingTime": "2019-02-15T11:24:37", - "startingTime": "2019-02-15T11:24:37", - "success": true - } - ], - "success": true - }, - "interface": "ata\n", - "manufacturer": "Seagate", - "model": "ST500DM002-1BD14", - "serialNumber": "Z2ANQ0F2", - "size": 476940, - "test": { - "@type": "TestHardDrive", - "CommandTimeout": 0, - "CurrentPendingSectorCount": 0, - "OfflineUncorrectable": 0, - "assessment": true, - "error": false, - "firstError": null, - "lifetime": 29050, - "passedLifetime": 29050, - "powerCycleCount": 738, - "reallocatedSectorCount": 0, - "reportedUncorrectableErrors": 0, - "status": "Completed without error", - "type": "Short offline" - }, - "type": "HDD" - }, - { - "@type": "GraphicCard", - "manufacturer": "Intel Corporation", - "memory": 256.0, - "model": "2nd Generation Core Processor Family Integrated Graphics Controller", - "serialNumber": null - }, - { - "@type": "Motherboard", - "connectors": { - "firewire": 0, - "pcmcia": 0, - "serial": 1, - "usb": 2 - }, - "manufacturer": "LENOVO", - "model": null, - "serialNumber": "INVALID", - "totalSlots": 4, - "usedSlots": 2 - }, - { - "@type": "NetworkAdapter", - "manufacturer": "Intel Corporation", - "model": "82579LM Gigabit Network Connection", - "serialNumber": "cc:52:af:45:98:41", - "speed": 1000 - }, - { - "@type": "SoundCard", - "manufacturer": "Intel Corporation", - "model": "6 Series/C200 Series Chipset Family High Definition Audio Controller", - "serialNumber": null - } - ], - "date": "2019-02-15T10:24:53", - "device": { - "@type": "Computer", - "manufacturer": "LENOVO", - "model": "7072A37", - "serialNumber": "PBTWK83", - "type": "Desktop" - }, - "elapsed": "2:36:50", - "inventory": { - "elapsed": "0:00:29" - }, - "snapshotSoftware": "Workbench", - "tests": [ - { - "@type": "StressTest", - "elapsed": "0:02:00", - "success": true - } - ], - "version": "10.0b8" - } - ], - "usbs": [] -} From 1810f6dcb86ff70eb838e0649774cd81faec1571 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 18 Feb 2019 23:04:47 +0100 Subject: [PATCH 17/23] Use newer teal --- requirements.txt | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/requirements.txt b/requirements.txt index 83c08615..d81f1b7e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,7 @@ requests[security]==2.19.1 requests-mock==1.5.2 SQLAlchemy==1.2.17 SQLAlchemy-Utils==0.33.11 -teal==0.2.0a37 +teal==0.2.0a38 webargs==4.0.0 Werkzeug==0.14.1 sqlalchemy-citext==1.3.post0 diff --git a/setup.py b/setup.py index 4d539e4f..6468ee7c 100644 --- a/setup.py +++ b/setup.py @@ -29,7 +29,7 @@ setup( long_description=long_description, long_description_content_type='text/markdown', install_requires=[ - 'teal>=0.2.0a37', # teal always first + 'teal>=0.2.0a38', # teal always first 'click', 'click-spinner', 'ereuse-utils[naming, test, session, cli]>=0.4b21', From e813fb02c7a31b11cd8ec0b5e642ea8ce653dd0a Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Wed, 27 Feb 2019 10:33:37 +0100 Subject: [PATCH 18/23] Do not return tag token provider from Inventory --- ereuse_devicehub/resources/inventory/schema.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ereuse_devicehub/resources/inventory/schema.py b/ereuse_devicehub/resources/inventory/schema.py index 7d7a7dea..57b157d5 100644 --- a/ereuse_devicehub/resources/inventory/schema.py +++ b/ereuse_devicehub/resources/inventory/schema.py @@ -8,4 +8,3 @@ class Inventory(Thing): id = mf.String(dump_only=True) name = mf.String(dump_only=True) tag_provider = teal.marshmallow.URL(dump_only=True, data_key='tagProvider') - tag_token = mf.UUID(dump_only=True, data_key='tagToken') From 13ffab70226f2f4a120224d506d676e2136c37c1 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Thu, 28 Feb 2019 18:21:24 +0100 Subject: [PATCH 19/23] Move export to Documents --- ereuse_devicehub/resources/device/views.py | 155 +----------------- .../resources/documents/device_row.py | 109 ++++++++++++ .../resources/documents/documents.py | 39 +++++ tests/test_basic.py | 1 + tests/test_reports.py | 25 ++- 5 files changed, 170 insertions(+), 159 deletions(-) create mode 100644 ereuse_devicehub/resources/documents/device_row.py diff --git a/ereuse_devicehub/resources/device/views.py b/ereuse_devicehub/resources/device/views.py index f2ab43d3..bbe229d6 100644 --- a/ereuse_devicehub/resources/device/views.py +++ b/ereuse_devicehub/resources/device/views.py @@ -1,14 +1,10 @@ -import csv import datetime -from io import StringIO import marshmallow -from flask import current_app as app, render_template, request, make_response +from flask import current_app as app, render_template, request from flask.json import jsonify from flask_sqlalchemy import Pagination from marshmallow import fields, fields as f, validate as v -from sqlalchemy.orm import aliased -from sqlalchemy.util import OrderedDict from teal import query from teal.cache import cache from teal.resource import View @@ -17,9 +13,7 @@ from ereuse_devicehub import auth from ereuse_devicehub.db import db from ereuse_devicehub.query import SearchQueryParser, things_response from ereuse_devicehub.resources import search -from ereuse_devicehub.resources.device.models import Component, Computer, Device, Manufacturer, \ - Display, Processor, GraphicCard, Motherboard, NetworkAdapter, DataStorage, RamModule, \ - SoundCard +from ereuse_devicehub.resources.device.models import Device, Manufacturer from ereuse_devicehub.resources.device.search import DeviceSearch from ereuse_devicehub.resources.event import models as events from ereuse_devicehub.resources.lot.models import LotDeviceDescendants @@ -138,150 +132,7 @@ class DeviceView(View): ).order_by( search.Search.rank(properties, search_p) + search.Search.rank(tags, search_p) ) - query = query.filter(*args['filter']).order_by(*args['sort']) - if 'text/csv' in request.accept_mimetypes: - return self.generate_post_csv(query) - else: - devices = query.paginate(page=args['page'], per_page=30) # type: Pagination - ret = { - 'items': self.schema.dump(devices.items, many=True, nested=1), - # todo pagination should be in Header like github - # https://developer.github.com/v3/guides/traversing-with-pagination/ - 'pagination': { - 'page': devices.page, - 'perPage': devices.per_page, - 'total': devices.total, - 'previous': devices.prev_num, - 'next': devices.next_num - }, - 'url': request.path - } - return jsonify(ret) - - def generate_post_csv(self, query): - """ - Get device query and put information in csv format - :param query: - :return: - """ - data = StringIO() - cw = csv.writer(data) - first = True - for device in query: - d = DeviceRow(device) - if first: - cw.writerow(name for name in d.keys()) - first = False - cw.writerow(v for v in d.values()) - output = make_response(data.getvalue()) - output.headers['Content-Disposition'] = 'attachment; filename=export.csv' - output.headers['Content-type'] = 'text/csv' - return output - - -class DeviceRow(OrderedDict): - NUMS = { - Display.t: 1, - Processor.t: 2, - GraphicCard.t: 2, - Motherboard.t: 1, - NetworkAdapter.t: 2, - SoundCard.t: 2 - } - - def __init__(self, device: Device) -> None: - super().__init__() - self.device = device - # General information about device - self['Type'] = device.t - if isinstance(device, Computer): - self['Chassis'] = device.chassis - self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' - for i, tag in zip(range(1, 3), device.tags): - self['Tag {}'.format(i)] = format(tag) - self['Serial Number'] = device.serial_number - self['Model'] = device.model - self['Manufacturer'] = device.manufacturer - # self['State'] = device.last_event_of() - self['Price'] = device.price - self['Registered in'] = format(device.created, '%c') - if isinstance(device, Computer): - self['Processor'] = device.processor_model - self['RAM (GB)'] = device.ram_size - self['Storage Size (MB)'] = device.data_storage_size - rate = device.rate - if rate: - self['Rate'] = rate.rating - self['Range'] = rate.rating_range - self['Processor Rate'] = rate.processor - self['Processor Range'] = rate.workbench.processor_range - self['RAM Rate'] = rate.ram - self['RAM Range'] = rate.workbench.ram_range - self['Data Storage Rate'] = rate.data_storage - self['Data Storage Range'] = rate.workbench.data_storage_range - # More specific information about components - if isinstance(device, Computer): - self.components() - - - def components(self): - """ - Function to get all components information of a device - """ - assert isinstance(self.device, Computer) - # todo put an input specific order (non alphabetic) - for type in sorted(app.resources[Component.t].subresources_types): # type: str - max = self.NUMS.get(type, 4) - if type not in ['Component', 'HardDrive', 'SolidStateDrive']: - i = 1 - for component in (r for r in self.device.components if r.type == type): - self.fill_component(type, i, component) - i += 1 - if i > max: - break - while i <= max: - self.fill_component(type, i) - i += 1 - - def fill_component(self, type, i, component=None): - """ - Function to put specific information of components in OrderedDict (csv) - :param type: type of component - :param component: device.components - """ - self['{} {}'.format(type, i)] = format(component) if component else '' - self['{} {} Manufacturer'.format(type, i)] = component.serial_number if component else '' - self['{} {} Model'.format(type, i)] = component.serial_number if component else '' - self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' - - """ Particular fields for component GraphicCard """ - if isinstance(component, GraphicCard): - self['{} {} Memory (MB)'.format(type, i)] = component.memory - - """ Particular fields for component DataStorage.t -> (HardDrive, SolidStateDrive) """ - if isinstance(component, DataStorage): - self['{} {} Size (MB)'.format(type, i)] = component.size - self['{} {} Privacy'.format(type, i)] = component.privacy - - # todo decide if is relevant more info about Motherboard - """ Particular fields for component Motherboard """ - if isinstance(component, Motherboard): - self['{} {} Slots'.format(type, i)] = component.slots - - """ Particular fields for component Processor """ - if isinstance(component, Processor): - self['{} {} Number of cores'.format(type, i)] = component.cores - self['{} {} Speed (GHz)'.format(type, i)] = component.speed - - """ Particular fields for component RamModule """ - if isinstance(component, RamModule): - self['{} {} Size (MB)'.format(type, i)] = component.size - self['{} {} Speed (MHz)'.format(type, i)] = component.speed - self['{} {} Size'.format(type, i)] = component.size - - # todo add Display size, ... - # todo add NetworkAdapter speedLink? - # todo add some ComputerAccessories + return query.filter(*args['filter']).order_by(*args['sort']) class ManufacturerView(View): diff --git a/ereuse_devicehub/resources/documents/device_row.py b/ereuse_devicehub/resources/documents/device_row.py new file mode 100644 index 00000000..5012da29 --- /dev/null +++ b/ereuse_devicehub/resources/documents/device_row.py @@ -0,0 +1,109 @@ +from collections import OrderedDict + +from flask import current_app + +from ereuse_devicehub.resources.device import models as d + + +class DeviceRow(OrderedDict): + NUMS = { + d.Display.t: 1, + d.Processor.t: 2, + d.GraphicCard.t: 2, + d.Motherboard.t: 1, + d.NetworkAdapter.t: 2, + d.SoundCard.t: 2 + } + + def __init__(self, device: d.Device) -> None: + super().__init__() + self.device = device + # General information about device + self['Type'] = device.t + if isinstance(device, d.Computer): + self['Chassis'] = device.chassis + self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' + for i, tag in zip(range(1, 3), device.tags): + self['Tag {}'.format(i)] = format(tag) + self['Serial Number'] = device.serial_number + self['Model'] = device.model + self['Manufacturer'] = device.manufacturer + # self['State'] = device.last_event_of() + self['Price'] = device.price + self['Registered in'] = format(device.created, '%c') + if isinstance(device, d.Computer): + self['Processor'] = device.processor_model + self['RAM (GB)'] = device.ram_size + self['Storage Size (MB)'] = device.data_storage_size + rate = device.rate + if rate: + self['Rate'] = rate.rating + self['Range'] = rate.rating_range + self['Processor Rate'] = rate.processor + self['Processor Range'] = rate.workbench.processor_range + self['RAM Rate'] = rate.ram + self['RAM Range'] = rate.workbench.ram_range + self['Data Storage Rate'] = rate.data_storage + self['Data Storage Range'] = rate.workbench.data_storage_range + # More specific information about components + if isinstance(device, d.Computer): + self.components() + + def components(self): + """ + Function to get all components information of a device + """ + assert isinstance(self.device, d.Computer) + # todo put an input specific order (non alphabetic) + for type in sorted(current_app.resources[d.Component.t].subresources_types): # type: str + max = self.NUMS.get(type, 4) + if type not in ['Component', 'HardDrive', 'SolidStateDrive']: + i = 1 + for component in (r for r in self.device.components if r.type == type): + self.fill_component(type, i, component) + i += 1 + if i > max: + break + while i <= max: + self.fill_component(type, i) + i += 1 + + def fill_component(self, type, i, component=None): + """ + Function to put specific information of components in OrderedDict (csv) + :param type: type of component + :param component: device.components + """ + self['{} {}'.format(type, i)] = format(component) if component else '' + self['{} {} Manufacturer'.format(type, i)] = component.serial_number if component else '' + self['{} {} Model'.format(type, i)] = component.serial_number if component else '' + self['{} {} Serial Number'.format(type, i)] = component.serial_number if component else '' + + """ Particular fields for component GraphicCard """ + if isinstance(component, d.GraphicCard): + self['{} {} Memory (MB)'.format(type, i)] = component.memory + + """ Particular fields for component DataStorage.t -> (HardDrive, SolidStateDrive) """ + if isinstance(component, d.DataStorage): + self['{} {} Size (MB)'.format(type, i)] = component.size + self['{} {} Privacy'.format(type, i)] = component.privacy + + # todo decide if is relevant more info about Motherboard + """ Particular fields for component Motherboard """ + if isinstance(component, d.Motherboard): + self['{} {} Slots'.format(type, i)] = component.slots + + """ Particular fields for component Processor """ + if isinstance(component, d.Processor): + self['{} {} Number of cores'.format(type, i)] = component.cores + self['{} {} Speed (GHz)'.format(type, i)] = component.speed + + """ Particular fields for component RamModule """ + if isinstance(component, d.RamModule): + self['{} {} Size (MB)'.format(type, i)] = component.size + self['{} {} Speed (MHz)'.format(type, i)] = component.speed + self['{} {} Size'.format(type, i)] = component.size + + # todo add Display size, ... + # todo add NetworkAdapter speedLink? + # todo add some ComputerAccessories diff --git a/ereuse_devicehub/resources/documents/documents.py b/ereuse_devicehub/resources/documents/documents.py index 34121d8c..72582a21 100644 --- a/ereuse_devicehub/resources/documents/documents.py +++ b/ereuse_devicehub/resources/documents/documents.py @@ -1,5 +1,8 @@ +import csv +import datetime import enum import uuid +from io import StringIO from typing import Callable, Iterable, Tuple import boltons @@ -7,11 +10,14 @@ import flask import flask_weasyprint import teal.marshmallow from boltons import urlutils +from flask import make_response +from teal.cache import cache from teal.resource import Resource from ereuse_devicehub.db import db from ereuse_devicehub.resources.device import models as devs from ereuse_devicehub.resources.device.views import DeviceView +from ereuse_devicehub.resources.documents.device_row import DeviceRow from ereuse_devicehub.resources.event import models as evs @@ -97,6 +103,33 @@ class DocumentView(DeviceView): return flask.render_template('documents/erasure.html', **params) +class DevicesDocumentView(DeviceView): + @cache(datetime.timedelta(minutes=1)) + def find(self, args: dict): + query = self.query(args) + return self.generate_post_csv(query) + + def generate_post_csv(self, query): + """ + Get device query and put information in csv format + :param query: + :return: + """ + data = StringIO() + cw = csv.writer(data) + first = True + for device in query: + d = DeviceRow(device) + if first: + cw.writerow(name for name in d.keys()) + first = False + cw.writerow(v for v in d.values()) + output = make_response(data.getvalue()) + output.headers['Content-Disposition'] = 'attachment; filename=export.csv' + output.headers['Content-type'] = 'text/csv' + return output + + class DocumentDef(Resource): __type__ = 'Document' SCHEMA = None @@ -124,3 +157,9 @@ class DocumentDef(Resource): self.add_url_rule('/erasures/', defaults=d, view_func=view, methods=get) self.add_url_rule('/erasures/<{}:{}>'.format(self.ID_CONVERTER.value, self.ID_NAME), view_func=view, methods=get) + devices_view = DevicesDocumentView.as_view('devicesDocumentView', + definition=self, + auth=app.auth) + if self.AUTH: + devices_view = app.auth.requires_auth(devices_view) + self.add_url_rule('/devices/', defaults=d, view_func=devices_view, methods=get) diff --git a/tests/test_basic.py b/tests/test_basic.py index 711dbf92..f211503e 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -28,6 +28,7 @@ def test_api_docs(client: Client): '/lots/{id}/children', '/lots/{id}/devices', '/documents/erasures/', + '/documents/devices/', '/documents/static/{filename}', '/tags/{tag_id}/device/{device_id}', '/devices/static/{filename}' diff --git a/tests/test_reports.py b/tests/test_reports.py index feb216d0..aa6baf59 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -3,8 +3,10 @@ from datetime import datetime from io import StringIO from pathlib import Path +import pytest + from ereuse_devicehub.client import UserClient -from ereuse_devicehub.resources.device.models import Device +from ereuse_devicehub.resources.documents import documents as docs from ereuse_devicehub.resources.event.models import Snapshot from tests.conftest import file @@ -14,7 +16,8 @@ def test_export_basic_snapshot(user: UserClient): Test export device information in a csv file """ snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, + csv_str, _ = user.get(res=docs.DocumentDef.t, + item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) @@ -40,7 +43,8 @@ def test_export_full_snapshot(user: UserClient): Test a export device with all information and a lot of components """ snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) - csv_str, _ = user.get(res=Device, + csv_str, _ = user.get(res=docs.DocumentDef.t, + item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) @@ -67,7 +71,9 @@ def test_export_empty(user: UserClient): """ Test to check works correctly exporting csv without any information (no snapshot) """ - csv_str, _ = user.get(res=Device, accept='text/csv') + csv_str, _ = user.get(res=docs.DocumentDef.t, + accept='text/csv', + item='devices/') f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) @@ -80,7 +86,8 @@ def test_export_computer_monitor(user: UserClient): Test a export device type computer monitor """ snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, + csv_str, _ = user.get(res=docs.DocumentDef.t, + item='devices/', accept='text/csv', query=[('filter', {'type': ['ComputerMonitor']})]) f = StringIO(csv_str) @@ -105,7 +112,8 @@ def test_export_keyboard(user: UserClient): Test a export device type keyboard """ snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=Device, + csv_str, _ = user.get(res=docs.DocumentDef.t, + item='devices/', accept='text/csv', query=[('filter', {'type': ['Keyboard']})]) f = StringIO(csv_str) @@ -124,6 +132,7 @@ def test_export_keyboard(user: UserClient): assert fixture_csv[1] == export_csv[1], 'Component information are not equal' +@pytest.mark.xfail(reason='Develop test') def test_export_multiple_devices(user: UserClient): """ Test a export multiple devices with different components and information @@ -131,6 +140,7 @@ def test_export_multiple_devices(user: UserClient): pass +@pytest.mark.xfail(reason='Develop test') def test_export_only_components(user: UserClient): """ Test a export only components @@ -138,7 +148,8 @@ def test_export_only_components(user: UserClient): pass -def test_export_computers__and_components(user: UserClient): +@pytest.mark.xfail(reason='Develop test') +def test_export_computers_and_components(user: UserClient): """ Test a export multiple devices (computers and independent components) """ From 8f4ba8d503d3a0bf7aafa0f4724a1f863d46a065 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Mon, 4 Mar 2019 09:33:01 +0100 Subject: [PATCH 20/23] Update Teal link --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db54c0af..a02b5a04 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Our main objectives are: - To highly integrate with existing IT Asset Management Systems. - To be decentralized. -Devicehub is built with [Teal](https://github.com/bustawin/teal) and +Devicehub is built with [Teal](https://github.com/ereuse/teal) and [Flask](http://flask.pocoo.org). ## Installing From f1f285eb1dd66cb629a4ae204505eaad1db1bcaa Mon Sep 17 00:00:00 2001 From: nad Date: Wed, 6 Mar 2019 18:42:50 +0100 Subject: [PATCH 21/23] Add new Events DataStorage fields in export --- .../resources/documents/device_row.py | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/ereuse_devicehub/resources/documents/device_row.py b/ereuse_devicehub/resources/documents/device_row.py index 5012da29..a75ed60e 100644 --- a/ereuse_devicehub/resources/documents/device_row.py +++ b/ereuse_devicehub/resources/documents/device_row.py @@ -3,6 +3,7 @@ from collections import OrderedDict from flask import current_app from ereuse_devicehub.resources.device import models as d +from ereuse_devicehub.resources.event.models import TestDataStorage, BenchmarkDataStorage class DeviceRow(OrderedDict): @@ -15,6 +16,7 @@ class DeviceRow(OrderedDict): d.SoundCard.t: 2 } + # TODO Add more fields information def __init__(self, device: d.Device) -> None: super().__init__() self.device = device @@ -22,6 +24,8 @@ class DeviceRow(OrderedDict): self['Type'] = device.t if isinstance(device, d.Computer): self['Chassis'] = device.chassis + else: + self['Chassis'] = '' self['Tag 1'] = self['Tag 2'] = self['Tag 3'] = '' for i, tag in zip(range(1, 3), device.tags): self['Tag {}'.format(i)] = format(tag) @@ -29,12 +33,12 @@ class DeviceRow(OrderedDict): self['Model'] = device.model self['Manufacturer'] = device.manufacturer # self['State'] = device.last_event_of() - self['Price'] = device.price self['Registered in'] = format(device.created, '%c') + self['Price'] = device.price if isinstance(device, d.Computer): self['Processor'] = device.processor_model self['RAM (GB)'] = device.ram_size - self['Storage Size (MB)'] = device.data_storage_size + self['Data Storage Size (MB)'] = device.data_storage_size rate = device.rate if rate: self['Rate'] = rate.rating @@ -54,7 +58,7 @@ class DeviceRow(OrderedDict): Function to get all components information of a device """ assert isinstance(self.device, d.Computer) - # todo put an input specific order (non alphabetic) + # todo put an input specific order (non alphabetic) & where are a list of types components for type in sorted(current_app.resources[d.Component.t].subresources_types): # type: str max = self.NUMS.get(type, 4) if type not in ['Component', 'HardDrive', 'SolidStateDrive']: @@ -87,11 +91,18 @@ class DeviceRow(OrderedDict): if isinstance(component, d.DataStorage): self['{} {} Size (MB)'.format(type, i)] = component.size self['{} {} Privacy'.format(type, i)] = component.privacy - - # todo decide if is relevant more info about Motherboard - """ Particular fields for component Motherboard """ - if isinstance(component, d.Motherboard): - self['{} {} Slots'.format(type, i)] = component.slots + try: + self['{} {} Lifetime'.format(type, i)] = component.last_event_of(TestDataStorage).lifetime + except: + self['{} {} Lifetime'.format(type, i)] = '' + try: + self['{} {} Reading speed'.format(type, i)] = component.last_event_of(BenchmarkDataStorage).read_speed + except: + self['{} {} Reading speed'.format(type, i)] = '' + try: + self['{} {} Writing speed'.format(type, i)] = component.last_event_of(BenchmarkDataStorage).write_speed + except: + self['{} {} Writing speed'.format(type, i)] = '' """ Particular fields for component Processor """ if isinstance(component, d.Processor): @@ -102,7 +113,6 @@ class DeviceRow(OrderedDict): if isinstance(component, d.RamModule): self['{} {} Size (MB)'.format(type, i)] = component.size self['{} {} Speed (MHz)'.format(type, i)] = component.speed - self['{} {} Size'.format(type, i)] = component.size # todo add Display size, ... # todo add NetworkAdapter speedLink? From c5da07ef9c3257d5b17bdfd97fe225c61a9796db Mon Sep 17 00:00:00 2001 From: nad Date: Wed, 6 Mar 2019 18:44:21 +0100 Subject: [PATCH 22/23] Add new tests and update some fixtures --- tests/files/basic.csv | 4 +- tests/files/computer-monitor.csv | 4 +- tests/files/keyboard.csv | 4 +- tests/files/multiples_devices.csv | 17 ++++++++ tests/files/real-eee-1001pxd.csv | 4 +- tests/test_reports.py | 71 ++++++++++++++++++------------- 6 files changed, 67 insertions(+), 37 deletions(-) create mode 100644 tests/files/multiples_devices.csv diff --git a/tests/files/basic.csv b/tests/files/basic.csv index db045b6d..f78453e9 100644 --- a/tests/files/basic.csv +++ b/tests/files/basic.csv @@ -1,2 +1,2 @@ -Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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 1 Size,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 -Desktop,Microtower,,,,d1s,d1ml,d1mr,,Tue Nov 13 17:20:42 2018,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,,, +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 +Desktop,Microtower,,,,d1s,d1ml,d1mr,Tue Mar 5 19:54:18 2019,,p1ml,0,0,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low,,,,,,,,,,,,,,,,,,,,,"GraphicCard 2: model gc1ml, S/N gc1s",gc1s,gc1s,gc1s,,,,,,,,,,,,,,,,,,"Processor 4: model p1ml, S/N p1s",p1s,p1s,p1s,,1.6,,,,,"RamModule 3: model rm1ml, S/N rm1s",rm1s,rm1s,rm1s,,1333,,,,,,,,,,,,,,,,,,,, diff --git a/tests/files/computer-monitor.csv b/tests/files/computer-monitor.csv index 26213062..0c529700 100644 --- a/tests/files/computer-monitor.csv +++ b/tests/files/computer-monitor.csv @@ -1,2 +1,2 @@ -Type,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in -ComputerMonitor,,,,cn0fp446728728541c8s,1707fpf,dell,,Wed Oct 24 20:57:18 2018 +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Registered in,Price +ComputerMonitor,,,,,cn0fp446728728541c8s,1707fpf,dell,Wed Oct 24 20:57:18 2018 \ No newline at end of file diff --git a/tests/files/keyboard.csv b/tests/files/keyboard.csv index dd279133..097a48fc 100644 --- a/tests/files/keyboard.csv +++ b/tests/files/keyboard.csv @@ -1,2 +1,2 @@ -Type,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in -Keyboard,,,,bar,foo,baz,,Wed Oct 24 21:01:48 2018 +Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Registered in,Price +Keyboard,,,,,bar,foo,baz,Wed Oct 24 21:01:48 2018 diff --git a/tests/files/multiples_devices.csv b/tests/files/multiples_devices.csv new file mode 100644 index 00000000..6a093d0d --- /dev/null +++ b/tests/files/multiples_devices.csv @@ -0,0 +1,17 @@ +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.73,Very low,1.0,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.73,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.73,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.73,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.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.73,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.73,Very low,1.0,Very low,1.53,Very low,3.76,Medium +RamModule,,,,,,,,Wed Mar 6 18:22:05 2019,,1.73,Very low,1.0,Very low,1.53,Very low,3.76,Medium +HardDrive,,,,,e2024242cv86hj,hts54322,hitachi,Wed Mar6 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.73,Very low,1.0,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,,,,,,,,,,,,,,,,,,,, +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 +Processor,,,,,p1s,p1ml,p1mr,Wed Mar 6 18:22:06 2019,,0.8,Very low,1.0,Very low,1.0,Very low,1.0,Very low +Keyboard,,,,,bar,foo,baz,Wed Mar 6 18:22:06 2019, +ComputerMonitor,,,,,cn0fp446728728541c8s,1707fpf,dell,Wed Mar 6 18:22:06 2019, diff --git a/tests/files/real-eee-1001pxd.csv b/tests/files/real-eee-1001pxd.csv index 2debf295..ef09a24b 100644 --- a/tests/files/real-eee-1001pxd.csv +++ b/tests/files/real-eee-1001pxd.csv @@ -1,2 +1,2 @@ -Type,Chassis,Tag 1,Tag 2,Tag 3,Serial Number,Model,Manufacturer,Price,Registered in,Processor,RAM (GB),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,Motherboard 1 Slots,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 1 Size,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.,,Thu Oct 25 10:26:02 2018,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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,2,"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,1024,,,,,,,,,,,,,"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 +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.,Tue Mar 5 19:56:08 2019,,intel atom cpu n455 @ 1.66ghz,1024,238475,1.73,Very low,1.0,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 diff --git a/tests/test_reports.py b/tests/test_reports.py index aa6baf59..fe053760 100644 --- a/tests/test_reports.py +++ b/tests/test_reports.py @@ -3,10 +3,8 @@ from datetime import datetime from io import StringIO from pathlib import Path -import pytest - from ereuse_devicehub.client import UserClient -from ereuse_devicehub.resources.documents import documents as docs +from ereuse_devicehub.resources.documents import documents from ereuse_devicehub.resources.event.models import Snapshot from tests.conftest import file @@ -16,24 +14,26 @@ def test_export_basic_snapshot(user: UserClient): Test export device information in a csv file """ snapshot, _ = user.post(file('basic.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=docs.DocumentDef.t, + csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) + # Open fixture csv and transform to list with Path(__file__).parent.joinpath('files').joinpath('basic.csv').open() as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - assert isinstance(datetime.strptime(export_csv[1][9], '%c'), datetime), \ + assert isinstance(datetime.strptime(export_csv[1][8], '%c'), datetime), \ 'Register in field is not a datetime' - fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] - export_csv[1] = export_csv[1][:9] + export_csv[1][10:] # Pop dates fields from csv lists to compare them + fixture_csv[1] = fixture_csv[1][:8] + fixture_csv[1][9:] + export_csv[1] = export_csv[1][:8] + export_csv[1][9:] + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' @@ -43,25 +43,26 @@ def test_export_full_snapshot(user: UserClient): Test a export device with all information and a lot of components """ snapshot, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) - csv_str, _ = user.get(res=docs.DocumentDef.t, + csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', query=[('filter', {'type': ['Computer']})]) f = StringIO(csv_str) obj_csv = csv.reader(f, f) export_csv = list(obj_csv) + # Open fixture csv and transform to list with Path(__file__).parent.joinpath('files').joinpath('real-eee-1001pxd.csv').open() \ as csv_file: obj_csv = csv.reader(csv_file) fixture_csv = list(obj_csv) - assert isinstance(datetime.strptime(export_csv[1][9], '%c'), datetime), \ + assert isinstance(datetime.strptime(export_csv[1][8], '%c'), datetime), \ 'Register in field is not a datetime' # Pop dates fields from csv lists to compare them - fixture_csv[1] = fixture_csv[1][:9] + fixture_csv[1][10:] - export_csv[1] = export_csv[1][:9] + export_csv[1][10:] + fixture_csv[1] = fixture_csv[1][:8] + fixture_csv[1][9:] + export_csv[1] = export_csv[1][:8] + export_csv[1][9:] assert fixture_csv[0] == export_csv[0], 'Headers are not equal' assert fixture_csv[1] == export_csv[1], 'Computer information are not equal' @@ -71,7 +72,7 @@ def test_export_empty(user: UserClient): """ Test to check works correctly exporting csv without any information (no snapshot) """ - csv_str, _ = user.get(res=docs.DocumentDef.t, + csv_str, _ = user.get(res=documents.DocumentDef.t, accept='text/csv', item='devices/') f = StringIO(csv_str) @@ -86,7 +87,7 @@ def test_export_computer_monitor(user: UserClient): Test a export device type computer monitor """ snapshot, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=docs.DocumentDef.t, + csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', query=[('filter', {'type': ['ComputerMonitor']})]) @@ -112,7 +113,7 @@ def test_export_keyboard(user: UserClient): Test a export device type keyboard """ snapshot, _ = user.post(file('keyboard.snapshot'), res=Snapshot) - csv_str, _ = user.get(res=docs.DocumentDef.t, + csv_str, _ = user.get(res=documents.DocumentDef.t, item='devices/', accept='text/csv', query=[('filter', {'type': ['Keyboard']})]) @@ -132,25 +133,37 @@ def test_export_keyboard(user: UserClient): assert fixture_csv[1] == export_csv[1], 'Component information are not equal' -@pytest.mark.xfail(reason='Develop test') def test_export_multiple_devices(user: UserClient): """ - Test a export multiple devices with different components and information + Test a export multiple devices (Computers and other types) with different information """ - pass + # Post all devices snapshots + snapshot_pc, _ = user.post(file('real-eee-1001pxd.snapshot.11'), res=Snapshot) + snapshot_empty, _ = user.post(file('basic.snapshot'), res=Snapshot) + snapshot_keyboard, _ = user.post(file('keyboard.snapshot'), res=Snapshot) + snapshot_monitor, _ = user.post(file('computer-monitor.snapshot'), res=Snapshot) + # need query param?? + csv_str, _ = user.get(res=documents.DocumentDef.t, + item='devices/', + accept='text/csv') + f = StringIO(csv_str) + obj_csv = csv.reader(f, f) + export_csv = list(obj_csv) -@pytest.mark.xfail(reason='Develop test') -def test_export_only_components(user: UserClient): - """ - Test a export only components - """ - pass + # Open fixture csv and transform to list + with Path(__file__).parent.joinpath('files').joinpath('multiples_devices.csv').open() \ + as csv_file: + obj_csv = csv.reader(csv_file) + fixture_csv = list(obj_csv) + assert fixture_csv[0] == export_csv[0], 'Headers are not equal' -@pytest.mark.xfail(reason='Develop test') -def test_export_computers_and_components(user: UserClient): - """ - Test a export multiple devices (computers and independent components) - """ - pass + max_range = max(len(export_csv), len(fixture_csv)) - 1 + # check if all devices information is correct + for i in range(1, max_range): + if isinstance(datetime.strptime(export_csv[i][8], '%c'), datetime): + export_csv[i] = export_csv[i][:8] + export_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' From e47748563e20b3fe273040fcf25636c8c00f2f02 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 26 Mar 2019 10:55:38 +0100 Subject: [PATCH 23/23] Update docs --- docs/actions.rst | 30 +++++-------- docs/devices.rst | 18 ++++++-- docs/index.rst | 32 +++++++++++--- docs/states.rst | 48 +++++++++++++++++++++ ereuse_devicehub/resources/device/states.py | 4 ++ 5 files changed, 103 insertions(+), 29 deletions(-) create mode 100644 docs/states.rst diff --git a/docs/actions.rst b/docs/actions.rst index 59fa7b33..45b19b7e 100644 --- a/docs/actions.rst +++ b/docs/actions.rst @@ -1,15 +1,14 @@ -Actions and states -################## - Actions -******* - +####### Actions are events performed to devices, changing their **state**. Actions can have attributes defining **where** it happened, **who** performed them, **when**, etc. Actions are stored in a log for each device. An exemplifying action can be ``Repair``, which dictates that a device has been repaired, -after this action, the device is in the ``repaired`` state. +after this action, the device is in the ``repaired`` state. Another +example is performing a ``Sell`` to agent 1 (now this agent *owns* +the device), and then performing another ``Sell`` to agent 2 (now +agent 2 is the owner). Devicehub actions inherit from `schema actions `_, are written in Pascal case and using @@ -19,14 +18,14 @@ is going to be / must be repaired, whereas ``Repair`` states that the reparation happened. The former actions have the preposition *To* prefixing the verb. -Actions and states affect devices in different ways or **dimensions**. +:ref:`actions:Actions` and :ref:`states:States` affect devices in +different ways or **dimensions**. For example, ``Repair`` affects the **physical** dimension of a device, and ``Sell`` the **political** dimension of a device. A device can be in several states at the same time, one per dimension; ie. a device can be ``repaired`` (physical) and ``reserved`` (political), but not ``repaired`` and ``disposed`` at the same time: - - Physical actions: The following actions describe and react on the Physical condition of the devices. @@ -37,7 +36,7 @@ but not ``repaired`` and ``disposed`` at the same time: - DisposeWaste, Recover - Association actions: Actions that change the associations users have with devices; - ie. the **owners**, **usufructuarees**, **reservees**, + ie. the **owners**, **usufructuarees** (*from usufruct*), **reservees** (*from reserve*), and **physical possessors**. - Trade @@ -60,15 +59,8 @@ but not ``repaired`` and ``disposed`` at the same time: The following index has all the actions (please note we are moving from calling them ``Event`` to call them ``Action``): +Schema +****** + .. dhlist:: :module: ereuse_devicehub.resources.event.schemas - - -States -****** -.. autoclass:: ereuse_devicehub.resources.device.states.State - -.. uml:: states.puml - -.. autoclass:: ereuse_devicehub.resources.device.states.Trading -.. autoclass:: ereuse_devicehub.resources.device.states.Physical diff --git a/docs/devices.rst b/docs/devices.rst index 697802a7..1974eebd 100644 --- a/docs/devices.rst +++ b/docs/devices.rst @@ -1,6 +1,19 @@ Devices -######### +####### +Devices are objects that can be identified, and they are the +main entity in a Devicehub. Refer to :ref:`devices:Device` for more +info. +Schema +****** +The following schema represents all the device types and their +properties. + +.. dhlist:: + :module: ereuse_devicehub.resources.device.schemas + +API +*** You can retrieve devices using ``GET /devices/``, or a specific device by ``GET /devices/24``. @@ -46,5 +59,4 @@ The result is a JSON object with the following fields: - **next**: The number of the next page, if any. - **last**: The number of the last page, if any. -.. dhlist:: - :module: ereuse_devicehub.resources.device.schemas + diff --git a/docs/index.rst b/docs/index.rst index 0269992a..a8547ff9 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -14,19 +14,36 @@ reusing devices, created under the project Our main objectives are: -- To offer a common IT Asset Management for donors, receivers and IT - professionals so they can manage devices and exchange them. - This is, reusing –and ultimately recycling. +- To offer a common IT Asset Management for distributors, refurbishers, + receivers and other IT professionals so they can manage devices and exchange them. + This is, reusing —and ultimately recycling. - To automatically recollect, analyse, process and share (controlling privacy) metadata about devices with other tools of the eReuse ecosystem to guarantee traceability, and to provide inputs for the indicators which measure circularity. -- To highly integrate with existing IT Asset Management Systems. -- To be decentralized. -Devicehub is built with `Teal `_ and -`Flask `_. +The main entity of a Devicehub are :ref:`devices:Devices`, which is any object that +can be identified. Devices are divided in *types* (like ``Computer``), +and each one defines *properties*, like serial number, weight, +quality rating, pricing, or a list of owners. +We perform :ref:`actions:Actions` on devices, which are events that +change their *state* and *properties*. Examples are sales, reparations, +quality diagnostics, data wiping, and location. +Actions are stored in the traceability log of the device. + +Devicehub is decentralized, and each instance is an inventory. We can +share and exchange devices between inventories —like in real live between +organizations. + +:ref:`tags:Tags` identify devices through those organizations and their +internal systems. With Devicehub we can manage and print smart tags with +QR and NFC capabilities, operating devices by literally scanning them. + +Devicehub is a REST API built with `Teal `_ and +`Flask `_ using `PostgreSQL `_. +`DevicehubClient `_ is the +front–end that consumes this API. .. toctree:: :maxdepth: 2 @@ -34,6 +51,7 @@ Devicehub is built with `Teal `_ and api devices actions + states tags lots diff --git a/docs/states.rst b/docs/states.rst new file mode 100644 index 00000000..7c253e9a --- /dev/null +++ b/docs/states.rst @@ -0,0 +1,48 @@ +States +###### +.. note:: In construction. + +A mutable property of a device result of applying an +:ref:`actions:Action` to it. + +States are represented as properties in :ref:`devices:Device` and +sub–types. They can be steps in a workflow +(like ``sold`` and ``payed``, part of a trading), or properties +describing computed values from applying events (like a list of owners, +or a quality rating). + +There are three types of states: + +* **Trading**: a workflow of states resulting from applying the action + :ref:`actions:Trade`. +* **Physical**: a workflow of states resulting from applying + physical actions (ref. :ref:`actions:Actions`). +* **Attributes**: miscellaneous device properties that are not part of + a workflow. + +.. uml:: states.puml + +Trading +******* + Trading states. + +:cvar Reserved: The device has been reserved. +:cvar Cancelled: The device has been cancelled. +:cvar Sold: The device has been sold. +:cvar Donated: The device is donated. +:cvar Renting: The device is in renting +:cvar ToBeDisposed: The device is disposed. + This is the end of life of a device. +:cvar ProductDisposed: The device has been removed + from the facility. It does not mean end-of-life. + +Physical +******** + Physical states. + +:cvar ToBeRepaired: The device has been selected for reparation. +:cvar Repaired: The device has been repaired. +:cvar Preparing: The device is going to be or being prepared. +:cvar Prepared: The device has been prepared. +:cvar ReadyToBeUsed: The device is in working conditions. +:cvar InUse: The device is being reported to be in active use. diff --git a/ereuse_devicehub/resources/device/states.py b/ereuse_devicehub/resources/device/states.py index 1cadfb39..93c5a2af 100644 --- a/ereuse_devicehub/resources/device/states.py +++ b/ereuse_devicehub/resources/device/states.py @@ -6,6 +6,10 @@ from ereuse_devicehub.resources.event import models as e class State(Enum): + """A mutable property of a device result of applying an + :ref:`actions:Action` to it. + """ + @classmethod def events(cls): """Events participating in this state."""