Update device structure

This commit is contained in:
Xavier Bustamante Talavera 2018-06-26 15:35:13 +02:00
parent fd936fd0e3
commit b0b455d4f0
24 changed files with 452 additions and 331 deletions

View File

@ -1,10 +1,11 @@
from distutils.version import StrictVersion from distutils.version import StrictVersion
from typing import Set from typing import Set
from ereuse_devicehub.resources.device import ComponentDef, ComputerDef, ComputerMonitorDef, \ from ereuse_devicehub.resources.device import CellphoneDef, ComponentDef, ComputerDef, \
DataStorageDef, DesktopDef, DeviceDef, GraphicCardDef, HardDriveDef, LaptopDef, MicrotowerDef, \ ComputerMonitorDef, DataStorageDef, DesktopDef, DeviceDef, DisplayDef, GraphicCardDef, \
MotherboardDef, NetbookDef, NetworkAdapterDef, ProcessorDef, RamModuleDef, ServerDef, \ HardDriveDef, LaptopDef, MobileDef, MonitorDef, MotherboardDef, NetworkAdapterDef, \
SolidStateDriveDef ProcessorDef, RamModuleDef, ServerDef, SmartphoneDef, SolidStateDriveDef, TabletDef, \
TelevisionSetDef
from ereuse_devicehub.resources.event import AddDef, AggregateRateDef, AppRateDef, \ from ereuse_devicehub.resources.event import AddDef, AggregateRateDef, AppRateDef, \
BenchmarkDataStorageDef, BenchmarkDef, BenchmarkProcessorDef, BenchmarkProcessorSysbenchDef, \ BenchmarkDataStorageDef, BenchmarkDef, BenchmarkProcessorDef, BenchmarkProcessorSysbenchDef, \
BenchmarkRamSysbenchDef, BenchmarkWithRateDef, EraseBasicDef, EraseSectorsDef, EventDef, \ BenchmarkRamSysbenchDef, BenchmarkWithRateDef, EraseBasicDef, EraseSectorsDef, EventDef, \
@ -19,9 +20,9 @@ from teal.config import Config
class DevicehubConfig(Config): class DevicehubConfig(Config):
RESOURCE_DEFINITIONS = { RESOURCE_DEFINITIONS = {
DeviceDef, ComputerDef, DesktopDef, LaptopDef, NetbookDef, ServerDef, DeviceDef, ComputerDef, DesktopDef, LaptopDef, ServerDef, MonitorDef, TelevisionSetDef,
MicrotowerDef, ComputerMonitorDef, ComponentDef, GraphicCardDef, DataStorageDef, ComputerMonitorDef, ComponentDef, GraphicCardDef, DataStorageDef,
SolidStateDriveDef, SolidStateDriveDef, MobileDef, DisplayDef, SmartphoneDef, TabletDef, CellphoneDef,
HardDriveDef, MotherboardDef, NetworkAdapterDef, RamModuleDef, ProcessorDef, UserDef, HardDriveDef, MotherboardDef, NetworkAdapterDef, RamModuleDef, ProcessorDef, UserDef,
OrganizationDef, TagDef, EventDef, AddDef, RemoveDef, EraseBasicDef, EraseSectorsDef, OrganizationDef, TagDef, EventDef, AddDef, RemoveDef, EraseBasicDef, EraseSectorsDef,
StepDef, StepZeroDef, StepRandomDef, RateDef, AggregateRateDef, WorkbenchRateDef, StepDef, StepZeroDef, StepRandomDef, RateDef, AggregateRateDef, WorkbenchRateDef,

View File

@ -11,7 +11,8 @@ version: '11.0'
software: Workbench software: Workbench
elapsed: 500 elapsed: 500
device: device:
type: Microtower type: Desktop
chassis: Tower
serialNumber: d1s serialNumber: d1s
model: d1ml model: d1ml
manufacturer: d1mr manufacturer: d1mr

View File

@ -1,6 +1,7 @@
from ereuse_devicehub.resources.device.schemas import Component, Computer, ComputerMonitor, \ from ereuse_devicehub.resources.device.schemas import Cellphone, Component, Computer, \
DataStorage, Desktop, Device, GraphicCard, HardDrive, Laptop, Microtower, Motherboard, Netbook, \ ComputerMonitor, DataStorage, Desktop, Device, Display, GraphicCard, HardDrive, Laptop, Mobile, \
NetworkAdapter, Processor, RamModule, Server, SolidStateDrive Monitor, Motherboard, NetworkAdapter, Processor, RamModule, Server, Smartphone, \
SolidStateDrive, Tablet, TelevisionSet
from ereuse_devicehub.resources.device.views import DeviceView from ereuse_devicehub.resources.device.views import DeviceView
from teal.resource import Converters, Resource from teal.resource import Converters, Resource
@ -27,26 +28,46 @@ class LaptopDef(ComputerDef):
SCHEMA = Laptop SCHEMA = Laptop
class NetbookDef(ComputerDef):
VIEW = None
SCHEMA = Netbook
class ServerDef(ComputerDef): class ServerDef(ComputerDef):
VIEW = None VIEW = None
SCHEMA = Server SCHEMA = Server
class MicrotowerDef(ComputerDef): class MonitorDef(DeviceDef):
VIEW = None VIEW = None
SCHEMA = Microtower SCHEMA = Monitor
class ComputerMonitorDef(DeviceDef): class ComputerMonitorDef(MonitorDef):
VIEW = None VIEW = None
SCHEMA = ComputerMonitor SCHEMA = ComputerMonitor
class TelevisionSetDef(MonitorDef):
VIEW = None
SCHEMA = TelevisionSet
class MobileDef(DeviceDef):
VIEW = None
SCHEMA = Mobile
class SmartphoneDef(MobileDef):
VIEW = None
SCHEMA = Smartphone
class TabletDef(MobileDef):
VIEW = None
SCHEMA = Tablet
class CellphoneDef(MobileDef):
VIEW = None
SCHEMA = Cellphone
class ComponentDef(DeviceDef): class ComponentDef(DeviceDef):
VIEW = None VIEW = None
SCHEMA = Component SCHEMA = Component
@ -90,3 +111,8 @@ class RamModuleDef(ComponentDef):
class ProcessorDef(ComponentDef): class ProcessorDef(ComponentDef):
VIEW = None VIEW = None
SCHEMA = Processor SCHEMA = Processor
class DisplayDef(ComponentDef):
VIEW = None
SCHEMA = Display

View File

@ -141,7 +141,7 @@ class ComputerMonitor(Device):
size.comment = """ size.comment = """
The size of the monitor in inches. The size of the monitor in inches.
""" """
technology = Column(DBEnum(ComputerMonitorTechnologies)) technology = Column(DBEnum(DisplayTech))
technology.comment = """ technology.comment = """
The technology the monitor uses to display the image. The technology the monitor uses to display the image.
""" """
@ -224,8 +224,15 @@ class Motherboard(JoinedComponentTableMixin, Component):
pcmcia = Column(SmallInteger, check_range('pcmcia')) pcmcia = Column(SmallInteger, check_range('pcmcia'))
class NetworkAdapter(JoinedComponentTableMixin, Component): class NetworkMixin:
speed = Column(SmallInteger, check_range('speed', min=10, max=10000)) speed = Column(SmallInteger, check_range('speed', min=10, max=10000))
speed.comment = """
The maximum speed this network adapter can handle, in mbps.
"""
class NetworkAdapter(JoinedComponentTableMixin, NetworkMixin, Component):
pass
class Processor(JoinedComponentTableMixin, Component): class Processor(JoinedComponentTableMixin, Component):

View File

@ -3,7 +3,7 @@ from typing import Dict, List, Set
from colour import Color from colour import Color
from sqlalchemy import Column, Integer from sqlalchemy import Column, Integer
from ereuse_devicehub.resources.enums import ComputerMonitorTechnologies, DataStorageInterface, \ from ereuse_devicehub.resources.enums import ComputerChassis, DataStorageInterface, DisplayTech, \
RamFormat, RamInterface RamFormat, RamInterface
from ereuse_devicehub.resources.event.models import Event, EventWithMultipleDevices, \ from ereuse_devicehub.resources.event.models import Event, EventWithMultipleDevices, \
EventWithOneDevice EventWithOneDevice
@ -46,17 +46,40 @@ class Device(Thing):
self.tags = ... # type: Set[Tag] self.tags = ... # type: Set[Tag]
class Computer(Device): class DisplayMixin:
technology = ... # type: Column
size = ... # type: Column
resolution_width = ... # type: Column
resolution_height = ... # type: Column
def __init__(self) -> None:
super().__init__()
self.technology = ... # type: DisplayTech
self.size = ... # type: Integer
self.resolution_width = ... # type: int
self.resolution_height = ... # type: int
class Computer(DisplayMixin, Device):
components = ... # type: Column
chassis = ... # type: Column
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
super().__init__(**kwargs) super().__init__(**kwargs)
self.components = ... # type: Set[Component] self.components = ... # type: Set[Component]
self.events_parent = ... # type: Set[Event] self.events_parent = ... # type: Set[Event]
class Desktop(Computer): class Desktop(Computer):
pass pass
class ComputerMonitor(Monitor):
pass
class TelevisionSet(Monitor):
pass
class Laptop(Computer): class Laptop(Computer):
pass pass

View File

@ -2,18 +2,20 @@ from marshmallow import post_load, pre_load
from marshmallow.fields import Float, Integer, Str from marshmallow.fields import Float, Integer, Str
from marshmallow.validate import Length, OneOf, Range from marshmallow.validate import Length, OneOf, Range
from sqlalchemy.util import OrderedSet from sqlalchemy.util import OrderedSet
from stdnum import imei, meid
from ereuse_devicehub.marshmallow import NestedOn from ereuse_devicehub.marshmallow import NestedOn
from ereuse_devicehub.resources.device import models as m from ereuse_devicehub.resources.device import models as m
from ereuse_devicehub.resources.enums import ComputerMonitorTechnologies, RamFormat, RamInterface from ereuse_devicehub.resources.enums import ComputerChassis, DisplayTech, \
RamFormat, RamInterface
from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE from ereuse_devicehub.resources.models import STR_BIG_SIZE, STR_SIZE
from ereuse_devicehub.resources.schemas import Thing, UnitCodes from ereuse_devicehub.resources.schemas import Thing, UnitCodes
from teal.marshmallow import EnumField, ValidationError from teal.marshmallow import EnumField, ValidationError
class Device(Thing): class Device(Thing):
id = Integer(description=m.Device.id.comment.strip(), dump_only=True) id = Integer(description=m.Device.id.comment, dump_only=True)
hid = Str(dump_only=True, description=m.Device.hid.comment.strip()) hid = Str(dump_only=True, description=m.Device.hid.comment)
tags = NestedOn('Tag', tags = NestedOn('Tag',
many=True, many=True,
collection_class=OrderedSet, collection_class=OrderedSet,
@ -21,15 +23,9 @@ class Device(Thing):
model = Str(validate=Length(max=STR_BIG_SIZE)) model = Str(validate=Length(max=STR_BIG_SIZE))
manufacturer = Str(validate=Length(max=STR_SIZE)) manufacturer = Str(validate=Length(max=STR_SIZE))
serial_number = Str(data_key='serialNumber') serial_number = Str(data_key='serialNumber')
weight = Float(validate=Range(0.1, 3), weight = Float(validate=Range(0.1, 3), unit=UnitCodes.kgm, description=m.Device.weight.comment)
unit=UnitCodes.kgm, width = Float(validate=Range(0.1, 3), unit=UnitCodes.m, description=m.Device.width.comment)
description=m.Device.weight.comment.strip()) height = Float(validate=Range(0.1, 3), unit=UnitCodes.m, description=m.Device.height.comment)
width = Float(validate=Range(0.1, 3),
unit=UnitCodes.m,
description=m.Device.width.comment.strip())
height = Float(validate=Range(0.1, 3),
unit=UnitCodes.m,
description=m.Device.height.comment.strip())
events = NestedOn('Event', many=True, dump_only=True, description=m.Device.events.__doc__) events = NestedOn('Event', many=True, dump_only=True, description=m.Device.events.__doc__)
events_one = NestedOn('Event', many=True, load_only=True, collection_class=OrderedSet) events_one = NestedOn('Event', many=True, load_only=True, collection_class=OrderedSet)
@ -60,6 +56,7 @@ class Device(Thing):
class Computer(Device): class Computer(Device):
components = NestedOn('Component', many=True, dump_only=True, collection_class=OrderedSet) components = NestedOn('Component', many=True, dump_only=True, collection_class=OrderedSet)
chassis = EnumField(ComputerChassis, required=True)
class Desktop(Computer): class Desktop(Computer):
@ -70,28 +67,61 @@ class Laptop(Computer):
pass pass
class Netbook(Computer):
pass
class Server(Computer): class Server(Computer):
pass pass
class Microtower(Computer): class DisplayMixin:
size = Float(description=m.DisplayMixin.size.comment, validate=Range(2, 150))
technology = EnumField(DisplayTech,
description=m.DisplayMixin.technology.comment)
resolution_width = Integer(data_key='resolutionWidth',
validate=Range(10, 20000),
description=m.DisplayMixin.resolution_width.comment)
resolution_height = Integer(data_key='resolutionHeight',
validate=Range(10, 20000),
description=m.DisplayMixin.resolution_height.comment)
class NetworkMixin:
speed = Integer(validate=Range(min=10, max=10000),
unit=UnitCodes.mbps,
description=m.NetworkAdapter.speed.comment)
class Monitor(DisplayMixin, Device):
pass pass
class ComputerMonitor(Device): class ComputerMonitor(Monitor):
size = Float(description=m.ComputerMonitor.size.comment.strip(), validate=Range(2, 150)) pass
technology = EnumField(ComputerMonitorTechnologies,
description=m.ComputerMonitor.technology.comment.strip())
resolution_width = Integer(data_key='resolutionWidth', class TelevisionSet(Monitor):
validate=Range(10, 20000), pass
description=m.ComputerMonitor.resolution_width.comment.strip())
resolution_height = Integer(data_key='resolutionHeight',
validate=Range(10, 20000), class Mobile(Device):
description=m.ComputerMonitor.resolution_height.comment.strip()) imei = Integer(validate=lambda x: imei.validate(str(x)),
description=m.Mobile.imei.comment)
meid = Str(validate=meid.validate, description=m.Mobile.meid.comment)
@post_load
def convert_meid(self, data: dict):
if 'meid' in data:
data['meid'] = meid.compact(data['meid'])
class Smartphone(Mobile):
pass
class Tablet(Mobile):
pass
class Cellphone(Mobile):
pass
class Component(Device): class Component(Device):
@ -101,13 +131,13 @@ class Component(Device):
class GraphicCard(Component): class GraphicCard(Component):
memory = Integer(validate=Range(0, 10000), memory = Integer(validate=Range(0, 10000),
unit=UnitCodes.mbyte, unit=UnitCodes.mbyte,
description='The amount of memory of the Graphic Card in MB.') description=m.GraphicCard.memory.comment)
class DataStorage(Component): class DataStorage(Component):
size = Integer(validate=Range(0, 10 ** 8), size = Integer(validate=Range(0, 10 ** 8),
unit=UnitCodes.mbyte, unit=UnitCodes.mbyte,
description='The size of the hard-drive in MB.') description=m.DataStorage.size.comment)
class HardDrive(DataStorage): class HardDrive(DataStorage):
@ -119,7 +149,8 @@ class SolidStateDrive(DataStorage):
class Motherboard(Component): class Motherboard(Component):
slots = Integer(validate=Range(1, 20), description='PCI slots the motherboard has.') slots = Integer(validate=Range(1, 20),
description=m.Motherboard.slots.comment)
usb = Integer(validate=Range(0, 20)) usb = Integer(validate=Range(0, 20))
firewire = Integer(validate=Range(0, 20)) firewire = Integer(validate=Range(0, 20))
serial = Integer(validate=Range(0, 20)) serial = Integer(validate=Range(0, 20))

View File

@ -152,7 +152,7 @@ class DataStorageInterface(Enum):
@unique @unique
class ComputerMonitorTechnologies(Enum): class DisplayTech(Enum):
CRT = 'Cathode ray tube (CRT)' CRT = 'Cathode ray tube (CRT)'
TFT = 'Thin-film-transistor liquid-crystal (TFT)' TFT = 'Thin-film-transistor liquid-crystal (TFT)'
LED = 'LED-backlit (LED)' LED = 'LED-backlit (LED)'

View File

@ -31,6 +31,7 @@ class Event(Thing):
components = ... # type: relationship components = ... # type: relationship
parent_id = ... # type: Column parent_id = ... # type: Column
parent = ... # type: relationship parent = ... # type: relationship
closed = ... # type: Column
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
super().__init__(**kwargs) super().__init__(**kwargs)
@ -64,6 +65,14 @@ class EventWithMultipleDevices(Event):
self.devices = ... # type: Set[Device] self.devices = ... # type: Set[Device]
class Add(EventWithOneDevice):
pass
class Remove(EventWithOneDevice):
pass
class Step(Model): class Step(Model):
def __init__(self, **kwargs) -> None: def __init__(self, **kwargs) -> None:
self.erasure_id = ... # type: UUID self.erasure_id = ... # type: UUID

View File

@ -18,17 +18,15 @@ from teal.resource import Schema
class Event(Thing): class Event(Thing):
id = UUID(dump_only=True) id = UUID(dump_only=True)
name = String(default='', name = String(default='', validate=Length(STR_BIG_SIZE), description=m.Event.name.comment)
validate=Length(STR_BIG_SIZE), date = DateTime('iso', description=m.Event.date.comment)
description=m.Event.name.comment.strip()) error = Boolean(default=False, description=m.Event.error.comment)
date = DateTime('iso', description=m.Event.date.comment.strip()) incidence = Boolean(default=False, description=m.Event.incidence.comment)
error = Boolean(default=False, description=m.Event.error.comment.strip())
incidence = Boolean(default=False, description=m.Event.incidence.comment.strip())
snapshot = NestedOn('Snapshot', dump_only=True) snapshot = NestedOn('Snapshot', dump_only=True)
components = NestedOn(Component, dump_only=True, many=True) components = NestedOn(Component, dump_only=True, many=True)
description = String(default='', description=m.Event.description.comment.strip()) description = String(default='', description=m.Event.description.comment)
author = NestedOn(User, dump_only=True, exclude=('token',)) author = NestedOn(User, dump_only=True, exclude=('token',))
closed = Boolean(missing=True, description=m.Event.closed.comment.strip()) closed = Boolean(missing=True, description=m.Event.closed.comment)
class EventWithOneDevice(Event): class EventWithOneDevice(Event):

View File

@ -1,23 +1,24 @@
device: device:
manufacturer: 'p1' manufacturer: p1
serialNumber: 'p1' serialNumber: p1
model: 'p1' model: p1
type: 'Desktop' type: Desktop
chassis: Tower
components: components:
- manufacturer: 'p1c1m' - manufacturer: p1c1m
serialNumber: 'p1c1s' serialNumber: p1c1s
type: 'Motherboard' type: Motherboard
- manufacturer: 'p1c2m' - manufacturer: p1c2m
serialNumber: 'p1c2s' serialNumber: p1c2s
model: 'p1c2' model: p1c2
speed: 1.23 speed: 1.23
cores: 2 cores: 2
type: 'Processor' type: Processor
- manufacturer: 'p1c3m' - manufacturer: p1c3m
serialNumber: 'p1c3s' serialNumber: p1c3s
type: 'GraphicCard' type: GraphicCard
memory: 1.5 memory: 1.5
elapsed: 25 elapsed: 25
software: 'Workbench' software: Workbench
uuid: '76860eca-c3fd-41f6-a801-6af7bd8cf832' uuid: 76860eca-c3fd-41f6-a801-6af7bd8cf832
version: '11.0' version: '11.0'

View File

@ -1,19 +1,20 @@
device: device:
manufacturer: 'p2m' manufacturer: p2m
serialNumber: 'p2s' serialNumber: p2s
model: 'p2' model: p2
type: 'Microtower' type: Computer
chassis: Microtower
components: components:
- manufacturer: 'p2c1m' - manufacturer: p2c1m
serialNumber: 'p2c1s' serialNumber: p2c1s
type: 'Motherboard' type: Motherboard
- manufacturer: 'p1c2m' - manufacturer: p1c2m
serialNumber: 'p1c2s' serialNumber: p1c2s
model: 'p1c2' model: p1c2
speed: 1.23 speed: 1.23
cores: 2 cores: 2
type: 'Processor' type: Processor
elapsed: 25 elapsed: 25
software: 'Workbench' software: Workbench
uuid: 'f2e02261-87a1-4a50-b9b7-92c0e476e5f2' uuid: f2e02261-87a1-4a50-b9b7-92c0e476e5f2
version: '11.0' version: '11.0'

View File

@ -1,20 +1,21 @@
device: device:
manufacturer: 'p1' manufacturer: p1
serialNumber: 'p1' serialNumber: p1
model: 'p1' model: p1
type: 'Desktop' type: Desktop
chassis: Microtower
components: components:
- manufacturer: 'p1c2m' - manufacturer: p1c2m
serialNumber: 'p1c2s' serialNumber: p1c2s
model: 'p1c2' model: p1c2
type: 'Processor' type: Processor
cores: 2 cores: 2
speed: 1.23 speed: 1.23
- manufacturer: 'p1c3m' - manufacturer: p1c3m
serialNumber: 'p1c3s' serialNumber: p1c3s
type: 'GraphicCard' type: GraphicCard
memory: 1.5 memory: 1.5
elapsed: 30 elapsed: 30
software: 'Workbench' software: Workbench
uuid: '3be271b6-5ef4-47d8-8237-5e1133eebfc6' uuid: 3be271b6-5ef4-47d8-8237-5e1133eebfc6
version: '11.0' version: '11.0'

View File

@ -1,18 +1,19 @@
device: device:
manufacturer: 'p1' manufacturer: p1
serialNumber: 'p1' serialNumber: p1
model: 'p1' model: p1
type: 'Desktop' type: Desktop
chassis: Tower
components: components:
- manufacturer: 'p1c4m' - manufacturer: p1c4m
serialNumber: 'p1c4s' serialNumber: p1c4s
type: 'NetworkAdapter' type: NetworkAdapter
speed: 1000 speed: 1000
- manufacturer: 'p1c3m' - manufacturer: p1c3m
serialNumber: 'p1c3s' serialNumber: p1c3s
type: 'GraphicCard' type: GraphicCard
memory: 1.5 memory: 1.5
elapsed: 25 elapsed: 25
software: 'Workbench' software: Workbench
uuid: 'fd007eb4-48e3-454a-8763-169491904c6e' uuid: fd007eb4-48e3-454a-8763-169491904c6e
version: '11.0' version: '11.0'

View File

@ -1,25 +1,26 @@
type: 'Snapshot' type: Snapshot
uuid: 'f5efd26e-8754-46bc-87bf-fbccc39d60d9' uuid: f5efd26e-8754-46bc-87bf-fbccc39d60d9
version: '11.0' version: '11.0'
software: 'Workbench' software: Workbench
elapsed: 4 elapsed: 4
device: device:
type: 'Microtower' type: Computer
serialNumber: 'd1s' chassis: Microtower
model: 'd1ml' serialNumber: d1s
manufacturer: 'd1mr' model: d1ml
manufacturer: d1mr
events: events:
- type: 'WorkbenchRate' - type: WorkbenchRate
appearanceRange: 'A' appearanceRange: A
functionalityRange: 'B' functionalityRange: B
labelling: True labelling: True
bios: 'B' bios: B
components: components:
- type: 'GraphicCard' - type: GraphicCard
serialNumber: 'gc1s' serialNumber: gc1s
model: 'gc1ml' model: gc1ml
manufacturer: 'gc1mr' manufacturer: gc1mr
- type: 'RamModule' - type: RamModule
serialNumber: 'rm1s' serialNumber: rm1s
model: 'rm1ml' model: rm1ml
manufacturer: 'rm1mr' manufacturer: rm1mr

View File

@ -1,42 +1,43 @@
uuid: '74caa7eb-2bad-4333-94f6-6f1b031d0775' uuid: 74caa7eb-2bad-4333-94f6-6f1b031d0775
type: 'Snapshot' type: Snapshot
version: '11.0' version: '11.0'
software: 'Workbench' software: Workbench
elapsed: 4 elapsed: 4
device: device:
type: 'Microtower' type: Computer
serialNumber: 'pc1s' chassis: Microtower
model: 'pc1ml' serialNumber: pc1s
manufacturer: 'pc1mr' model: pc1ml
manufacturer: pc1mr
components: components:
- type: 'SolidStateDrive' - type: SolidStateDrive
serialNumber: 'c1s' serialNumber: c1s
model: 'c1ml' model: c1ml
manufacturer: 'c1mr' manufacturer: c1mr
events: events:
- type: 'EraseSectors' - type: EraseSectors
cleanWithZeros: True cleanWithZeros: True
startTime: '2018-06-01T08:12:06' startTime: 2018-06-01T08:12:06
endTime: '2018-06-01T09:12:06' endTime: 2018-06-01T09:12:06
secureRandomSteps: 20 secureRandomSteps: 20
steps: steps:
- type: 'StepZero' - type: StepZero
error: False error: False
startTime: '2018-06-01T08:15:00' startTime: 2018-06-01T08:15:00
endTime: '2018-06-01T09:16:00' endTime: 2018-06-01T09:16:00
secureRandomSteps: 1 secureRandomSteps: 1
cleanWithZeros: True cleanWithZeros: True
- type: 'StepZero' - type: StepZero
error: False error: False
startTime: '2018-06-01T08:16:00' startTime: 2018-06-01T08:16:00
endTime: '2018-06-01T09:17:00' endTime: 2018-06-01T09:17:00
secureRandomSteps: 1 secureRandomSteps: 1
cleanWithZeros: True cleanWithZeros: True
- type: 'GraphicCard' - type: GraphicCard
serialNumber: 'gc1s' serialNumber: gc1s
model: 'gc1ml' model: gc1ml
manufacturer: 'gc1mr' manufacturer: gc1mr
- type: 'RamModule' - type: RamModule
serialNumber: 'rm1s' serialNumber: rm1s
model: 'rm1ml' model: rm1ml
manufacturer: 'rm1mr' manufacturer: rm1mr

View File

@ -1,14 +1,15 @@
device: device:
type: 'Microtower' type: Desktop
serial_number: 'd1s' chassis: Microtower
model: 'd1ml' serial_number: d1s
manufacturer: 'd1mr' model: d1ml
manufacturer: d1mr
components: components:
- type: 'GraphicCard' - type: GraphicCard
serial_number: 'gc1s' serial_number: gc1s
model: 'gc1ml' model: gc1ml
manufacturer: 'gc1mr' manufacturer: gc1mr
- type: 'RamModule' - type: RamModule
serial_number: 'rm1s' serial_number: rm1s
model: 'rm1ml' model: rm1ml
manufacturer: 'rm1mr' manufacturer: rm1mr

View File

@ -1,66 +1,67 @@
# A Snapshot Phase 1 with a device # A Snapshot Phase 1 with a device
# and 1 GraphicCard, 2 RamModule, 1 Processor, 1 SSD, 1 HDD, 1 Motherboard # and 1 GraphicCard, 2 RamModule, 1 Processor, 1 SSD, 1 HDD, 1 Motherboard
# Prerequisites: # Prerequisites:
# - 2 tags: 'tag1' and 'tag2' from the default org # - 2 tags: tag1 and tag2 from the default org
# All numbers are invented # All numbers are invented
type: 'Snapshot' type: Snapshot
uuid: 'cb8ce6b5-6a1b-4084-b5b9-d8fadad2a015' uuid: cb8ce6b5-6a1b-4084-b5b9-d8fadad2a015
version: '11.0' version: '11.0'
software: 'Workbench' software: Workbench
expectedEvents: ['TestDataStorage', 'StressTest', 'EraseSectors', 'Install'] expectedEvents: [TestDataStorage, StressTest, EraseSectors, Install]
elapsed: 500 elapsed: 500
device: device:
type: 'Microtower' type: Desktop
serialNumber: 'd1s' chassis: Tower
model: 'd1ml' serialNumber: d1s
manufacturer: 'd1mr' model: d1ml
manufacturer: d1mr
tags: tags:
- type: 'Tag' - type: Tag
id: 'tag1' id: tag1
events: events:
- type: 'WorkbenchRate' - type: WorkbenchRate
appearanceRange: 'A' appearanceRange: A
functionalityRange: 'B' functionalityRange: B
- type: 'BenchmarkRamSysbench' - type: BenchmarkRamSysbench
rate: 2444 rate: 2444
components: components:
- type: 'GraphicCard' - type: GraphicCard
serialNumber: 'gc1-1s' serialNumber: gc1-1s
model: 'gc1-1ml' model: gc1-1ml
manufacturer: 'gc1-1mr' manufacturer: gc1-1mr
- type: 'RamModule' - type: RamModule
serialNumber: 'rm1-1s' serialNumber: rm1-1s
model: 'rm1-1ml' model: rm1-1ml
manufacturer: 'rm1-1mr' manufacturer: rm1-1mr
- type: 'RamModule' - type: RamModule
serialNumber: 'rm2-1s' serialNumber: rm2-1s
model: 'rm2-1ml' model: rm2-1ml
manufacturer: 'rm2-1mr' manufacturer: rm2-1mr
- type: 'Processor' - type: Processor
model: 'p1-1s' model: p1-1s
manufacturer: 'p1-1mr' manufacturer: p1-1mr
events: events:
- type: 'BenchmarkProcessor' - type: BenchmarkProcessor
rate: 2410 rate: 2410
- type: 'BenchmarkProcessorSysbench' - type: BenchmarkProcessorSysbench
rate: 4400 rate: 4400
- type: 'SolidStateDrive' - type: SolidStateDrive
serialNumber: 'ssd1-1s' serialNumber: ssd1-1s
model: 'ssd1-1ml' model: ssd1-1ml
manufacturer: 'ssd1-1mr' manufacturer: ssd1-1mr
events: events:
- type: 'BenchmarkDataStorage' - type: BenchmarkDataStorage
readSpeed: 20 readSpeed: 20
writeSpeed: 15 writeSpeed: 15
elapsed: 21 elapsed: 21
- type: 'TestDataStorage' - type: TestDataStorage
elapsed: 233 elapsed: 233
firstError: 0 firstError: 0
error: False error: False
status: 'Completed without error' status: Completed without error
length: 'Short' length: Short
lifetime: 99 lifetime: 99
passedLifetime: 99 passedLifetime: 99
assessment: True assessment: True
@ -72,15 +73,15 @@ components:
currentPendingSectorCount: 1 currentPendingSectorCount: 1
offlineUncorrectable: 33 offlineUncorrectable: 33
remainingLifetimePercentage: 1 remainingLifetimePercentage: 1
- type: 'HardDrive' - type: HardDrive
serialNumber: 'hdd1-1s' serialNumber: hdd1-1s
model: 'hdd1-1ml' model: hdd1-1ml
manufacturer: 'hdd1-1mr' manufacturer: hdd1-1mr
events: events:
- type: 'BenchmarkDataStorage' - type: BenchmarkDataStorage
readSpeed: 10 readSpeed: 10
writeSpeed: 5 writeSpeed: 5
- type: 'Motherboard' - type: Motherboard
serialNumber: 'mb1-1s' serialNumber: mb1-1s
model: 'mb1-1ml' model: mb1-1ml
manufacturer: 'mb1-1mr' manufacturer: mb1-1mr

View File

@ -35,4 +35,4 @@ def test_api_docs(client: Client):
'scheme': 'basic', 'scheme': 'basic',
'name': 'Authorization' 'name': 'Authorization'
} }
assert len(docs['definitions']) == 46 assert len(docs['definitions']) == 51

View File

@ -10,12 +10,12 @@ from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import Component, Computer, ComputerMonitor, Desktop, \ from ereuse_devicehub.resources.device.models import Component, ComputerMonitor, Desktop, Device, \
Device, GraphicCard, Laptop, Microtower, Motherboard, NetworkAdapter GraphicCard, Laptop, Motherboard, NetworkAdapter
from ereuse_devicehub.resources.device.schemas import Device as DeviceS from ereuse_devicehub.resources.device.schemas import Device as DeviceS
from ereuse_devicehub.resources.device.sync import MismatchBetweenTags, MismatchBetweenTagsAndHid, \ from ereuse_devicehub.resources.device.sync import MismatchBetweenTags, MismatchBetweenTagsAndHid, \
Sync Sync
from ereuse_devicehub.resources.enums import ComputerMonitorTechnologies from ereuse_devicehub.resources.enums import ComputerChassis, DisplayTech
from ereuse_devicehub.resources.event.models import Remove, Test from ereuse_devicehub.resources.event.models import Remove, Test
from ereuse_devicehub.resources.tag.model import Tag from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.resources.user import User from ereuse_devicehub.resources.user import User
@ -29,7 +29,10 @@ def test_device_model():
""" """
Tests that the correctness of the device model and its relationships. Tests that the correctness of the device model and its relationships.
""" """
pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s') pc = Desktop(model='p1mo',
manufacturer='p1ma',
serial_number='p1s',
chassis=ComputerChassis.Tower)
net = NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s') net = NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s')
graphic = GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500) graphic = GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
pc.components.add(net) pc.components.add(net)
@ -82,7 +85,7 @@ def test_physical_properties():
manufacturer='mr', manufacturer='mr',
width=2.0, width=2.0,
color=Color()) color=Color())
pc = Computer() pc = Desktop(chassis=ComputerChassis.Tower)
pc.components.add(c) pc.components.add(c)
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()
@ -108,7 +111,7 @@ def test_component_similar_one():
snapshot = file('pc-components.db') snapshot = file('pc-components.db')
d = snapshot['device'] d = snapshot['device']
snapshot['components'][0]['serial_number'] = snapshot['components'][1]['serial_number'] = None snapshot['components'][0]['serial_number'] = snapshot['components'][1]['serial_number'] = None
pc = Computer(**d, components=OrderedSet(Component(**c) for c in snapshot['components'])) pc = Desktop(**d, components=OrderedSet(Component(**c) for c in snapshot['components']))
component1, component2 = pc.components # type: Component component1, component2 = pc.components # type: Component
db.session.add(pc) db.session.add(pc)
db.session.flush() db.session.flush()
@ -134,10 +137,12 @@ def test_add_remove():
values = file('pc-components.db') values = file('pc-components.db')
pc = values['device'] pc = values['device']
c1, c2 = (Component(**c) for c in values['components']) c1, c2 = (Component(**c) for c in values['components'])
pc = Computer(**pc, components=OrderedSet([c1, c2])) pc = Desktop(**pc, components=OrderedSet([c1, c2]))
db.session.add(pc) db.session.add(pc)
c3 = Component(serial_number='nc1') c3 = Component(serial_number='nc1')
pc2 = Computer(serial_number='s2', components=OrderedSet([c3])) pc2 = Desktop(serial_number='s2',
components=OrderedSet([c3]),
chassis=ComputerChassis.Microtower)
c4 = Component(serial_number='c4s') c4 = Component(serial_number='c4s')
db.session.add(pc2) db.session.add(pc2)
db.session.add(c4) db.session.add(c4)
@ -161,12 +166,12 @@ def test_sync_run_components_empty():
remove all the components from the device. remove all the components from the device.
""" """
s = file('pc-components.db') s = file('pc-components.db')
pc = Computer(**s['device'], components=OrderedSet(Component(**c) for c in s['components'])) pc = Desktop(**s['device'], components=OrderedSet(Component(**c) for c in s['components']))
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()
# Create a new transient non-db synced object # Create a new transient non-db synced object
pc = Computer(**s['device']) pc = Desktop(**s['device'])
db_pc, _ = Sync().run(pc, components=OrderedSet()) db_pc, _ = Sync().run(pc, components=OrderedSet())
assert not db_pc.components assert not db_pc.components
assert not pc.components assert not pc.components
@ -179,52 +184,52 @@ def test_sync_run_components_none():
keep all the components from the device. keep all the components from the device.
""" """
s = file('pc-components.db') s = file('pc-components.db')
pc = Computer(**s['device'], components=OrderedSet(Component(**c) for c in s['components'])) pc = Desktop(**s['device'], components=OrderedSet(Component(**c) for c in s['components']))
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()
# Create a new transient non-db synced object # Create a new transient non-db synced object
transient_pc = Computer(**s['device']) transient_pc = Desktop(**s['device'])
db_pc, _ = Sync().run(transient_pc, components=None) db_pc, _ = Sync().run(transient_pc, components=None)
assert db_pc.components assert db_pc.components
assert db_pc.components == pc.components assert db_pc.components == pc.components
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_sync_execute_register_computer_new_computer_no_tag(): def test_sync_execute_register_Desktop_new_Desktop_no_tag():
""" """
Syncs a new computer with HID and without a tag, creating it. Syncs a new Desktop with HID and without a tag, creating it.
:return: :return:
""" """
# Case 1: device does not exist on DB # Case 1: device does not exist on DB
pc = Computer(**file('pc-components.db')['device']) pc = Desktop(**file('pc-components.db')['device'])
db_pc = Sync().execute_register(pc) db_pc = Sync().execute_register(pc)
assert pc.physical_properties == db_pc.physical_properties assert pc.physical_properties == db_pc.physical_properties
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_sync_execute_register_computer_existing_no_tag(): def test_sync_execute_register_Desktop_existing_no_tag():
""" """
Syncs an existing computer with HID and without a tag. Syncs an existing Desktop with HID and without a tag.
""" """
pc = Computer(**file('pc-components.db')['device']) pc = Desktop(**file('pc-components.db')['device'])
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()
pc = Computer(**file('pc-components.db')['device']) # Create a new transient non-db object pc = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object
# 1: device exists on DB # 1: device exists on DB
db_pc = Sync().execute_register(pc) db_pc = Sync().execute_register(pc)
assert pc.physical_properties == db_pc.physical_properties assert pc.physical_properties == db_pc.physical_properties
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_sync_execute_register_computer_no_hid_no_tag(): def test_sync_execute_register_Desktop_no_hid_no_tag():
""" """
Syncs a computer without HID and no tag. Syncs a Desktop without HID and no tag.
This should fail as we don't have a way to identify it. This should fail as we don't have a way to identify it.
""" """
pc = Computer(**file('pc-components.db')['device']) pc = Desktop(**file('pc-components.db')['device'])
# 1: device has no HID # 1: device has no HID
pc.hid = pc.model = None pc.hid = pc.model = None
with pytest.raises(NeedsId): with pytest.raises(NeedsId):
@ -232,9 +237,9 @@ def test_sync_execute_register_computer_no_hid_no_tag():
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_sync_execute_register_computer_tag_not_linked(): def test_sync_execute_register_Desktop_tag_not_linked():
""" """
Syncs a new computer with HID and a non-linked tag. Syncs a new Desktop with HID and a non-linked tag.
It is OK if the tag was not linked, it will be linked in this process. It is OK if the tag was not linked, it will be linked in this process.
""" """
@ -243,24 +248,24 @@ def test_sync_execute_register_computer_tag_not_linked():
db.session.commit() db.session.commit()
# Create a new transient non-db object # Create a new transient non-db object
pc = Computer(**file('pc-components.db')['device'], tags=OrderedSet([Tag(id='FOO')])) pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([Tag(id='FOO')]))
returned_pc = Sync().execute_register(pc) returned_pc = Sync().execute_register(pc)
assert returned_pc == pc assert returned_pc == pc
assert tag.device == pc, 'Tag has to be linked' assert tag.device == pc, 'Tag has to be linked'
assert Computer.query.one() == pc, 'Computer had to be set to db' assert Desktop.query.one() == pc, 'Desktop had to be set to db'
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str): def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
""" """
Validates registering a computer without HID and a non-linked tag. Validates registering a Desktop without HID and a non-linked tag.
In this case it is ok still, as the non-linked tag proves that In this case it is ok still, as the non-linked tag proves that
the computer was not existing before (otherwise the tag would the Desktop was not existing before (otherwise the tag would
be linked), and thus it creates a new computer. be linked), and thus it creates a new Desktop.
""" """
tag = Tag(id=tag_id) tag = Tag(id=tag_id)
pc = Computer(**file('pc-components.db')['device'], tags=OrderedSet([tag])) pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([tag]))
returned_pc = Sync().execute_register(pc) returned_pc = Sync().execute_register(pc)
db.session.commit() db.session.commit()
assert returned_pc == pc assert returned_pc == pc
@ -270,7 +275,7 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
# they have the same pk though # they have the same pk though
assert tag != db_tag, 'They are not the same tags though' assert tag != db_tag, 'They are not the same tags though'
assert db_tag.id == tag.id assert db_tag.id == tag.id
assert Computer.query.one() == pc, 'Computer had to be set to db' assert Desktop.query.one() == pc, 'Desktop had to be set to db'
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
@ -281,7 +286,7 @@ def test_sync_execute_register_tag_does_not_exist():
Tags have to be created before trying to link them through a Snapshot. Tags have to be created before trying to link them through a Snapshot.
""" """
pc = Computer(**file('pc-components.db')['device'], tags=OrderedSet([Tag()])) pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([Tag()]))
with raises(ResourceNotFound): with raises(ResourceNotFound):
Sync().execute_register(pc) Sync().execute_register(pc)
@ -294,11 +299,11 @@ def test_sync_execute_register_tag_linked_same_device():
(If it has HID it validates both HID and tag point at the same (If it has HID it validates both HID and tag point at the same
device, this his checked in ). device, this his checked in ).
""" """
orig_pc = Computer(**file('pc-components.db')['device']) orig_pc = Desktop(**file('pc-components.db')['device'])
db.session.add(Tag(id='foo', device=orig_pc)) db.session.add(Tag(id='foo', device=orig_pc))
db.session.commit() db.session.commit()
pc = Computer(**file('pc-components.db')['device']) # Create a new transient non-db object pc = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object
pc.tags.add(Tag(id='foo')) pc.tags.add(Tag(id='foo'))
db_pc = Sync().execute_register(pc) db_pc = Sync().execute_register(pc)
assert db_pc.id == orig_pc.id assert db_pc.id == orig_pc.id
@ -312,15 +317,15 @@ def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags():
Checks that sync raises an error if finds that at least two passed-in Checks that sync raises an error if finds that at least two passed-in
tags are not linked to the same device. tags are not linked to the same device.
""" """
pc1 = Computer(**file('pc-components.db')['device']) pc1 = Desktop(**file('pc-components.db')['device'])
db.session.add(Tag(id='foo-1', device=pc1)) db.session.add(Tag(id='foo-1', device=pc1))
pc2 = Computer(**file('pc-components.db')['device']) pc2 = Desktop(**file('pc-components.db')['device'])
pc2.serial_number = 'pc2-serial' pc2.serial_number = 'pc2-serial'
pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model) pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
db.session.add(Tag(id='foo-2', device=pc2)) db.session.add(Tag(id='foo-2', device=pc2))
db.session.commit() db.session.commit()
pc1 = Computer(**file('pc-components.db')['device']) # Create a new transient non-db object pc1 = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object
pc1.tags.add(Tag(id='foo-1')) pc1.tags.add(Tag(id='foo-1'))
pc1.tags.add(Tag(id='foo-2')) pc1.tags.add(Tag(id='foo-2'))
with raises(MismatchBetweenTags): with raises(MismatchBetweenTags):
@ -335,15 +340,15 @@ def test_sync_execute_register_mismatch_between_tags_and_hid():
In this case we set HID -> pc1 but tag -> pc2 In this case we set HID -> pc1 but tag -> pc2
""" """
pc1 = Computer(**file('pc-components.db')['device']) pc1 = Desktop(**file('pc-components.db')['device'])
db.session.add(Tag(id='foo-1', device=pc1)) db.session.add(Tag(id='foo-1', device=pc1))
pc2 = Computer(**file('pc-components.db')['device']) pc2 = Desktop(**file('pc-components.db')['device'])
pc2.serial_number = 'pc2-serial' pc2.serial_number = 'pc2-serial'
pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model) pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
db.session.add(Tag(id='foo-2', device=pc2)) db.session.add(Tag(id='foo-2', device=pc2))
db.session.commit() db.session.commit()
pc1 = Computer(**file('pc-components.db')['device']) # Create a new transient non-db object pc1 = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object
pc1.tags.add(Tag(id='foo-2')) pc1.tags.add(Tag(id='foo-2'))
with raises(MismatchBetweenTagsAndHid): with raises(MismatchBetweenTagsAndHid):
Sync().execute_register(pc1) Sync().execute_register(pc1)
@ -352,7 +357,10 @@ def test_sync_execute_register_mismatch_between_tags_and_hid():
def test_get_device(app: Devicehub, user: UserClient): def test_get_device(app: Devicehub, user: UserClient):
"""Checks GETting a Desktop with its components.""" """Checks GETting a Desktop with its components."""
with app.app_context(): with app.app_context():
pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s') pc = Desktop(model='p1mo',
manufacturer='p1ma',
serial_number='p1s',
chassis=ComputerChassis.Tower)
pc.components = OrderedSet([ pc.components = OrderedSet([
NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'), NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500) GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
@ -384,24 +392,33 @@ def test_get_device(app: Devicehub, user: UserClient):
def test_get_devices(app: Devicehub, user: UserClient): def test_get_devices(app: Devicehub, user: UserClient):
"""Checks GETting multiple devices.""" """Checks GETting multiple devices."""
with app.app_context(): with app.app_context():
pc = Desktop(model='p1mo', manufacturer='p1ma', serial_number='p1s') pc = Desktop(model='p1mo',
manufacturer='p1ma',
serial_number='p1s',
chassis=ComputerChassis.Tower)
pc.components = OrderedSet([ pc.components = OrderedSet([
NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'), NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500) GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
]) ])
pc1 = Microtower(model='p2mo', manufacturer='p2ma', serial_number='p2s') pc1 = Desktop(model='p2mo',
pc2 = Laptop(model='p3mo', manufacturer='p3ma', serial_number='p3s') manufacturer='p2ma',
serial_number='p2s',
chassis=ComputerChassis.Tower)
pc2 = Laptop(model='p3mo',
manufacturer='p3ma',
serial_number='p3s',
chassis=ComputerChassis.Netbook)
db.session.add_all((pc, pc1, pc2)) db.session.add_all((pc, pc1, pc2))
db.session.commit() db.session.commit()
devices, _ = user.get(res=Device) devices, _ = user.get(res=Device)
assert tuple(d['id'] for d in devices) == (1, 2, 3, 4, 5) assert tuple(d['id'] for d in devices) == (1, 2, 3, 4, 5)
assert tuple(d['type'] for d in devices) == ('Desktop', 'Microtower', assert tuple(d['type'] for d in devices) == ('Desktop', 'Desktop', 'Laptop',
'Laptop', 'NetworkAdapter', 'GraphicCard') 'NetworkAdapter', 'GraphicCard')
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
def test_computer_monitor(): def test_computer_monitor():
m = ComputerMonitor(technology=ComputerMonitorTechnologies.LCD, m = ComputerMonitor(technology=DisplayTech.LCD,
manufacturer='foo', manufacturer='foo',
model='bar', model='bar',
serial_number='foo-bar', serial_number='foo-bar',
@ -410,3 +427,18 @@ def test_computer_monitor():
size=14.5) size=14.5)
db.session.add(m) db.session.add(m)
db.session.commit() db.session.commit()
@pytest.mark.xfail(reason='Make test')
def test_mobile_meid():
pass
@pytest.mark.xfail(reason='Make test')
def test_mobile_imei():
pass
@pytest.mark.xfail(reason='Make test')
def test_computer_with_display():
pass

View File

@ -5,7 +5,7 @@ from flask import g
from sqlalchemy.util import OrderedSet from sqlalchemy.util import OrderedSet
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.models import Device, GraphicCard, HardDrive, Microtower, \ from ereuse_devicehub.resources.device.models import Computer, Device, GraphicCard, HardDrive, \
RamModule, SolidStateDrive RamModule, SolidStateDrive
from ereuse_devicehub.resources.enums import TestHardDriveLength from ereuse_devicehub.resources.enums import TestHardDriveLength
from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, EraseBasic, EraseSectors, \ from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, EraseBasic, EraseSectors, \
@ -130,7 +130,7 @@ def test_install():
@pytest.mark.usefixtures('auth_app_context') @pytest.mark.usefixtures('auth_app_context')
def test_update_components_event_one(): def test_update_components_event_one():
computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1') computer = Computer(serial_number='sn1', model='ml1', manufacturer='mr1')
hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar') hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
computer.components.add(hdd) computer.components.add(hdd)
@ -155,7 +155,7 @@ def test_update_components_event_one():
@pytest.mark.usefixtures('auth_app_context') @pytest.mark.usefixtures('auth_app_context')
def test_update_components_event_multiple(): def test_update_components_event_multiple():
computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1') computer = Computer(serial_number='sn1', model='ml1', manufacturer='mr1')
hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar') hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
computer.components.add(hdd) computer.components.add(hdd)
@ -181,7 +181,7 @@ def test_update_components_event_multiple():
@pytest.mark.usefixtures('auth_app_context') @pytest.mark.usefixtures('auth_app_context')
def test_update_parent(): def test_update_parent():
computer = Microtower(serial_number='sn1', model='ml1', manufacturer='mr1') computer = Computer(serial_number='sn1', model='ml1', manufacturer='mr1')
hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar') hdd = HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar')
computer.components.add(hdd) computer.components.add(hdd)

View File

@ -3,8 +3,8 @@ import pytest
from ereuse_devicehub.client import UserClient from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, Microtower, \ from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, SolidStateDrive
SolidStateDrive from ereuse_devicehub.resources.enums import ComputerChassis
from ereuse_devicehub.resources.inventory import Filters, Inventory, Sorting from ereuse_devicehub.resources.inventory import Filters, Inventory, Sorting
from teal.utils import compiled from teal.utils import compiled
@ -25,8 +25,8 @@ def test_inventory_filters():
}) })
s, params = compiled(Device, q) s, params = compiled(Device, q)
# Order between query clauses can change # Order between query clauses can change
assert '(device.type IN (%(type_1)s, %(type_2)s, %(type_3)s, %(type_4)s, ' \ assert '(device.type IN (%(type_1)s, %(type_2)s, %(type_3)s, %(type_4)s) ' \
'%(type_5)s, %(type_6)s) OR device.type IN (%(type_7)s))' in s 'OR device.type IN (%(type_5)s))' in s
assert 'device.manufacturer ILIKE %(manufacturer_1)s' in s assert 'device.manufacturer ILIKE %(manufacturer_1)s' in s
assert 'rate.rating BETWEEN %(rating_1)s AND %(rating_2)s' in s assert 'rate.rating BETWEEN %(rating_1)s AND %(rating_2)s' in s
assert 'rate.appearance BETWEEN %(appearance_1)s AND %(appearance_2)s' in s assert 'rate.appearance BETWEEN %(appearance_1)s AND %(appearance_2)s' in s
@ -34,38 +34,11 @@ def test_inventory_filters():
# type_x can be assigned at different values # type_x can be assigned at different values
# ex: type_1 can be 'Desktop' in one execution but the next one 'Laptop' # ex: type_1 can be 'Desktop' in one execution but the next one 'Laptop'
assert set(params.keys()) == { assert set(params.keys()) == {'id_2', 'appearance_1', 'type_1', 'type_4', 'rating_2', 'type_5',
'id_1', 'type_3', 'type_2', 'appearance_2', 'id_1', 'rating_1',
'manufacturer_1', 'manufacturer_1'}
'type_4', assert set(params.values()) == {2.0, 'Laptop', 4.0, 3.0, 6.0, 'Desktop', 'activa-02%',
'type_3', 'Server', 'Dell%', 'Computer', 'bcn-%'}
'id_2',
'type_1',
'rating_1',
'type_5',
'appearance_2',
'type_6',
'type_7',
'appearance_1',
'rating_2',
'type_2'
}
assert set(params.values()) == {
'bcn-%',
'Dell%',
'Laptop',
'Server',
'activa-02%',
'Computer',
3.0,
'Microtower',
4.0,
'Netbook',
'Laptop',
2.0,
6.0,
'Desktop'
}
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
@ -79,9 +52,18 @@ def test_inventory_sort():
def inventory_query_dummy(app: Devicehub): def inventory_query_dummy(app: Devicehub):
with app.app_context(): with app.app_context():
db.session.add_all(( # The order matters ;-) db.session.add_all(( # The order matters ;-)
Desktop(serial_number='s1', model='ml1', manufacturer='mr1'), Desktop(serial_number='s1',
Laptop(serial_number='s3', model='ml3', manufacturer='mr3'), model='ml1',
Microtower(serial_number='s2', model='ml2', manufacturer='mr2'), manufacturer='mr1',
chassis=ComputerChassis.Tower),
Laptop(serial_number='s3',
model='ml3',
manufacturer='mr3',
chassis=ComputerChassis.Detachable),
Desktop(serial_number='s2',
model='ml2',
manufacturer='mr2',
chassis=ComputerChassis.Microtower),
SolidStateDrive(serial_number='s4', model='ml4', manufacturer='mr4') SolidStateDrive(serial_number='s4', model='ml4', manufacturer='mr4')
)) ))
db.session.commit() db.session.commit()
@ -91,14 +73,14 @@ def inventory_query_dummy(app: Devicehub):
def test_inventory_query_no_filters(user: UserClient): def test_inventory_query_no_filters(user: UserClient):
i, _ = user.get(res=Inventory) i, _ = user.get(res=Inventory)
assert tuple(d['type'] for d in i['devices']) == ( assert tuple(d['type'] for d in i['devices']) == (
'SolidStateDrive', 'Microtower', 'Laptop', 'Desktop' 'SolidStateDrive', 'Desktop', 'Laptop', 'Desktop'
) )
@pytest.mark.usefixtures('inventory_query_dummy') @pytest.mark.usefixtures('inventory_query_dummy')
def test_inventory_query_filter_type(user: UserClient): def test_inventory_query_filter_type(user: UserClient):
i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Computer', 'Microtower']})]) i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Desktop', 'Laptop']})])
assert tuple(d['type'] for d in i['devices']) == ('Microtower', 'Laptop', 'Desktop') assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop')
@pytest.mark.usefixtures('inventory_query_dummy') @pytest.mark.usefixtures('inventory_query_dummy')
@ -107,4 +89,4 @@ def test_inventory_query_filter_sort(user: UserClient):
('sort', {'created': Sorting.ASCENDING}), ('sort', {'created': Sorting.ASCENDING}),
('filter', {'type': ['Computer']}) ('filter', {'type': ['Computer']})
]) ])
assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Microtower') assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop')

