Merge pull request #75 from eReuse/feature/#1851-Extended-Export-CSV-file

Feature/#1851 extended export csv file
This commit is contained in:
Jordi Nadeu 2020-10-22 17:21:55 +02:00 committed by GitHub
commit 6ee93f36cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 755 additions and 118 deletions

View File

@ -1,10 +1,12 @@
""" This file frame a correct row for csv report """
from collections import OrderedDict
from flask import url_for
from flask import current_app
from ereuse_devicehub.resources.action.models import BenchmarkDataStorage, RateComputer, \
TestDataStorage
from ereuse_devicehub.resources.enums import Severity
from ereuse_devicehub.resources.device import models as d, states
from ereuse_devicehub.resources.action.models import (BenchmarkDataStorage, RateComputer,
TestDataStorage)
class DeviceRow(OrderedDict):
@ -14,26 +16,55 @@ class DeviceRow(OrderedDict):
d.GraphicCard.t: 2,
d.Motherboard.t: 1,
d.NetworkAdapter.t: 2,
d.SoundCard.t: 2
d.SoundCard.t: 2,
d.RamModule.t: 4,
d.DataStorage: 5,
}
ORDER_COMPONENTS = [
d.Processor.t,
d.RamModule.t,
d.DataStorage.t,
d.Motherboard.t,
d.Display.t,
d.GraphicCard.t,
d.NetworkAdapter.t,
d.SoundCard.t,
]
# TODO Add more fields information
def __init__(self, device: d.Device) -> None:
super().__init__()
self.device = device
snapshot = get_action(device, 'Snapshot')
software = ''
if snapshot:
software = "{software} {version}".format(
software=snapshot.software.name, version=snapshot.version)
# General information about device
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'] = ''
self['System ID'] = device.id
self['Public Link'] = '{url}{id}'.format(url=url_for('Device.main', _external=True),
id=device.id)
self['Tag 1 Type'] = self['Tag 1 ID'] = self['Tag 1 Organization'] = ''
self['Tag 2 Type'] = self['Tag 2 ID'] = self['Tag 2 Organization'] = ''
self['Tag 3 Type'] = self['Tag 3 ID'] = self['Tag 3 Organization'] = ''
for i, tag in zip(range(1, 3), device.tags):
self['Tag {}'.format(i)] = format(tag)
self['Serial Number'] = convert_none_to_empty_str(device.serial_number)
self['Model'] = convert_none_to_empty_str(device.model)
self['Manufacturer'] = convert_none_to_empty_str(device.manufacturer)
# TODO @cayop we need redefined how save the Tag Type info
self['Tag {} Type'.format(i)] = 'unamed'
self['Tag {} ID'.format(i)] = tag.id
self['Tag {} Organization'.format(i)] = tag.org.name
self['Device Hardware ID'] = device.hid
self['Device Type'] = device.t
self['Device Chassis'] = ''
if isinstance(device, d.Computer):
self['Device Chassis'] = device.chassis.name
self['Device Serial Number'] = none2str(device.serial_number)
self['Device Model'] = none2str(device.model)
self['Device Manufacturer'] = none2str(device.manufacturer)
self['Registered in'] = format(device.created, '%c')
self['Registered (process)'] = software
self['Updated in (software)'] = device.updated
self['Updated in (web)'] = ''
try:
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
except LookupError:
@ -42,105 +73,237 @@ class DeviceRow(OrderedDict):
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
except LookupError:
self['Trading state'] = ''
self['Price'] = convert_none_to_empty_str(device.price)
if isinstance(device, d.Computer):
self['Processor'] = convert_none_to_empty_str(device.processor_model)
self['RAM (MB)'] = convert_none_to_empty_str(device.ram_size)
self['Data Storage Size (MB)'] = convert_none_to_empty_str(device.data_storage_size)
rate = device.rate
if rate:
self['Rate'] = rate.rating
self['Range'] = rate.rating_range
assert isinstance(rate, RateComputer)
self['Processor Rate'] = rate.processor
self['Processor Range'] = rate.processor_range
self['RAM Rate'] = rate.ram
self['RAM Range'] = rate.ram_range
self['Data Storage Rate'] = rate.data_storage
self['Data Storage Range'] = rate.data_storage_range
self['Processor'] = none2str(device.processor_model)
self['RAM (MB)'] = none2str(device.ram_size)
self['Data Storage Size (MB)'] = none2str(device.data_storage_size)
# More specific information about components
if isinstance(device, d.Computer):
self.components()
else:
# TODO @cayop we need add columns as a component
pass
rate = device.rate
if rate:
self['Device Rate'] = rate.rating
self['Device Range'] = rate.rating_range.name
assert isinstance(rate, RateComputer)
self['Processor Rate'] = rate.processor
self['Processor Range'] = rate.processor_range.name
self['RAM Rate'] = rate.ram
self['RAM Range'] = rate.ram_range.name
self['Data Storage Rate'] = rate.data_storage
self['Data Storage Range'] = rate.data_storage_range.name
self['Price'] = none2str(device.price)
benchram = get_action(device, 'BenchmarkRamSysbench')
if benchram:
self['Benchmark RamSysbench (points)'] = none2str(benchram.rate)
else:
self['Benchmark RamSysbench (points)'] = ''
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) & 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']:
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
for ctype in self.ORDER_COMPONENTS: # ctype: str
cmax = self.NUMS.get(ctype, 4)
i = 1
l_ctype = [ctype]
if ctype == d.DataStorage.t:
l_ctype = [ctype, d.HardDrive.t, d.SolidStateDrive.t]
for component in (r for r in self.device.components if r.type in l_ctype):
self.fill_component(ctype, i, component)
i += 1
if i > cmax:
break
while i <= cmax:
self.fill_component(ctype, i)
i += 1
def fill_component(self, type, i, component=None):
def fill_component(self, ctype, i, component=None):
"""Function to put specific information of components
in OrderedDict (csv)
:param type: type of component
:param ctype: 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 ''
# Basic fields for all components
self['{} {}'.format(ctype, i)] = format(component) if component else ''
if component is None:
self['{} {} Manufacturer'.format(ctype, i)] = ''
self['{} {} Model'.format(ctype, i)] = ''
self['{} {} Serial Number'.format(ctype, i)] = ''
else:
self['{} {} Manufacturer'.format(ctype, i)] = none2str(component.manufacturer)
self['{} {} Model'.format(ctype, i)] = none2str(component.model)
self['{} {} Serial Number'.format(ctype, i)] = none2str(component.serial_number)
"""Particular fields for component GraphicCard."""
if isinstance(component, d.GraphicCard):
self['{} {} Memory (MB)'.format(type, i)] = component.memory
if ctype == d.Processor.t:
self.get_processor(ctype, i, component)
"""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
try:
self['{} {} Lifetime'.format(type, i)] = component.last_action_of(
TestDataStorage).lifetime
except:
self['{} {} Lifetime'.format(type, i)] = ''
try:
self['{} {} Reading speed'.format(type, i)] = component.last_action_of(
BenchmarkDataStorage).read_speed
except:
self['{} {} Reading speed'.format(type, i)] = ''
try:
self['{} {} Writing speed'.format(type, i)] = component.last_action_of(
BenchmarkDataStorage).write_speed
except:
self['{} {} Writing speed'.format(type, i)] = ''
if ctype == d.RamModule.t:
self.get_ram(ctype, i, component)
if ctype == d.DataStorage.t:
self.get_datastorage(ctype, i, component)
if ctype == d.GraphicCard.t:
self.get_graphic_card(ctype, i, component)
def get_processor(self, ctype, i, component):
"""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
if component is None:
self['{} {} Number of cores'.format(ctype, i)] = ''
self['{} {} Speed (GHz)'.format(ctype, i)] = ''
self['Benchmark {} {} (points)'.format(ctype, i)] = ''
self['Benchmark ProcessorSysbench {} {} (points)'.format(ctype, i)] = ''
return
"""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['{} {} Number of cores'.format(ctype, i)] = none2str(component.cores)
self['{} {} Speed (GHz)'.format(ctype, i)] = none2str(component.speed)
# todo add Display, NetworkAdapter, etc...
benchmark = get_action(component, 'BenchmarkProcessor')
if not benchmark:
self['Benchmark {} {} (points)'.format(ctype, i)] = ''
else:
self['Benchmark {} {} (points)'.format(ctype, i)] = benchmark.rate
sysbench = get_action(component, 'BenchmarkProcessorSysbench')
if not sysbench:
self['Benchmark ProcessorSysbench {} {} (points)'.format(ctype, i)] = ''
return
self['Benchmark ProcessorSysbench {} {} (points)'.format(ctype, i)] = sysbench.rate
def get_ram(self, ctype, i, component):
"""Particular fields for component Ram Module."""
if component is None:
self['{} {} Size (MB)'.format(ctype, i)] = ''
self['{} {} Speed (MHz)'.format(ctype, i)] = ''
return
self['{} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
self['{} {} Speed (MHz)'.format(ctype, i)] = none2str(component.speed)
def get_datastorage(self, ctype, i, component):
"""Particular fields for component DataStorage.
A DataStorage can be HardDrive or SolidStateDrive.
"""
if component is None:
self['{} {} Size (MB)'.format(ctype, i)] = ''
self['Erasure {} {}'.format(ctype, i)] = ''
self['Erasure {} {} Serial Number'.format(ctype, i)] = ''
self['Erasure {} {} Size (MB)'.format(ctype, i)] = ''
self['Erasure {} {} Software'.format(ctype, i)] = ''
self['Erasure {} {} Result'.format(ctype, i)] = ''
self['Erasure {} {} Type'.format(ctype, i)] = ''
self['Erasure {} {} Method'.format(ctype, i)] = ''
self['Erasure {} {} Elapsed (hours)'.format(ctype, i)] = ''
self['Erasure {} {} Date'.format(ctype, i)] = ''
self['Erasure {} {} Steps'.format(ctype, i)] = ''
self['Erasure {} {} Steps Start Time'.format(ctype, i)] = ''
self['Erasure {} {} Steps End Time'.format(ctype, i)] = ''
self['Benchmark {} {} Read Speed (MB/s)'.format(ctype, i)] = ''
self['Benchmark {} {} Writing speed (MB/s)'.format(ctype, i)] = ''
self['Test {} {} Software'.format(ctype, i)] = ''
self['Test {} {} Type'.format(ctype, i)] = ''
self['Test {} {} Result'.format(ctype, i)] = ''
self['Test {} {} Power on (hours used)'.format(ctype, i)] = ''
self['Test {} {} Lifetime remaining (percentage)'.format(ctype, i)] = ''
return
snapshot = get_action(component, 'Snapshot')
software = ''
if snapshot:
software = "{software} {version}".format(
software=snapshot.software.name, version=snapshot.version)
self['{} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
erasures = [a for a in component.actions if a.type in ['EraseBasic', 'EraseSectors']]
erasure = erasures[-1] if erasures else None
if not erasure:
self['Erasure {} {}'.format(ctype, i)] = none2str(component.hid)
serial_number = none2str(component.serial_number)
self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number
self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
self['Erasure {} {} Software'.format(ctype, i)] = ''
self['Erasure {} {} Result'.format(ctype, i)] = ''
self['Erasure {} {} Type'.format(ctype, i)] = ''
self['Erasure {} {} Method'.format(ctype, i)] = ''
self['Erasure {} {} Elapsed (hours)'.format(ctype, i)] = ''
self['Erasure {} {} Date'.format(ctype, i)] = ''
self['Erasure {} {} Steps'.format(ctype, i)] = ''
self['Erasure {} {} Steps Start Time'.format(ctype, i)] = ''
self['Erasure {} {} Steps End Time'.format(ctype, i)] = ''
else:
self['Erasure {} {}'.format(ctype, i)] = none2str(component.hid)
serial_number = none2str(component.serial_number)
self['Erasure {} {} Serial Number'.format(ctype, i)] = serial_number
self['Erasure {} {} Size (MB)'.format(ctype, i)] = none2str(component.size)
self['Erasure {} {} Software'.format(ctype, i)] = software
result = get_result(erasure.severity)
self['Erasure {} {} Result'.format(ctype, i)] = result
self['Erasure {} {} Type'.format(ctype, i)] = erasure.type
self['Erasure {} {} Method'.format(ctype, i)] = erasure.method
self['Erasure {} {} Elapsed (hours)'.format(ctype, i)] = format(erasure.elapsed)
self['Erasure {} {} Date'.format(ctype, i)] = format(erasure.created)
steps = ','.join((format(x) for x in erasure.steps))
self['Erasure {} {} Steps'.format(ctype, i)] = steps
steps_start_time = ','.join((format(x.start_time) for x in erasure.steps))
self['Erasure {} {} Steps Start Time'.format(ctype, i)] = steps_start_time
steps_end_time = ','.join((format(x.end_time) for x in erasure.steps))
self['Erasure {} {} Steps End Time'.format(ctype, i)] = steps_end_time
benchmark = get_action(component, 'BenchmarkDataStorage')
if not benchmark:
self['Benchmark {} {} Read Speed (MB/s)'.format(ctype, i)] = ''
self['Benchmark {} {} Writing speed (MB/s)'.format(ctype, i)] = ''
else:
self['Benchmark {} {} Read Speed (MB/s)'.format(ctype, i)] = none2str(
benchmark.read_speed)
self['Benchmark {} {} Writing speed (MB/s)'.format(ctype, i)] = none2str(
benchmark.write_speed)
test_storage = get_action(component, 'TestDataStorage')
if not test_storage:
self['Test {} {} Software'.format(ctype, i)] = ''
self['Test {} {} Type'.format(ctype, i)] = ''
self['Test {} {} Result'.format(ctype, i)] = ''
self['Test {} {} Power on (hours used)'.format(ctype, i)] = ''
self['Test {} {} Lifetime remaining (percentage)'.format(ctype, i)] = ''
return
self['Test {} {} Software'.format(ctype, i)] = software
self['Test {} {} Type'.format(ctype, i)] = test_storage.length.value
self['Test {} {} Result'.format(ctype, i)] = get_result(test_storage.severity)
self['Test {} {} Power on (hours used)'.format(ctype, i)] = none2str(
test_storage.power_cycle_count)
self['Test {} {} Lifetime remaining (percentage)'.format(ctype, i)] = none2str(
test_storage.lifetime)
def get_graphic_card(self, ctype, i, component):
"""Particular fields for component GraphicCard."""
if component is None:
self['{} {} Memory (MB)'.format(ctype, i)] = ''
return
self['{} {} Memory (MB)'.format(ctype, i)] = none2str(component.memory)
class StockRow(OrderedDict):
def __init__(self, device: d.Device) -> None:
super().__init__()
self.device = device
self['Type'] = convert_none_to_empty_str(device.t)
self['Type'] = none2str(device.t)
if isinstance(device, d.Computer):
self['Chassis'] = device.chassis
else:
self['Chassis'] = ''
self['Serial Number'] = convert_none_to_empty_str(device.serial_number)
self['Model'] = convert_none_to_empty_str(device.model)
self['Manufacturer'] = convert_none_to_empty_str(device.manufacturer)
self['Serial Number'] = none2str(device.serial_number)
self['Model'] = none2str(device.model)
self['Manufacturer'] = none2str(device.manufacturer)
self['Registered in'] = format(device.created, '%c')
try:
self['Physical state'] = device.last_action_of(*states.Physical.actions()).t
@ -150,10 +313,10 @@ class StockRow(OrderedDict):
self['Trading state'] = device.last_action_of(*states.Trading.actions()).t
except LookupError:
self['Trading state'] = ''
self['Price'] = convert_none_to_empty_str(device.price)
self['Processor'] = convert_none_to_empty_str(device.processor_model)
self['RAM (MB)'] = convert_none_to_empty_str(device.ram_size)
self['Data Storage Size (MB)'] = convert_none_to_empty_str(device.data_storage_size)
self['Price'] = none2str(device.price)
self['Processor'] = none2str(device.processor_model)
self['RAM (MB)'] = none2str(device.ram_size)
self['Data Storage Size (MB)'] = none2str(device.data_storage_size)
rate = device.rate
if rate:
self['Rate'] = rate.rating
@ -167,7 +330,24 @@ class StockRow(OrderedDict):
self['Data Storage Range'] = rate.data_storage_range
def convert_none_to_empty_str(s):
if s is None:
def get_result(severity):
""" For the csv is necessary simplify the message of results """
type_of_results = {
Severity.Error: 'Failure',
Severity.Warning: 'Success with Warnings',
Severity.Notice: 'Success',
Severity.Info: 'Success'
}
return type_of_results[severity]
def none2str(string):
""" convert none to empty str """
if string is None:
return ''
return s
return format(string)
def get_action(component, action):
""" Filter one action from a component or return None """
result = [a for a in component.actions if a.type == action]
return result[-1] if result else None

View File

@ -117,7 +117,7 @@ class DevicesDocumentView(DeviceView):
def generate_post_csv(self, query):
"""Get device query and put information in csv format."""
data = StringIO()
cw = csv.writer(data)
cw = csv.writer(data, delimiter=';', quotechar='"')
first = True
for device in query:
d = DeviceRow(device)
@ -125,7 +125,7 @@ class DevicesDocumentView(DeviceView):
cw.writerow(d.keys())
first = False
cw.writerow(d.values())
output = make_response(data.getvalue())
output = make_response(data.getvalue().encode('utf-8'))
output.headers['Content-Disposition'] = 'attachment; filename=export.csv'
output.headers['Content-type'] = 'text/csv'
return output

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,272 @@
{
"components": [
{
"resolutionHeight": 600,
"model": "AUO LCD Monitor",
"manufacturer": "AUO \"AUO\"",
"size": 10.0,
"resolutionWidth": 1024,
"productionDate": "2009-01-04T00:00:00",
"refreshRate": 60,
"technology": "LCD",
"type": "Display",
"serialNumber": null,
"actions": []
},
{
"type": "NetworkAdapter",
"model": "AR9285 Wireless Network Adapter",
"serialNumber": "74:2f:68:8b:fd:c8",
"manufacturer": "Qualcomm Atheros",
"wireless": true,
"actions": []
},
{
"type": "NetworkAdapter",
"model": "AR8152 v2.0 Fast Ethernet",
"serialNumber": "14:da:e9:42:f6:7c",
"manufacturer": "Qualcomm Atheros",
"speed": 100,
"wireless": false,
"actions": []
},
{
"type": "Processor",
"cores": 1,
"threads": 1,
"address": 64,
"model": "Intel Atom CPU N455 @ 1.66GHz",
"serialNumber": null,
"manufacturer": "Intel Corp.",
"speed": 1.667,
"actions": [
{
"type": "BenchmarkProcessorSysbench",
"rate": 164.0803,
"elapsed": 164
},
{
"type": "BenchmarkProcessor",
"rate": 6666.24,
"elapsed": 0
}
]
},
{
"type": "GraphicCard",
"model": "Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller",
"serialNumber": null,
"memory": 256.0,
"manufacturer": "Intel Corporation",
"actions": []
},
{
"type": "SoundCard",
"model": "NM10/ICH7 Family High Definition Audio Controller",
"serialNumber": null,
"manufacturer": "Intel Corporation",
"actions": []
},
{
"type": "SoundCard",
"model": "USB 2.0 UVC VGA WebCam",
"serialNumber": "0x0001",
"manufacturer": "Azurewave",
"actions": []
},
{
"type": "RamModule",
"format": "DIMM",
"model": null,
"size": 1024,
"interface": "DDR3",
"serialNumber": null,
"manufacturer": null,
"speed": 667.0,
"actions": []
},
{
"size": 1024.0,
"actions": [],
"format": "SODIMM",
"model": "48594D503131325336344350362D53362020",
"interface": "DDR3",
"type": "RamModule",
"manufacturer": "Hynix Semiconductor",
"serialNumber": "4F43487B",
"speed": 667.0
},
{
"type": "HardDrive",
"model": "HTS54322",
"size": 238475,
"interface": "ATA",
"serialNumber": "E2024242CV86HJ",
"manufacturer": "Hitachi",
"actions": [
{
"type": "BenchmarkDataStorage",
"elapsed": 16,
"writeSpeed": 21.8,
"readSpeed": 66.2
},
{
"type": "TestDataStorage",
"length": "Extended",
"elapsed": 2,
"severity": "Error",
"status": "Unspecified Error. Self-test not started."
},
{
"type": "EraseBasic",
"steps": [
{
"type": "StepRandom",
"startTime": "2018-07-03T09:15:22.257059+00:00",
"severity": "Info",
"endTime": "2018-07-03T10:32:11.843190+00:00"
}
],
"startTime": "2018-07-03T09:15:22.256074+00:00",
"severity": "Info",
"endTime": "2018-07-03T10:32:11.848455+00:00"
}
]
},
{
"size": 160041.88569599998,
"variant": "1A01",
"actions": [
{
"type": "EraseBasic",
"steps": [
{
"type": "StepRandom",
"endTime": "2019-10-23T08:35:31.400587+00:00",
"severity": "Info",
"startTime": "2019-10-23T07:49:54.410830+00:00"
}
],
"endTime": "2019-10-23T08:35:31.400988+00:00",
"severity": "Error",
"startTime": "2019-10-23T07:49:54.410193+00:00"
},
{
"elapsed": 22,
"writeSpeed": 17.3,
"readSpeed": 41.6,
"type": "BenchmarkDataStorage"
},
{
"status": "Completed without error",
"reallocatedSectorCount": 0,
"currentPendingSectorCount": 0,
"assessment": true,
"severity": "Info",
"offlineUncorrectable": 0,
"lifetime": 4692,
"type": "TestDataStorage",
"length": "Short",
"elapsed": 118,
"powerCycleCount": 5293
}
],
"model": "WDC WD1600BEVT-2",
"interface": "ATA",
"type": "DataStorage",
"manufacturer": "Western Digital",
"serialNumber": "WD-WX11A80W7430"
},
{
"actions": [
{
"writeSpeed": 17.1,
"type": "BenchmarkDataStorage",
"elapsed": 22,
"readSpeed": 41.1
},
{
"type": "EraseSectors",
"startTime": "2019-08-19T16:48:19.689794+00:00",
"steps": [
{
"startTime": "2019-08-19T16:48:19.690458+00:00",
"type": "StepRandom",
"severity": "Info",
"endTime": "2019-08-19T17:34:22.930562+00:00"
},
{
"startTime": "2019-08-19T17:34:22.690458+00:00",
"type": "StepZero",
"severity": "Info",
"endTime": "2019-08-19T18:34:22.930562+00:00"
}
],
"severity": "Info",
"endTime": "2019-08-19T18:34:22.930959+00:00"
},
{
"currentPendingSectorCount": 0,
"lifetime": 4673,
"elapsed": 115,
"reallocatedSectorCount": 0,
"powerCycleCount": 5231,
"status": "Completed without error",
"assessment": true,
"type": "TestDataStorage",
"severity": "Info",
"length": "Short",
"offlineUncorrectable": 0
}
],
"model": "WDC WD1600BEVT-2",
"manufacturer": "Western Digital",
"size": 160042.0,
"interface": "ATA",
"serialNumber": "WD-WX11A80W7430",
"type": "SolidStateDrive",
"variant": "1A01"
},
{
"type": "Motherboard",
"serial": 1,
"firewire": 0,
"model": "1001PXD",
"slots": 2,
"pcmcia": 0,
"serialNumber": "Eee0123456789",
"usb": 5,
"manufacturer": "ASUSTeK Computer INC.",
"actions": [
{
"type": "TestBios",
"accessRange": "C"
}
]
}
],
"elapsed": 4875,
"uuid": "3fd12a01-c04e-4fd8-9e64-2660c459e725",
"version": "11.0b11",
"type": "Snapshot",
"software": "Workbench",
"device": {
"type": "Laptop",
"model": "1001PXD",
"serialNumber": "B8OAAS048287",
"manufacturer": "ASUSTeK Computer INC.",
"chassis": "Netbook",
"actions": [
{
"type": "BenchmarkRamSysbench",
"rate": 15.7188,
"elapsed": 16
},
{
"type": "StressTest",
"severity": "Info",
"elapsed": 60
}
]
}
}

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,162 @@
{
"components": [
{
"type": "NetworkAdapter",
"model": "AR9285 Wireless Network Adapter",
"serialNumber": "74:2f:68:8b:fd:c9",
"manufacturer": "Qualcomm Atheros",
"wireless": true,
"actions": []
},
{
"type": "NetworkAdapter",
"model": "AR8152 v2.0 Fast Ethernet",
"serialNumber": "14:da:e9:42:f6:7b",
"manufacturer": "Qualcomm Atheros",
"speed": 100,
"wireless": false,
"actions": []
},
{
"type": "Processor",
"cores": 1,
"threads": 1,
"address": 64,
"model": "Intel Atom CPU N455 @ 2.66GHz",
"serialNumber": null,
"manufacturer": "Intel Corp.",
"speed": 2.667,
"actions": [
{
"type": "BenchmarkProcessorSysbench",
"rate": 164.0803,
"elapsed": 164
},
{
"type": "BenchmarkProcessor",
"rate": 6666.24,
"elapsed": 0
}
]
},
{
"type": "GraphicCard",
"model": "Atom Processor D4xx/D5xx/N4xx/N5xx Integrated Graphics Controller",
"serialNumber": null,
"memory": 256.0,
"manufacturer": "Intel Corporation",
"actions": []
},
{
"type": "SoundCard",
"model": "NM10/ICH7 Family High Definition Audio Controller",
"serialNumber": null,
"manufacturer": "Intel Corporation",
"actions": []
},
{
"type": "SoundCard",
"model": "USB 2.0 UVC VGA WebCam",
"serialNumber": "0x0001",
"manufacturer": "Azurewave",
"actions": []
},
{
"type": "RamModule",
"format": "DIMM",
"model": null,
"size": 1024,
"interface": "DDR2",
"serialNumber": null,
"manufacturer": null,
"speed": 667.0,
"actions": []
},
{
"type": "HardDrive",
"model": "HTS54322",
"size": 238475,
"interface": "ATA",
"serialNumber": "E2024242CV86MM",
"manufacturer": "Hitachi",
"actions": [
{
"type": "BenchmarkDataStorage",
"elapsed": 16,
"writeSpeed": 21.8,
"readSpeed": 66.2
},
{
"type": "TestDataStorage",
"length": "Short",
"elapsed": 2,
"severity": "Error",
"status": "Unspecified Error. Self-test not started."
},
{
"type": "EraseBasic",
"steps": [
{
"type": "StepRandom",
"startTime": "2018-07-03T09:15:22.257059+00:00",
"severity": "Info",
"endTime": "2018-07-03T10:32:11.843190+00:00"
}
],
"startTime": "2018-07-03T09:15:22.256074+00:00",
"severity": "Info",
"endTime": "2018-07-03T10:32:11.848455+00:00"
}
]
},
{
"type": "Motherboard",
"serial": 1,
"firewire": 0,
"model": "1001PXD",
"slots": 2,
"pcmcia": 0,
"serialNumber": "Eee0123456720",
"usb": 5,
"manufacturer": "ASUSTeK Computer INC.",
"actions": [
{
"type": "TestBios",
"accessRange": "C"
}
]
}
],
"elapsed": 4875,
"uuid": "c058e8d2-fb92-47cb-a4b7-522b75561135",
"version": "11.0a2",
"type": "Snapshot",
"software": "Workbench",
"endTime": "2018-07-03T09:10:57.034598+00:00",
"device": {
"type": "Laptop",
"model": "1001PXD",
"serialNumber": "B8OAAS048285",
"manufacturer": "ASUSTeK Computer INC.",
"chassis": "Netbook",
"actions": [
{
"type": "BenchmarkRamSysbench",
"rate": 15.7188,
"elapsed": 16
},
{
"type": "StressTest",
"severity": "Info",
"elapsed": 60
},
{
"appearanceRange": "B",
"functionalityRange": "A",
"type": "VisualTest"
}
]
},
"closed": false
}

View File

@ -8,9 +8,13 @@ import teal.marshmallow
from ereuse_utils.test import ANY
from ereuse_devicehub.client import Client, UserClient
from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.action.models import Snapshot
from ereuse_devicehub.resources.documents import documents
from ereuse_devicehub.resources.device import models as d
from ereuse_devicehub.resources.lot.models import Lot
from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.db import db
from tests.conftest import file
@ -84,52 +88,68 @@ def test_export_basic_snapshot(user: UserClient):
accept='text/csv',
query=[('filter', {'type': ['Computer']})])
f = StringIO(csv_str)
obj_csv = csv.reader(f, f)
obj_csv = csv.reader(f, f, delimiter=';', quotechar='"')
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)
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
fixture_csv = list(obj_csv)
assert isinstance(datetime.strptime(export_csv[1][8], '%c'), datetime), \
assert isinstance(datetime.strptime(export_csv[1][17], '%c'), datetime), \
'Register in field is not a datetime'
# 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'
assert fixture_csv[1][:17] == export_csv[1][:17], 'Computer information are not equal'
assert fixture_csv[1][18] == export_csv[1][18], 'Computer information are not equal'
assert fixture_csv[1][20:] == export_csv[1][20:], 'Computer information are not equal'
@pytest.mark.mvp
def test_export_full_snapshot(user: UserClient):
def test_export_extended(app: Devicehub, 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)
snapshot1, _ = user.post(file('real-eee-1001pxd.snapshot.12'), res=Snapshot, status=201)
snapshot2, _ = user.post(file('complete.export.snapshot'), res=Snapshot, status=201)
with app.app_context():
# Create a pc with a tag
tag = Tag(id='foo', owner_id=user.user['id'])
# pc = Desktop(serial_number='sn1', chassis=ComputerChassis.Tower, owner_id=user.user['id'])
pc = d.Device.query.filter_by(id=snapshot1['device']['id']).first()
pc.tags.add(tag)
db.session.add(pc)
db.session.commit()
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)
obj_csv = csv.reader(f, f, delimiter=';', quotechar='"')
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)
with Path(__file__).parent.joinpath('files').joinpath(
'proposal_extended_csv_report.csv').open() as csv_file:
obj_csv = csv.reader(csv_file, delimiter=';', quotechar='"')
fixture_csv = list(obj_csv)
assert isinstance(datetime.strptime(export_csv[1][8], '%c'), datetime), \
assert isinstance(datetime.strptime(export_csv[1][17], '%c'), datetime), \
'Register in field is not a datetime'
# 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'
assert fixture_csv[1][:17] == export_csv[1][:17], 'Computer information are not equal'
assert fixture_csv[1][18] == export_csv[1][18], 'Computer information are not equal'
assert fixture_csv[1][20:79] == export_csv[1][20:79], 'Computer information are not equal'
assert fixture_csv[1][80] == export_csv[1][80], 'Computer information are not equal'
assert fixture_csv[1][83:] == export_csv[1][83:], 'Computer information are not equal'
assert fixture_csv[2][:17] == export_csv[2][:17], 'Computer information are not equal'
assert fixture_csv[2][18] == export_csv[2][18], 'Computer information are not equal'
assert fixture_csv[2][20:79] == export_csv[2][20:79], 'Computer information are not equal'
assert fixture_csv[2][80] == export_csv[2][80], 'Computer information are not equal'
assert fixture_csv[2][83:103] == export_csv[2][83:103], 'Computer information are not equal'
assert fixture_csv[2][104] == export_csv[2][104], 'Computer information are not equal'
assert fixture_csv[2][107:127] == export_csv[2][107:127], 'Computer information are not equal'
assert fixture_csv[2][128] == export_csv[2][128], 'Computer information are not equal'
assert fixture_csv[2][131:] == export_csv[2][131:], 'Computer information are not equal'
@pytest.mark.mvp