Update device structure
This commit is contained in:
parent
fd936fd0e3
commit
b0b455d4f0
|
@ -1,10 +1,11 @@
|
|||
from distutils.version import StrictVersion
|
||||
from typing import Set
|
||||
|
||||
from ereuse_devicehub.resources.device import ComponentDef, ComputerDef, ComputerMonitorDef, \
|
||||
DataStorageDef, DesktopDef, DeviceDef, GraphicCardDef, HardDriveDef, LaptopDef, MicrotowerDef, \
|
||||
MotherboardDef, NetbookDef, NetworkAdapterDef, ProcessorDef, RamModuleDef, ServerDef, \
|
||||
SolidStateDriveDef
|
||||
from ereuse_devicehub.resources.device import CellphoneDef, ComponentDef, ComputerDef, \
|
||||
ComputerMonitorDef, DataStorageDef, DesktopDef, DeviceDef, DisplayDef, GraphicCardDef, \
|
||||
HardDriveDef, LaptopDef, MobileDef, MonitorDef, MotherboardDef, NetworkAdapterDef, \
|
||||
ProcessorDef, RamModuleDef, ServerDef, SmartphoneDef, SolidStateDriveDef, TabletDef, \
|
||||
TelevisionSetDef
|
||||
from ereuse_devicehub.resources.event import AddDef, AggregateRateDef, AppRateDef, \
|
||||
BenchmarkDataStorageDef, BenchmarkDef, BenchmarkProcessorDef, BenchmarkProcessorSysbenchDef, \
|
||||
BenchmarkRamSysbenchDef, BenchmarkWithRateDef, EraseBasicDef, EraseSectorsDef, EventDef, \
|
||||
|
@ -19,9 +20,9 @@ from teal.config import Config
|
|||
|
||||
class DevicehubConfig(Config):
|
||||
RESOURCE_DEFINITIONS = {
|
||||
DeviceDef, ComputerDef, DesktopDef, LaptopDef, NetbookDef, ServerDef,
|
||||
MicrotowerDef, ComputerMonitorDef, ComponentDef, GraphicCardDef, DataStorageDef,
|
||||
SolidStateDriveDef,
|
||||
DeviceDef, ComputerDef, DesktopDef, LaptopDef, ServerDef, MonitorDef, TelevisionSetDef,
|
||||
ComputerMonitorDef, ComponentDef, GraphicCardDef, DataStorageDef,
|
||||
SolidStateDriveDef, MobileDef, DisplayDef, SmartphoneDef, TabletDef, CellphoneDef,
|
||||
HardDriveDef, MotherboardDef, NetworkAdapterDef, RamModuleDef, ProcessorDef, UserDef,
|
||||
OrganizationDef, TagDef, EventDef, AddDef, RemoveDef, EraseBasicDef, EraseSectorsDef,
|
||||
StepDef, StepZeroDef, StepRandomDef, RateDef, AggregateRateDef, WorkbenchRateDef,
|
||||
|
|
|
@ -11,7 +11,8 @@ version: '11.0'
|
|||
software: Workbench
|
||||
elapsed: 500
|
||||
device:
|
||||
type: Microtower
|
||||
type: Desktop
|
||||
chassis: Tower
|
||||
serialNumber: d1s
|
||||
model: d1ml
|
||||
manufacturer: d1mr
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
from ereuse_devicehub.resources.device.schemas import Component, Computer, ComputerMonitor, \
|
||||
DataStorage, Desktop, Device, GraphicCard, HardDrive, Laptop, Microtower, Motherboard, Netbook, \
|
||||
NetworkAdapter, Processor, RamModule, Server, SolidStateDrive
|
||||
from ereuse_devicehub.resources.device.schemas import Cellphone, Component, Computer, \
|
||||
ComputerMonitor, DataStorage, Desktop, Device, Display, GraphicCard, HardDrive, Laptop, Mobile, \
|
||||
Monitor, Motherboard, NetworkAdapter, Processor, RamModule, Server, Smartphone, \
|
||||
SolidStateDrive, Tablet, TelevisionSet
|
||||
from ereuse_devicehub.resources.device.views import DeviceView
|
||||
from teal.resource import Converters, Resource
|
||||
|
||||
|
@ -27,26 +28,46 @@ class LaptopDef(ComputerDef):
|
|||
SCHEMA = Laptop
|
||||
|
||||
|
||||
class NetbookDef(ComputerDef):
|
||||
VIEW = None
|
||||
SCHEMA = Netbook
|
||||
|
||||
|
||||
class ServerDef(ComputerDef):
|
||||
VIEW = None
|
||||
SCHEMA = Server
|
||||
|
||||
|
||||
class MicrotowerDef(ComputerDef):
|
||||
class MonitorDef(DeviceDef):
|
||||
VIEW = None
|
||||
SCHEMA = Microtower
|
||||
SCHEMA = Monitor
|
||||
|
||||
|
||||
class ComputerMonitorDef(DeviceDef):
|
||||
class ComputerMonitorDef(MonitorDef):
|
||||
VIEW = None
|
||||
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):
|
||||
VIEW = None
|
||||
SCHEMA = Component
|
||||
|
@ -90,3 +111,8 @@ class RamModuleDef(ComponentDef):
|
|||
class ProcessorDef(ComponentDef):
|
||||
VIEW = None
|
||||
SCHEMA = Processor
|
||||
|
||||
|
||||
class DisplayDef(ComponentDef):
|
||||
VIEW = None
|
||||
SCHEMA = Display
|
||||
|
|
|
@ -141,7 +141,7 @@ class ComputerMonitor(Device):
|
|||
size.comment = """
|
||||
The size of the monitor in inches.
|
||||
"""
|
||||
technology = Column(DBEnum(ComputerMonitorTechnologies))
|
||||
technology = Column(DBEnum(DisplayTech))
|
||||
technology.comment = """
|
||||
The technology the monitor uses to display the image.
|
||||
"""
|
||||
|
@ -224,8 +224,15 @@ class Motherboard(JoinedComponentTableMixin, Component):
|
|||
pcmcia = Column(SmallInteger, check_range('pcmcia'))
|
||||
|
||||
|
||||
class NetworkAdapter(JoinedComponentTableMixin, Component):
|
||||
class NetworkMixin:
|
||||
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):
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Dict, List, Set
|
|||
from colour import Color
|
||||
from sqlalchemy import Column, Integer
|
||||
|
||||
from ereuse_devicehub.resources.enums import ComputerMonitorTechnologies, DataStorageInterface, \
|
||||
from ereuse_devicehub.resources.enums import ComputerChassis, DataStorageInterface, DisplayTech, \
|
||||
RamFormat, RamInterface
|
||||
from ereuse_devicehub.resources.event.models import Event, EventWithMultipleDevices, \
|
||||
EventWithOneDevice
|
||||
|
@ -46,17 +46,40 @@ class Device(Thing):
|
|||
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:
|
||||
super().__init__(**kwargs)
|
||||
self.components = ... # type: Set[Component]
|
||||
self.events_parent = ... # type: Set[Event]
|
||||
|
||||
|
||||
class Desktop(Computer):
|
||||
pass
|
||||
|
||||
|
||||
class ComputerMonitor(Monitor):
|
||||
pass
|
||||
|
||||
|
||||
class TelevisionSet(Monitor):
|
||||
pass
|
||||
|
||||
class Laptop(Computer):
|
||||
pass
|
||||
|
||||
|
|
|
@ -2,18 +2,20 @@ from marshmallow import post_load, pre_load
|
|||
from marshmallow.fields import Float, Integer, Str
|
||||
from marshmallow.validate import Length, OneOf, Range
|
||||
from sqlalchemy.util import OrderedSet
|
||||
from stdnum import imei, meid
|
||||
|
||||
from ereuse_devicehub.marshmallow import NestedOn
|
||||
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.schemas import Thing, UnitCodes
|
||||
from teal.marshmallow import EnumField, ValidationError
|
||||
|
||||
|
||||
class Device(Thing):
|
||||
id = Integer(description=m.Device.id.comment.strip(), dump_only=True)
|
||||
hid = Str(dump_only=True, description=m.Device.hid.comment.strip())
|
||||
id = Integer(description=m.Device.id.comment, dump_only=True)
|
||||
hid = Str(dump_only=True, description=m.Device.hid.comment)
|
||||
tags = NestedOn('Tag',
|
||||
many=True,
|
||||
collection_class=OrderedSet,
|
||||
|
@ -21,15 +23,9 @@ class Device(Thing):
|
|||
model = Str(validate=Length(max=STR_BIG_SIZE))
|
||||
manufacturer = Str(validate=Length(max=STR_SIZE))
|
||||
serial_number = Str(data_key='serialNumber')
|
||||
weight = Float(validate=Range(0.1, 3),
|
||||
unit=UnitCodes.kgm,
|
||||
description=m.Device.weight.comment.strip())
|
||||
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())
|
||||
weight = Float(validate=Range(0.1, 3), unit=UnitCodes.kgm, description=m.Device.weight.comment)
|
||||
width = Float(validate=Range(0.1, 3), unit=UnitCodes.m, description=m.Device.width.comment)
|
||||
height = Float(validate=Range(0.1, 3), unit=UnitCodes.m, description=m.Device.height.comment)
|
||||
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)
|
||||
|
||||
|
@ -60,6 +56,7 @@ class Device(Thing):
|
|||
|
||||
class Computer(Device):
|
||||
components = NestedOn('Component', many=True, dump_only=True, collection_class=OrderedSet)
|
||||
chassis = EnumField(ComputerChassis, required=True)
|
||||
|
||||
|
||||
class Desktop(Computer):
|
||||
|
@ -70,28 +67,61 @@ class Laptop(Computer):
|
|||
pass
|
||||
|
||||
|
||||
class Netbook(Computer):
|
||||
pass
|
||||
|
||||
|
||||
class Server(Computer):
|
||||
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
|
||||
|
||||
|
||||
class ComputerMonitor(Device):
|
||||
size = Float(description=m.ComputerMonitor.size.comment.strip(), validate=Range(2, 150))
|
||||
technology = EnumField(ComputerMonitorTechnologies,
|
||||
description=m.ComputerMonitor.technology.comment.strip())
|
||||
resolution_width = Integer(data_key='resolutionWidth',
|
||||
validate=Range(10, 20000),
|
||||
description=m.ComputerMonitor.resolution_width.comment.strip())
|
||||
resolution_height = Integer(data_key='resolutionHeight',
|
||||
validate=Range(10, 20000),
|
||||
description=m.ComputerMonitor.resolution_height.comment.strip())
|
||||
class ComputerMonitor(Monitor):
|
||||
pass
|
||||
|
||||
|
||||
class TelevisionSet(Monitor):
|
||||
pass
|
||||
|
||||
|
||||
class Mobile(Device):
|
||||
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):
|
||||
|
@ -101,13 +131,13 @@ class Component(Device):
|
|||
class GraphicCard(Component):
|
||||
memory = Integer(validate=Range(0, 10000),
|
||||
unit=UnitCodes.mbyte,
|
||||
description='The amount of memory of the Graphic Card in MB.')
|
||||
description=m.GraphicCard.memory.comment)
|
||||
|
||||
|
||||
class DataStorage(Component):
|
||||
size = Integer(validate=Range(0, 10 ** 8),
|
||||
unit=UnitCodes.mbyte,
|
||||
description='The size of the hard-drive in MB.')
|
||||
description=m.DataStorage.size.comment)
|
||||
|
||||
|
||||
class HardDrive(DataStorage):
|
||||
|
@ -119,7 +149,8 @@ class SolidStateDrive(DataStorage):
|
|||
|
||||
|
||||
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))
|
||||
firewire = Integer(validate=Range(0, 20))
|
||||
serial = Integer(validate=Range(0, 20))
|
||||
|
|
|
@ -152,7 +152,7 @@ class DataStorageInterface(Enum):
|
|||
|
||||
|
||||
@unique
|
||||
class ComputerMonitorTechnologies(Enum):
|
||||
class DisplayTech(Enum):
|
||||
CRT = 'Cathode ray tube (CRT)'
|
||||
TFT = 'Thin-film-transistor liquid-crystal (TFT)'
|
||||
LED = 'LED-backlit (LED)'
|
||||
|
|
|
@ -31,6 +31,7 @@ class Event(Thing):
|
|||
components = ... # type: relationship
|
||||
parent_id = ... # type: Column
|
||||
parent = ... # type: relationship
|
||||
closed = ... # type: Column
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
@ -64,6 +65,14 @@ class EventWithMultipleDevices(Event):
|
|||
self.devices = ... # type: Set[Device]
|
||||
|
||||
|
||||
class Add(EventWithOneDevice):
|
||||
pass
|
||||
|
||||
|
||||
class Remove(EventWithOneDevice):
|
||||
pass
|
||||
|
||||
|
||||
class Step(Model):
|
||||
def __init__(self, **kwargs) -> None:
|
||||
self.erasure_id = ... # type: UUID
|
||||
|
|
|
@ -18,17 +18,15 @@ from teal.resource import Schema
|
|||
|
||||
class Event(Thing):
|
||||
id = UUID(dump_only=True)
|
||||
name = String(default='',
|
||||
validate=Length(STR_BIG_SIZE),
|
||||
description=m.Event.name.comment.strip())
|
||||
date = DateTime('iso', description=m.Event.date.comment.strip())
|
||||
error = Boolean(default=False, description=m.Event.error.comment.strip())
|
||||
incidence = Boolean(default=False, description=m.Event.incidence.comment.strip())
|
||||
name = String(default='', validate=Length(STR_BIG_SIZE), description=m.Event.name.comment)
|
||||
date = DateTime('iso', description=m.Event.date.comment)
|
||||
error = Boolean(default=False, description=m.Event.error.comment)
|
||||
incidence = Boolean(default=False, description=m.Event.incidence.comment)
|
||||
snapshot = NestedOn('Snapshot', dump_only=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',))
|
||||
closed = Boolean(missing=True, description=m.Event.closed.comment.strip())
|
||||
closed = Boolean(missing=True, description=m.Event.closed.comment)
|
||||
|
||||
|
||||
class EventWithOneDevice(Event):
|
||||
|
|
|
@ -1,23 +1,24 @@
|
|||
device:
|
||||
manufacturer: 'p1'
|
||||
serialNumber: 'p1'
|
||||
model: 'p1'
|
||||
type: 'Desktop'
|
||||
manufacturer: p1
|
||||
serialNumber: p1
|
||||
model: p1
|
||||
type: Desktop
|
||||
chassis: Tower
|
||||
components:
|
||||
- manufacturer: 'p1c1m'
|
||||
serialNumber: 'p1c1s'
|
||||
type: 'Motherboard'
|
||||
- manufacturer: 'p1c2m'
|
||||
serialNumber: 'p1c2s'
|
||||
model: 'p1c2'
|
||||
- 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'
|
||||
type: Processor
|
||||
- manufacturer: p1c3m
|
||||
serialNumber: p1c3s
|
||||
type: GraphicCard
|
||||
memory: 1.5
|
||||
elapsed: 25
|
||||
software: 'Workbench'
|
||||
uuid: '76860eca-c3fd-41f6-a801-6af7bd8cf832'
|
||||
software: Workbench
|
||||
uuid: 76860eca-c3fd-41f6-a801-6af7bd8cf832
|
||||
version: '11.0'
|
|
@ -1,19 +1,20 @@
|
|||
device:
|
||||
manufacturer: 'p2m'
|
||||
serialNumber: 'p2s'
|
||||
model: 'p2'
|
||||
type: 'Microtower'
|
||||
manufacturer: p2m
|
||||
serialNumber: p2s
|
||||
model: p2
|
||||
type: Computer
|
||||
chassis: Microtower
|
||||
components:
|
||||
- manufacturer: 'p2c1m'
|
||||
serialNumber: 'p2c1s'
|
||||
type: 'Motherboard'
|
||||
- manufacturer: 'p1c2m'
|
||||
serialNumber: 'p1c2s'
|
||||
model: 'p1c2'
|
||||
- manufacturer: p2c1m
|
||||
serialNumber: p2c1s
|
||||
type: Motherboard
|
||||
- manufacturer: p1c2m
|
||||
serialNumber: p1c2s
|
||||
model: p1c2
|
||||
speed: 1.23
|
||||
cores: 2
|
||||
type: 'Processor'
|
||||
type: Processor
|
||||
elapsed: 25
|
||||
software: 'Workbench'
|
||||
uuid: 'f2e02261-87a1-4a50-b9b7-92c0e476e5f2'
|
||||
software: Workbench
|
||||
uuid: f2e02261-87a1-4a50-b9b7-92c0e476e5f2
|
||||
version: '11.0'
|
|
@ -1,20 +1,21 @@
|
|||
device:
|
||||
manufacturer: 'p1'
|
||||
serialNumber: 'p1'
|
||||
model: 'p1'
|
||||
type: 'Desktop'
|
||||
manufacturer: p1
|
||||
serialNumber: p1
|
||||
model: p1
|
||||
type: Desktop
|
||||
chassis: Microtower
|
||||
components:
|
||||
- manufacturer: 'p1c2m'
|
||||
serialNumber: 'p1c2s'
|
||||
model: 'p1c2'
|
||||
type: 'Processor'
|
||||
- manufacturer: p1c2m
|
||||
serialNumber: p1c2s
|
||||
model: p1c2
|
||||
type: Processor
|
||||
cores: 2
|
||||
speed: 1.23
|
||||
- manufacturer: 'p1c3m'
|
||||
serialNumber: 'p1c3s'
|
||||
type: 'GraphicCard'
|
||||
- manufacturer: p1c3m
|
||||
serialNumber: p1c3s
|
||||
type: GraphicCard
|
||||
memory: 1.5
|
||||
elapsed: 30
|
||||
software: 'Workbench'
|
||||
uuid: '3be271b6-5ef4-47d8-8237-5e1133eebfc6'
|
||||
software: Workbench
|
||||
uuid: 3be271b6-5ef4-47d8-8237-5e1133eebfc6
|
||||
version: '11.0'
|
|
@ -1,18 +1,19 @@
|
|||
device:
|
||||
manufacturer: 'p1'
|
||||
serialNumber: 'p1'
|
||||
model: 'p1'
|
||||
type: 'Desktop'
|
||||
manufacturer: p1
|
||||
serialNumber: p1
|
||||
model: p1
|
||||
type: Desktop
|
||||
chassis: Tower
|
||||
components:
|
||||
- manufacturer: 'p1c4m'
|
||||
serialNumber: 'p1c4s'
|
||||
type: 'NetworkAdapter'
|
||||
- manufacturer: p1c4m
|
||||
serialNumber: p1c4s
|
||||
type: NetworkAdapter
|
||||
speed: 1000
|
||||
- manufacturer: 'p1c3m'
|
||||
serialNumber: 'p1c3s'
|
||||
type: 'GraphicCard'
|
||||
- manufacturer: p1c3m
|
||||
serialNumber: p1c3s
|
||||
type: GraphicCard
|
||||
memory: 1.5
|
||||
elapsed: 25
|
||||
software: 'Workbench'
|
||||
uuid: 'fd007eb4-48e3-454a-8763-169491904c6e'
|
||||
software: Workbench
|
||||
uuid: fd007eb4-48e3-454a-8763-169491904c6e
|
||||
version: '11.0'
|
|
@ -1,25 +1,26 @@
|
|||
type: 'Snapshot'
|
||||
uuid: 'f5efd26e-8754-46bc-87bf-fbccc39d60d9'
|
||||
type: Snapshot
|
||||
uuid: f5efd26e-8754-46bc-87bf-fbccc39d60d9
|
||||
version: '11.0'
|
||||
software: 'Workbench'
|
||||
software: Workbench
|
||||
elapsed: 4
|
||||
device:
|
||||
type: 'Microtower'
|
||||
serialNumber: 'd1s'
|
||||
model: 'd1ml'
|
||||
manufacturer: 'd1mr'
|
||||
type: Computer
|
||||
chassis: Microtower
|
||||
serialNumber: d1s
|
||||
model: d1ml
|
||||
manufacturer: d1mr
|
||||
events:
|
||||
- type: 'WorkbenchRate'
|
||||
appearanceRange: 'A'
|
||||
functionalityRange: 'B'
|
||||
- type: WorkbenchRate
|
||||
appearanceRange: A
|
||||
functionalityRange: B
|
||||
labelling: True
|
||||
bios: 'B'
|
||||
bios: B
|
||||
components:
|
||||
- type: 'GraphicCard'
|
||||
serialNumber: 'gc1s'
|
||||
model: 'gc1ml'
|
||||
manufacturer: 'gc1mr'
|
||||
- type: 'RamModule'
|
||||
serialNumber: 'rm1s'
|
||||
model: 'rm1ml'
|
||||
manufacturer: 'rm1mr'
|
||||
- type: GraphicCard
|
||||
serialNumber: gc1s
|
||||
model: gc1ml
|
||||
manufacturer: gc1mr
|
||||
- type: RamModule
|
||||
serialNumber: rm1s
|
||||
model: rm1ml
|
||||
manufacturer: rm1mr
|
||||
|
|
|
@ -1,42 +1,43 @@
|
|||
uuid: '74caa7eb-2bad-4333-94f6-6f1b031d0775'
|
||||
type: 'Snapshot'
|
||||
uuid: 74caa7eb-2bad-4333-94f6-6f1b031d0775
|
||||
type: Snapshot
|
||||
version: '11.0'
|
||||
software: 'Workbench'
|
||||
software: Workbench
|
||||
elapsed: 4
|
||||
device:
|
||||
type: 'Microtower'
|
||||
serialNumber: 'pc1s'
|
||||
model: 'pc1ml'
|
||||
manufacturer: 'pc1mr'
|
||||
type: Computer
|
||||
chassis: Microtower
|
||||
serialNumber: pc1s
|
||||
model: pc1ml
|
||||
manufacturer: pc1mr
|
||||
components:
|
||||
- type: 'SolidStateDrive'
|
||||
serialNumber: 'c1s'
|
||||
model: 'c1ml'
|
||||
manufacturer: 'c1mr'
|
||||
- type: SolidStateDrive
|
||||
serialNumber: c1s
|
||||
model: c1ml
|
||||
manufacturer: c1mr
|
||||
events:
|
||||
- type: 'EraseSectors'
|
||||
- type: EraseSectors
|
||||
cleanWithZeros: True
|
||||
startTime: '2018-06-01T08:12:06'
|
||||
endTime: '2018-06-01T09:12:06'
|
||||
startTime: 2018-06-01T08:12:06
|
||||
endTime: 2018-06-01T09:12:06
|
||||
secureRandomSteps: 20
|
||||
steps:
|
||||
- type: 'StepZero'
|
||||
- type: StepZero
|
||||
error: False
|
||||
startTime: '2018-06-01T08:15:00'
|
||||
endTime: '2018-06-01T09:16:00'
|
||||
startTime: 2018-06-01T08:15:00
|
||||
endTime: 2018-06-01T09:16:00
|
||||
secureRandomSteps: 1
|
||||
cleanWithZeros: True
|
||||
- type: 'StepZero'
|
||||
- type: StepZero
|
||||
error: False
|
||||
startTime: '2018-06-01T08:16:00'
|
||||
endTime: '2018-06-01T09:17:00'
|
||||
startTime: 2018-06-01T08:16:00
|
||||
endTime: 2018-06-01T09:17:00
|
||||
secureRandomSteps: 1
|
||||
cleanWithZeros: True
|
||||
- type: 'GraphicCard'
|
||||
serialNumber: 'gc1s'
|
||||
model: 'gc1ml'
|
||||
manufacturer: 'gc1mr'
|
||||
- type: 'RamModule'
|
||||
serialNumber: 'rm1s'
|
||||
model: 'rm1ml'
|
||||
manufacturer: 'rm1mr'
|
||||
- type: GraphicCard
|
||||
serialNumber: gc1s
|
||||
model: gc1ml
|
||||
manufacturer: gc1mr
|
||||
- type: RamModule
|
||||
serialNumber: rm1s
|
||||
model: rm1ml
|
||||
manufacturer: rm1mr
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
device:
|
||||
type: 'Microtower'
|
||||
serial_number: 'd1s'
|
||||
model: 'd1ml'
|
||||
manufacturer: 'd1mr'
|
||||
type: Desktop
|
||||
chassis: Microtower
|
||||
serial_number: d1s
|
||||
model: d1ml
|
||||
manufacturer: d1mr
|
||||
components:
|
||||
- type: 'GraphicCard'
|
||||
serial_number: 'gc1s'
|
||||
model: 'gc1ml'
|
||||
manufacturer: 'gc1mr'
|
||||
- type: 'RamModule'
|
||||
serial_number: 'rm1s'
|
||||
model: 'rm1ml'
|
||||
manufacturer: 'rm1mr'
|
||||
- type: GraphicCard
|
||||
serial_number: gc1s
|
||||
model: gc1ml
|
||||
manufacturer: gc1mr
|
||||
- type: RamModule
|
||||
serial_number: rm1s
|
||||
model: rm1ml
|
||||
manufacturer: rm1mr
|
||||
|
|
|
@ -1,66 +1,67 @@
|
|||
# A Snapshot Phase 1 with a device
|
||||
# and 1 GraphicCard, 2 RamModule, 1 Processor, 1 SSD, 1 HDD, 1 Motherboard
|
||||
# Prerequisites:
|
||||
# - 2 tags: 'tag1' and 'tag2' from the default org
|
||||
# - 2 tags: tag1 and tag2 from the default org
|
||||
# All numbers are invented
|
||||
|
||||
|
||||
type: 'Snapshot'
|
||||
uuid: 'cb8ce6b5-6a1b-4084-b5b9-d8fadad2a015'
|
||||
type: Snapshot
|
||||
uuid: cb8ce6b5-6a1b-4084-b5b9-d8fadad2a015
|
||||
version: '11.0'
|
||||
software: 'Workbench'
|
||||
expectedEvents: ['TestDataStorage', 'StressTest', 'EraseSectors', 'Install']
|
||||
software: Workbench
|
||||
expectedEvents: [TestDataStorage, StressTest, EraseSectors, Install]
|
||||
elapsed: 500
|
||||
device:
|
||||
type: 'Microtower'
|
||||
serialNumber: 'd1s'
|
||||
model: 'd1ml'
|
||||
manufacturer: 'd1mr'
|
||||
type: Desktop
|
||||
chassis: Tower
|
||||
serialNumber: d1s
|
||||
model: d1ml
|
||||
manufacturer: d1mr
|
||||
tags:
|
||||
- type: 'Tag'
|
||||
id: 'tag1'
|
||||
- type: Tag
|
||||
id: tag1
|
||||
events:
|
||||
- type: 'WorkbenchRate'
|
||||
appearanceRange: 'A'
|
||||
functionalityRange: 'B'
|
||||
- type: 'BenchmarkRamSysbench'
|
||||
- type: WorkbenchRate
|
||||
appearanceRange: A
|
||||
functionalityRange: B
|
||||
- type: BenchmarkRamSysbench
|
||||
rate: 2444
|
||||
components:
|
||||
- type: 'GraphicCard'
|
||||
serialNumber: 'gc1-1s'
|
||||
model: 'gc1-1ml'
|
||||
manufacturer: 'gc1-1mr'
|
||||
- type: 'RamModule'
|
||||
serialNumber: 'rm1-1s'
|
||||
model: 'rm1-1ml'
|
||||
manufacturer: 'rm1-1mr'
|
||||
- type: 'RamModule'
|
||||
serialNumber: 'rm2-1s'
|
||||
model: 'rm2-1ml'
|
||||
manufacturer: 'rm2-1mr'
|
||||
- type: 'Processor'
|
||||
model: 'p1-1s'
|
||||
manufacturer: 'p1-1mr'
|
||||
- type: GraphicCard
|
||||
serialNumber: gc1-1s
|
||||
model: gc1-1ml
|
||||
manufacturer: gc1-1mr
|
||||
- type: RamModule
|
||||
serialNumber: rm1-1s
|
||||
model: rm1-1ml
|
||||
manufacturer: rm1-1mr
|
||||
- type: RamModule
|
||||
serialNumber: rm2-1s
|
||||
model: rm2-1ml
|
||||
manufacturer: rm2-1mr
|
||||
- type: Processor
|
||||
model: p1-1s
|
||||
manufacturer: p1-1mr
|
||||
events:
|
||||
- type: 'BenchmarkProcessor'
|
||||
- type: BenchmarkProcessor
|
||||
rate: 2410
|
||||
- type: 'BenchmarkProcessorSysbench'
|
||||
- type: BenchmarkProcessorSysbench
|
||||
rate: 4400
|
||||
- type: 'SolidStateDrive'
|
||||
serialNumber: 'ssd1-1s'
|
||||
model: 'ssd1-1ml'
|
||||
manufacturer: 'ssd1-1mr'
|
||||
- type: SolidStateDrive
|
||||
serialNumber: ssd1-1s
|
||||
model: ssd1-1ml
|
||||
manufacturer: ssd1-1mr
|
||||
events:
|
||||
- type: 'BenchmarkDataStorage'
|
||||
- type: BenchmarkDataStorage
|
||||
readSpeed: 20
|
||||
writeSpeed: 15
|
||||
elapsed: 21
|
||||
- type: 'TestDataStorage'
|
||||
- type: TestDataStorage
|
||||
elapsed: 233
|
||||
firstError: 0
|
||||
error: False
|
||||
status: 'Completed without error'
|
||||
length: 'Short'
|
||||
status: Completed without error
|
||||
length: Short
|
||||
lifetime: 99
|
||||
passedLifetime: 99
|
||||
assessment: True
|
||||
|
@ -72,15 +73,15 @@ components:
|
|||
currentPendingSectorCount: 1
|
||||
offlineUncorrectable: 33
|
||||
remainingLifetimePercentage: 1
|
||||
- type: 'HardDrive'
|
||||
serialNumber: 'hdd1-1s'
|
||||
model: 'hdd1-1ml'
|
||||
manufacturer: 'hdd1-1mr'
|
||||
- type: HardDrive
|
||||
serialNumber: hdd1-1s
|
||||
model: hdd1-1ml
|
||||
manufacturer: hdd1-1mr
|
||||
events:
|
||||
- type: 'BenchmarkDataStorage'
|
||||
- type: BenchmarkDataStorage
|
||||
readSpeed: 10
|
||||
writeSpeed: 5
|
||||
- type: 'Motherboard'
|
||||
serialNumber: 'mb1-1s'
|
||||
model: 'mb1-1ml'
|
||||
manufacturer: 'mb1-1mr'
|
||||
- type: Motherboard
|
||||
serialNumber: mb1-1s
|
||||
model: mb1-1ml
|
||||
manufacturer: mb1-1mr
|
||||
|
|
|
@ -35,4 +35,4 @@ def test_api_docs(client: Client):
|
|||
'scheme': 'basic',
|
||||
'name': 'Authorization'
|
||||
}
|
||||
assert len(docs['definitions']) == 46
|
||||
assert len(docs['definitions']) == 51
|
||||
|
|
|
@ -10,12 +10,12 @@ from ereuse_devicehub.client import UserClient
|
|||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
from ereuse_devicehub.resources.device.exceptions import NeedsId
|
||||
from ereuse_devicehub.resources.device.models import Component, Computer, ComputerMonitor, Desktop, \
|
||||
Device, GraphicCard, Laptop, Microtower, Motherboard, NetworkAdapter
|
||||
from ereuse_devicehub.resources.device.models import Component, ComputerMonitor, Desktop, Device, \
|
||||
GraphicCard, Laptop, Motherboard, NetworkAdapter
|
||||
from ereuse_devicehub.resources.device.schemas import Device as DeviceS
|
||||
from ereuse_devicehub.resources.device.sync import MismatchBetweenTags, MismatchBetweenTagsAndHid, \
|
||||
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.tag.model import Tag
|
||||
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.
|
||||
"""
|
||||
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')
|
||||
graphic = GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
|
||||
pc.components.add(net)
|
||||
|
@ -82,7 +85,7 @@ def test_physical_properties():
|
|||
manufacturer='mr',
|
||||
width=2.0,
|
||||
color=Color())
|
||||
pc = Computer()
|
||||
pc = Desktop(chassis=ComputerChassis.Tower)
|
||||
pc.components.add(c)
|
||||
db.session.add(pc)
|
||||
db.session.commit()
|
||||
|
@ -108,7 +111,7 @@ def test_component_similar_one():
|
|||
snapshot = file('pc-components.db')
|
||||
d = snapshot['device']
|
||||
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
|
||||
db.session.add(pc)
|
||||
db.session.flush()
|
||||
|
@ -134,10 +137,12 @@ def test_add_remove():
|
|||
values = file('pc-components.db')
|
||||
pc = values['device']
|
||||
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)
|
||||
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')
|
||||
db.session.add(pc2)
|
||||
db.session.add(c4)
|
||||
|
@ -161,12 +166,12 @@ def test_sync_run_components_empty():
|
|||
remove all the components from the device.
|
||||
"""
|
||||
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.commit()
|
||||
|
||||
# Create a new transient non-db synced object
|
||||
pc = Computer(**s['device'])
|
||||
pc = Desktop(**s['device'])
|
||||
db_pc, _ = Sync().run(pc, components=OrderedSet())
|
||||
assert not db_pc.components
|
||||
assert not pc.components
|
||||
|
@ -179,52 +184,52 @@ def test_sync_run_components_none():
|
|||
keep all the components from the device.
|
||||
"""
|
||||
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.commit()
|
||||
|
||||
# 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)
|
||||
assert db_pc.components
|
||||
assert db_pc.components == pc.components
|
||||
|
||||
|
||||
@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:
|
||||
"""
|
||||
# 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)
|
||||
assert pc.physical_properties == db_pc.physical_properties
|
||||
|
||||
|
||||
@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.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
|
||||
db_pc = Sync().execute_register(pc)
|
||||
assert pc.physical_properties == db_pc.physical_properties
|
||||
|
||||
|
||||
@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.
|
||||
"""
|
||||
pc = Computer(**file('pc-components.db')['device'])
|
||||
pc = Desktop(**file('pc-components.db')['device'])
|
||||
# 1: device has no HID
|
||||
pc.hid = pc.model = None
|
||||
with pytest.raises(NeedsId):
|
||||
|
@ -232,9 +237,9 @@ def test_sync_execute_register_computer_no_hid_no_tag():
|
|||
|
||||
|
||||
@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.
|
||||
"""
|
||||
|
@ -243,24 +248,24 @@ def test_sync_execute_register_computer_tag_not_linked():
|
|||
db.session.commit()
|
||||
|
||||
# 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)
|
||||
assert returned_pc == pc
|
||||
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')
|
||||
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
|
||||
the computer was not existing before (otherwise the tag would
|
||||
be linked), and thus it creates a new computer.
|
||||
the Desktop was not existing before (otherwise the tag would
|
||||
be linked), and thus it creates a new Desktop.
|
||||
"""
|
||||
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)
|
||||
db.session.commit()
|
||||
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
|
||||
assert tag != db_tag, 'They are not the same tags though'
|
||||
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')
|
||||
|
@ -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.
|
||||
"""
|
||||
pc = Computer(**file('pc-components.db')['device'], tags=OrderedSet([Tag()]))
|
||||
pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([Tag()]))
|
||||
with raises(ResourceNotFound):
|
||||
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
|
||||
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.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'))
|
||||
db_pc = Sync().execute_register(pc)
|
||||
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
|
||||
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))
|
||||
pc2 = Computer(**file('pc-components.db')['device'])
|
||||
pc2 = Desktop(**file('pc-components.db')['device'])
|
||||
pc2.serial_number = 'pc2-serial'
|
||||
pc2.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
|
||||
db.session.add(Tag(id='foo-2', device=pc2))
|
||||
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-2'))
|
||||
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
|
||||
"""
|
||||
pc1 = Computer(**file('pc-components.db')['device'])
|
||||
pc1 = Desktop(**file('pc-components.db')['device'])
|
||||
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.hid = Naming.hid(pc2.manufacturer, pc2.serial_number, pc2.model)
|
||||
db.session.add(Tag(id='foo-2', device=pc2))
|
||||
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'))
|
||||
with raises(MismatchBetweenTagsAndHid):
|
||||
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):
|
||||
"""Checks GETting a Desktop with its components."""
|
||||
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([
|
||||
NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
|
||||
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):
|
||||
"""Checks GETting multiple devices."""
|
||||
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([
|
||||
NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s'),
|
||||
GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
|
||||
])
|
||||
pc1 = Microtower(model='p2mo', manufacturer='p2ma', serial_number='p2s')
|
||||
pc2 = Laptop(model='p3mo', manufacturer='p3ma', serial_number='p3s')
|
||||
pc1 = Desktop(model='p2mo',
|
||||
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.commit()
|
||||
devices, _ = user.get(res=Device)
|
||||
assert tuple(d['id'] for d in devices) == (1, 2, 3, 4, 5)
|
||||
assert tuple(d['type'] for d in devices) == ('Desktop', 'Microtower',
|
||||
'Laptop', 'NetworkAdapter', 'GraphicCard')
|
||||
assert tuple(d['type'] for d in devices) == ('Desktop', 'Desktop', 'Laptop',
|
||||
'NetworkAdapter', 'GraphicCard')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('app_context')
|
||||
def test_computer_monitor():
|
||||
m = ComputerMonitor(technology=ComputerMonitorTechnologies.LCD,
|
||||
m = ComputerMonitor(technology=DisplayTech.LCD,
|
||||
manufacturer='foo',
|
||||
model='bar',
|
||||
serial_number='foo-bar',
|
||||
|
@ -410,3 +427,18 @@ def test_computer_monitor():
|
|||
size=14.5)
|
||||
db.session.add(m)
|
||||
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
|
||||
|
|
|
@ -5,7 +5,7 @@ from flask import g
|
|||
from sqlalchemy.util import OrderedSet
|
||||
|
||||
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
|
||||
from ereuse_devicehub.resources.enums import TestHardDriveLength
|
||||
from ereuse_devicehub.resources.event.models import BenchmarkDataStorage, EraseBasic, EraseSectors, \
|
||||
|
@ -130,7 +130,7 @@ def test_install():
|
|||
|
||||
@pytest.mark.usefixtures('auth_app_context')
|
||||
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')
|
||||
computer.components.add(hdd)
|
||||
|
||||
|
@ -155,7 +155,7 @@ def test_update_components_event_one():
|
|||
|
||||
@pytest.mark.usefixtures('auth_app_context')
|
||||
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')
|
||||
computer.components.add(hdd)
|
||||
|
||||
|
@ -181,7 +181,7 @@ def test_update_components_event_multiple():
|
|||
|
||||
@pytest.mark.usefixtures('auth_app_context')
|
||||
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')
|
||||
computer.components.add(hdd)
|
||||
|
||||
|
|
|
@ -3,8 +3,8 @@ import pytest
|
|||
from ereuse_devicehub.client import UserClient
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, Microtower, \
|
||||
SolidStateDrive
|
||||
from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, SolidStateDrive
|
||||
from ereuse_devicehub.resources.enums import ComputerChassis
|
||||
from ereuse_devicehub.resources.inventory import Filters, Inventory, Sorting
|
||||
from teal.utils import compiled
|
||||
|
||||
|
@ -25,8 +25,8 @@ def test_inventory_filters():
|
|||
})
|
||||
s, params = compiled(Device, q)
|
||||
# Order between query clauses can change
|
||||
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
|
||||
assert '(device.type IN (%(type_1)s, %(type_2)s, %(type_3)s, %(type_4)s) ' \
|
||||
'OR device.type IN (%(type_5)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.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
|
||||
# ex: type_1 can be 'Desktop' in one execution but the next one 'Laptop'
|
||||
assert set(params.keys()) == {
|
||||
'id_1',
|
||||
'manufacturer_1',
|
||||
'type_4',
|
||||
'type_3',
|
||||
'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'
|
||||
}
|
||||
assert set(params.keys()) == {'id_2', 'appearance_1', 'type_1', 'type_4', 'rating_2', 'type_5',
|
||||
'type_3', 'type_2', 'appearance_2', 'id_1', 'rating_1',
|
||||
'manufacturer_1'}
|
||||
assert set(params.values()) == {2.0, 'Laptop', 4.0, 3.0, 6.0, 'Desktop', 'activa-02%',
|
||||
'Server', 'Dell%', 'Computer', 'bcn-%'}
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('app_context')
|
||||
|
@ -79,9 +52,18 @@ def test_inventory_sort():
|
|||
def inventory_query_dummy(app: Devicehub):
|
||||
with app.app_context():
|
||||
db.session.add_all(( # The order matters ;-)
|
||||
Desktop(serial_number='s1', model='ml1', manufacturer='mr1'),
|
||||
Laptop(serial_number='s3', model='ml3', manufacturer='mr3'),
|
||||
Microtower(serial_number='s2', model='ml2', manufacturer='mr2'),
|
||||
Desktop(serial_number='s1',
|
||||
model='ml1',
|
||||
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')
|
||||
))
|
||||
db.session.commit()
|
||||
|
@ -91,14 +73,14 @@ def inventory_query_dummy(app: Devicehub):
|
|||
def test_inventory_query_no_filters(user: UserClient):
|
||||
i, _ = user.get(res=Inventory)
|
||||
assert tuple(d['type'] for d in i['devices']) == (
|
||||
'SolidStateDrive', 'Microtower', 'Laptop', 'Desktop'
|
||||
'SolidStateDrive', 'Desktop', 'Laptop', 'Desktop'
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inventory_query_dummy')
|
||||
def test_inventory_query_filter_type(user: UserClient):
|
||||
i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Computer', 'Microtower']})])
|
||||
assert tuple(d['type'] for d in i['devices']) == ('Microtower', 'Laptop', 'Desktop')
|
||||
i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Desktop', 'Laptop']})])
|
||||
assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop')
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('inventory_query_dummy')
|
||||
|
@ -107,4 +89,4 @@ def test_inventory_query_filter_sort(user: UserClient):
|
|||
('sort', {'created': Sorting.ASCENDING}),
|
||||
('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')
|
||||
|
|
|
@ -3,8 +3,9 @@ from distutils.version import StrictVersion
|
|||
import pytest
|
||||
|
||||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.resources.device.models import Microtower
|
||||
from ereuse_devicehub.resources.enums import Bios, ImageMimeTypes, Orientation, RatingSoftware
|
||||
from ereuse_devicehub.resources.device.models import Computer
|
||||
from ereuse_devicehub.resources.enums import Bios, ComputerChassis, ImageMimeTypes, Orientation, \
|
||||
RatingSoftware
|
||||
from ereuse_devicehub.resources.event.models import PhotoboxRate, WorkbenchRate
|
||||
from ereuse_devicehub.resources.image.models import Image, ImageList
|
||||
|
||||
|
@ -19,14 +20,14 @@ def test_workbench_rate():
|
|||
data_storage=4.1,
|
||||
algorithm_software=RatingSoftware.Ereuse,
|
||||
algorithm_version=StrictVersion('1.0'),
|
||||
device=Microtower(serial_number='24'))
|
||||
device=Computer(serial_number='24', chassis=ComputerChassis.Tower))
|
||||
db.session.add(rate)
|
||||
db.session.commit()
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('auth_app_context')
|
||||
def test_photobox_rate():
|
||||
pc = Microtower(serial_number='24')
|
||||
pc = Computer(serial_number='24', chassis=ComputerChassis.Tower)
|
||||
image = Image(name='foo',
|
||||
content=b'123',
|
||||
file_format=ImageMimeTypes.jpg,
|
||||
|
|
|
@ -9,10 +9,11 @@ from ereuse_devicehub.client import UserClient
|
|||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
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.enums import Bios, RatingSoftware, SnapshotSoftware
|
||||
from ereuse_devicehub.resources.event.models import EraseBasic, Event, Snapshot, SnapshotRequest, \
|
||||
from ereuse_devicehub.resources.enums import Bios, RatingSoftware, SnapshotSoftware, \
|
||||
ComputerChassis
|
||||
from ereuse_devicehub.resources.event.models import Event, Snapshot, SnapshotRequest, \
|
||||
WorkbenchRate
|
||||
from ereuse_devicehub.resources.tag import Tag
|
||||
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
|
||||
DB mapping.
|
||||
"""
|
||||
device = Microtower(serial_number='a1')
|
||||
device = Computer(serial_number='a1', chassis=ComputerChassis.Tower)
|
||||
# noinspection PyArgumentList
|
||||
snapshot = Snapshot(uuid=uuid4(),
|
||||
date=datetime.now(),
|
||||
|
@ -107,7 +108,7 @@ def test_snapshot_model():
|
|||
device=device))
|
||||
db.session.add(snapshot)
|
||||
db.session.commit()
|
||||
device = Microtower.query.one() # type: Microtower
|
||||
device = Computer.query.one() # type: Computer
|
||||
e1, e2 = device.events
|
||||
assert isinstance(e1, Snapshot), 'Creation order must be preserved: 1. snapshot, 2. WR'
|
||||
assert isinstance(e2, WorkbenchRate)
|
||||
|
@ -116,7 +117,7 @@ def test_snapshot_model():
|
|||
assert Snapshot.query.one_or_none() is None
|
||||
assert SnapshotRequest.query.one_or_none() is 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
|
||||
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@ from ereuse_devicehub.client import UserClient
|
|||
from ereuse_devicehub.db import db
|
||||
from ereuse_devicehub.devicehub import Devicehub
|
||||
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.view import CannotCreateETag, TagNotLinked
|
||||
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():
|
||||
# Create a pc with a tag
|
||||
tag = Tag(id='foo-bar')
|
||||
pc = Computer(serial_number='sn1')
|
||||
pc = Computer(serial_number='sn1', chassis=ComputerChassis.Tower)
|
||||
pc.tags.add(tag)
|
||||
db.session.add(pc)
|
||||
db.session.commit()
|
||||
|
|
Reference in New Issue