View File

@ -3,8 +3,9 @@ from distutils.version import StrictVersion
import pytest import pytest
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.resources.device.models import Microtower from ereuse_devicehub.resources.device.models import Computer
from ereuse_devicehub.resources.enums import Bios, ImageMimeTypes, Orientation, RatingSoftware from ereuse_devicehub.resources.enums import Bios, ComputerChassis, ImageMimeTypes, Orientation, \
RatingSoftware
from ereuse_devicehub.resources.event.models import PhotoboxRate, WorkbenchRate from ereuse_devicehub.resources.event.models import PhotoboxRate, WorkbenchRate
from ereuse_devicehub.resources.image.models import Image, ImageList from ereuse_devicehub.resources.image.models import Image, ImageList
@ -19,14 +20,14 @@ def test_workbench_rate():
data_storage=4.1, data_storage=4.1,
algorithm_software=RatingSoftware.Ereuse, algorithm_software=RatingSoftware.Ereuse,
algorithm_version=StrictVersion('1.0'), algorithm_version=StrictVersion('1.0'),
device=Microtower(serial_number='24')) device=Computer(serial_number='24', chassis=ComputerChassis.Tower))
db.session.add(rate) db.session.add(rate)
db.session.commit() db.session.commit()
@pytest.mark.usefixtures('auth_app_context') @pytest.mark.usefixtures('auth_app_context')
def test_photobox_rate(): def test_photobox_rate():
pc = Microtower(serial_number='24') pc = Computer(serial_number='24', chassis=ComputerChassis.Tower)
image = Image(name='foo', image = Image(name='foo',
content=b'123', content=b'123',
file_format=ImageMimeTypes.jpg, file_format=ImageMimeTypes.jpg,

View File

@ -9,10 +9,11 @@ from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device.exceptions import NeedsId from ereuse_devicehub.resources.device.exceptions import NeedsId
from ereuse_devicehub.resources.device.models import Device, Microtower, SolidStateDrive from ereuse_devicehub.resources.device.models import Computer, Device
from ereuse_devicehub.resources.device.sync import MismatchBetweenTagsAndHid from ereuse_devicehub.resources.device.sync import MismatchBetweenTagsAndHid
from ereuse_devicehub.resources.enums import Bios, RatingSoftware, SnapshotSoftware from ereuse_devicehub.resources.enums import Bios, RatingSoftware, SnapshotSoftware, \
from ereuse_devicehub.resources.event.models import EraseBasic, Event, Snapshot, SnapshotRequest, \ ComputerChassis
from ereuse_devicehub.resources.event.models import Event, Snapshot, SnapshotRequest, \
WorkbenchRate WorkbenchRate
from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.tag import Tag
from ereuse_devicehub.resources.user.models import User from ereuse_devicehub.resources.user.models import User
@ -87,7 +88,7 @@ def test_snapshot_model():
Tests creating a Snapshot with its relationships ensuring correct Tests creating a Snapshot with its relationships ensuring correct
DB mapping. DB mapping.
""" """
device = Microtower(serial_number='a1') device = Computer(serial_number='a1', chassis=ComputerChassis.Tower)
# noinspection PyArgumentList # noinspection PyArgumentList
snapshot = Snapshot(uuid=uuid4(), snapshot = Snapshot(uuid=uuid4(),
date=datetime.now(), date=datetime.now(),
@ -107,7 +108,7 @@ def test_snapshot_model():
device=device)) device=device))
db.session.add(snapshot) db.session.add(snapshot)
db.session.commit() db.session.commit()
device = Microtower.query.one() # type: Microtower device = Computer.query.one() # type: Computer
e1, e2 = device.events e1, e2 = device.events
assert isinstance(e1, Snapshot), 'Creation order must be preserved: 1. snapshot, 2. WR' assert isinstance(e1, Snapshot), 'Creation order must be preserved: 1. snapshot, 2. WR'
assert isinstance(e2, WorkbenchRate) assert isinstance(e2, WorkbenchRate)
@ -116,7 +117,7 @@ def test_snapshot_model():
assert Snapshot.query.one_or_none() is None assert Snapshot.query.one_or_none() is None
assert SnapshotRequest.query.one_or_none() is None assert SnapshotRequest.query.one_or_none() is None
assert User.query.one() is not None assert User.query.one() is not None
assert Microtower.query.one_or_none() is None assert Computer.query.one_or_none() is None
assert Device.query.one_or_none() is None assert Device.query.one_or_none() is None

View File

@ -6,6 +6,7 @@ from ereuse_devicehub.client import UserClient
from ereuse_devicehub.db import db from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device.models import Computer from ereuse_devicehub.resources.device.models import Computer
from ereuse_devicehub.resources.enums import ComputerChassis
from ereuse_devicehub.resources.tag import Tag from ereuse_devicehub.resources.tag import Tag
from ereuse_devicehub.resources.tag.view import CannotCreateETag, TagNotLinked from ereuse_devicehub.resources.tag.view import CannotCreateETag, TagNotLinked
from ereuse_devicehub.resources.user import Organization from ereuse_devicehub.resources.user import Organization
@ -86,7 +87,7 @@ def test_tag_get_device_from_tag_endpoint(app: Devicehub, user: UserClient):
with app.app_context(): with app.app_context():
# Create a pc with a tag # Create a pc with a tag
tag = Tag(id='foo-bar') tag = Tag(id='foo-bar')
pc = Computer(serial_number='sn1') pc = Computer(serial_number='sn1', chassis=ComputerChassis.Tower)
pc.tags.add(tag) pc.tags.add(tag)
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()