Use teal.test_import_resource; reformat imports; add generic events
This commit is contained in:
parent
6d85f314ef
commit
8efca0d589
|
@ -1,41 +1,21 @@
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
from itertools import chain
|
||||||
from typing import Set
|
from typing import Set
|
||||||
|
|
||||||
from ereuse_devicehub.resources.device import CellphoneDef, ComponentDef, ComputerDef, \
|
from ereuse_devicehub.resources import device, event, inventory, tag, user
|
||||||
ComputerMonitorDef, DataStorageDef, DesktopDef, DeviceDef, DisplayDef, GraphicCardDef, \
|
|
||||||
HardDriveDef, LaptopDef, MobileDef, MonitorDef, MotherboardDef, NetworkAdapterDef, \
|
|
||||||
ProcessorDef, RamModuleDef, ServerDef, SmartphoneDef, SolidStateDriveDef, SoundCardDef, \
|
|
||||||
TabletDef, TelevisionSetDef
|
|
||||||
from ereuse_devicehub.resources.enums import PriceSoftware, RatingSoftware
|
from ereuse_devicehub.resources.enums import PriceSoftware, RatingSoftware
|
||||||
from ereuse_devicehub.resources.event import AddDef, AggregateRateDef, AppRateDef, \
|
|
||||||
BenchmarkDataStorageDef, BenchmarkDef, BenchmarkProcessorDef, BenchmarkProcessorSysbenchDef, \
|
|
||||||
BenchmarkRamSysbenchDef, BenchmarkWithRateDef, EraseBasicDef, EraseSectorsDef, EreusePriceDef, \
|
|
||||||
EventDef, InstallDef, PhotoboxSystemRateDef, PhotoboxUserDef, PriceDef, RateDef, RemoveDef, \
|
|
||||||
SnapshotDef, StepDef, StepRandomDef, StepZeroDef, StressTestDef, TestDataStorageDef, TestDef, \
|
|
||||||
WorkbenchRateDef
|
|
||||||
from ereuse_devicehub.resources.inventory import InventoryDef
|
|
||||||
from ereuse_devicehub.resources.tag import TagDef
|
|
||||||
from ereuse_devicehub.resources.user import OrganizationDef, UserDef
|
|
||||||
from teal.auth import TokenAuth
|
from teal.auth import TokenAuth
|
||||||
from teal.config import Config
|
from teal.config import Config
|
||||||
from teal.currency import Currency
|
from teal.currency import Currency
|
||||||
|
from teal.utils import import_resource
|
||||||
|
|
||||||
|
|
||||||
class DevicehubConfig(Config):
|
class DevicehubConfig(Config):
|
||||||
RESOURCE_DEFINITIONS = {
|
RESOURCE_DEFINITIONS = set(chain(import_resource(device),
|
||||||
DeviceDef, ComputerDef, DesktopDef, LaptopDef, ServerDef, MonitorDef, TelevisionSetDef,
|
import_resource(event),
|
||||||
ComputerMonitorDef, ComponentDef, GraphicCardDef, DataStorageDef,
|
import_resource(user),
|
||||||
SolidStateDriveDef, MobileDef, DisplayDef, SmartphoneDef, TabletDef, CellphoneDef,
|
import_resource(tag),
|
||||||
HardDriveDef, MotherboardDef, NetworkAdapterDef, RamModuleDef, ProcessorDef, SoundCardDef,
|
import_resource(inventory)))
|
||||||
UserDef,
|
|
||||||
OrganizationDef, TagDef, EventDef, AddDef, RemoveDef, EraseBasicDef, EraseSectorsDef,
|
|
||||||
StepDef, StepZeroDef, StepRandomDef, RateDef, AggregateRateDef, WorkbenchRateDef,
|
|
||||||
PhotoboxUserDef, PhotoboxSystemRateDef, PriceDef, EreusePriceDef,
|
|
||||||
InstallDef, SnapshotDef, TestDef,
|
|
||||||
TestDataStorageDef, StressTestDef, WorkbenchRateDef, InventoryDef, BenchmarkDef,
|
|
||||||
BenchmarkDataStorageDef, BenchmarkWithRateDef, AppRateDef, BenchmarkProcessorDef,
|
|
||||||
BenchmarkProcessorSysbenchDef, BenchmarkRamSysbenchDef
|
|
||||||
}
|
|
||||||
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
|
PASSWORD_SCHEMES = {'pbkdf2_sha256'} # type: Set[str]
|
||||||
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str
|
SQLALCHEMY_DATABASE_URI = 'postgresql://dhub:ereuse@localhost/devicehub' # type: str
|
||||||
SCHEMA = 'dhub'
|
SCHEMA = 'dhub'
|
||||||
|
|
|
@ -1,13 +1,10 @@
|
||||||
from ereuse_devicehub.resources.device.schemas import Cellphone, Component, Computer, \
|
from ereuse_devicehub.resources.device import schemas
|
||||||
ComputerMonitor, DataStorage, Desktop, Device, Display, GraphicCard, HardDrive, Laptop, Mobile, \
|
|
||||||
Monitor, Motherboard, NetworkAdapter, Processor, RamModule, Server, Smartphone, \
|
|
||||||
SolidStateDrive, SoundCard, 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
|
||||||
|
|
||||||
|
|
||||||
class DeviceDef(Resource):
|
class DeviceDef(Resource):
|
||||||
SCHEMA = Device
|
SCHEMA = schemas.Device
|
||||||
VIEW = DeviceView
|
VIEW = DeviceView
|
||||||
ID_CONVERTER = Converters.int
|
ID_CONVERTER = Converters.int
|
||||||
AUTH = True
|
AUTH = True
|
||||||
|
@ -15,109 +12,109 @@ class DeviceDef(Resource):
|
||||||
|
|
||||||
class ComputerDef(DeviceDef):
|
class ComputerDef(DeviceDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Computer
|
SCHEMA = schemas.Computer
|
||||||
|
|
||||||
|
|
||||||
class DesktopDef(ComputerDef):
|
class DesktopDef(ComputerDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Desktop
|
SCHEMA = schemas.Desktop
|
||||||
|
|
||||||
|
|
||||||
class LaptopDef(ComputerDef):
|
class LaptopDef(ComputerDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Laptop
|
SCHEMA = schemas.Laptop
|
||||||
|
|
||||||
|
|
||||||
class ServerDef(ComputerDef):
|
class ServerDef(ComputerDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Server
|
SCHEMA = schemas.Server
|
||||||
|
|
||||||
|
|
||||||
class MonitorDef(DeviceDef):
|
class MonitorDef(DeviceDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Monitor
|
SCHEMA = schemas.Monitor
|
||||||
|
|
||||||
|
|
||||||
class ComputerMonitorDef(MonitorDef):
|
class ComputerMonitorDef(MonitorDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = ComputerMonitor
|
SCHEMA = schemas.ComputerMonitor
|
||||||
|
|
||||||
|
|
||||||
class TelevisionSetDef(MonitorDef):
|
class TelevisionSetDef(MonitorDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = TelevisionSet
|
SCHEMA = schemas.TelevisionSet
|
||||||
|
|
||||||
|
|
||||||
class MobileDef(DeviceDef):
|
class MobileDef(DeviceDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Mobile
|
SCHEMA = schemas.Mobile
|
||||||
|
|
||||||
|
|
||||||
class SmartphoneDef(MobileDef):
|
class SmartphoneDef(MobileDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Smartphone
|
SCHEMA = schemas.Smartphone
|
||||||
|
|
||||||
|
|
||||||
class TabletDef(MobileDef):
|
class TabletDef(MobileDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Tablet
|
SCHEMA = schemas.Tablet
|
||||||
|
|
||||||
|
|
||||||
class CellphoneDef(MobileDef):
|
class CellphoneDef(MobileDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Cellphone
|
SCHEMA = schemas.Cellphone
|
||||||
|
|
||||||
|
|
||||||
class ComponentDef(DeviceDef):
|
class ComponentDef(DeviceDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Component
|
SCHEMA = schemas.Component
|
||||||
|
|
||||||
|
|
||||||
class GraphicCardDef(ComponentDef):
|
class GraphicCardDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = GraphicCard
|
SCHEMA = schemas.GraphicCard
|
||||||
|
|
||||||
|
|
||||||
class DataStorageDef(ComponentDef):
|
class DataStorageDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = DataStorage
|
SCHEMA = schemas.DataStorage
|
||||||
|
|
||||||
|
|
||||||
class HardDriveDef(DataStorageDef):
|
class HardDriveDef(DataStorageDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = HardDrive
|
SCHEMA = schemas.HardDrive
|
||||||
|
|
||||||
|
|
||||||
class SolidStateDriveDef(DataStorageDef):
|
class SolidStateDriveDef(DataStorageDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = SolidStateDrive
|
SCHEMA = schemas.SolidStateDrive
|
||||||
|
|
||||||
|
|
||||||
class MotherboardDef(ComponentDef):
|
class MotherboardDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Motherboard
|
SCHEMA = schemas.Motherboard
|
||||||
|
|
||||||
|
|
||||||
class NetworkAdapterDef(ComponentDef):
|
class NetworkAdapterDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = NetworkAdapter
|
SCHEMA = schemas.NetworkAdapter
|
||||||
|
|
||||||
|
|
||||||
class RamModuleDef(ComponentDef):
|
class RamModuleDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = RamModule
|
SCHEMA = schemas.RamModule
|
||||||
|
|
||||||
|
|
||||||
class ProcessorDef(ComponentDef):
|
class ProcessorDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Processor
|
SCHEMA = schemas.Processor
|
||||||
|
|
||||||
|
|
||||||
class SoundCardDef(ComponentDef):
|
class SoundCardDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = SoundCard
|
SCHEMA = schemas.SoundCard
|
||||||
|
|
||||||
|
|
||||||
class DisplayDef(ComponentDef):
|
class DisplayDef(ComponentDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Display
|
SCHEMA = schemas.Display
|
||||||
|
|
|
@ -1,17 +1,13 @@
|
||||||
from typing import Callable, Iterable, Tuple
|
from typing import Callable, Iterable, Tuple
|
||||||
|
|
||||||
from ereuse_devicehub.resources.device.sync import Sync
|
from ereuse_devicehub.resources.device.sync import Sync
|
||||||
from ereuse_devicehub.resources.event.schemas import Add, AggregateRate, AppRate, Benchmark, \
|
from ereuse_devicehub.resources.event import schemas
|
||||||
BenchmarkDataStorage, BenchmarkProcessor, BenchmarkProcessorSysbench, BenchmarkRamSysbench, \
|
|
||||||
BenchmarkWithRate, EraseBasic, EraseSectors, EreusePrice, Event, Install, PhotoboxSystemRate, \
|
|
||||||
PhotoboxUserRate, Price, Rate, Remove, Snapshot, Step, StepRandom, StepZero, StressTest, Test, \
|
|
||||||
TestDataStorage, WorkbenchRate
|
|
||||||
from ereuse_devicehub.resources.event.views import EventView, SnapshotView
|
from ereuse_devicehub.resources.event.views import EventView, SnapshotView
|
||||||
from teal.resource import Converters, Resource
|
from teal.resource import Converters, Resource
|
||||||
|
|
||||||
|
|
||||||
class EventDef(Resource):
|
class EventDef(Resource):
|
||||||
SCHEMA = Event
|
SCHEMA = schemas.Event
|
||||||
VIEW = EventView
|
VIEW = EventView
|
||||||
AUTH = True
|
AUTH = True
|
||||||
ID_CONVERTER = Converters.uuid
|
ID_CONVERTER = Converters.uuid
|
||||||
|
@ -19,87 +15,87 @@ class EventDef(Resource):
|
||||||
|
|
||||||
class AddDef(EventDef):
|
class AddDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Add
|
SCHEMA = schemas.Add
|
||||||
|
|
||||||
|
|
||||||
class RemoveDef(EventDef):
|
class RemoveDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Remove
|
SCHEMA = schemas.Remove
|
||||||
|
|
||||||
|
|
||||||
class EraseBasicDef(EventDef):
|
class EraseBasicDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = EraseBasic
|
SCHEMA = schemas.EraseBasic
|
||||||
|
|
||||||
|
|
||||||
class EraseSectorsDef(EraseBasicDef):
|
class EraseSectorsDef(EraseBasicDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = EraseSectors
|
SCHEMA = schemas.EraseSectors
|
||||||
|
|
||||||
|
|
||||||
class StepDef(Resource):
|
class StepDef(Resource):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Step
|
SCHEMA = schemas.Step
|
||||||
|
|
||||||
|
|
||||||
class StepZeroDef(StepDef):
|
class StepZeroDef(StepDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = StepZero
|
SCHEMA = schemas.StepZero
|
||||||
|
|
||||||
|
|
||||||
class StepRandomDef(StepDef):
|
class StepRandomDef(StepDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = StepRandom
|
SCHEMA = schemas.StepRandom
|
||||||
|
|
||||||
|
|
||||||
class RateDef(EventDef):
|
class RateDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Rate
|
SCHEMA = schemas.Rate
|
||||||
|
|
||||||
|
|
||||||
class AggregateRateDef(RateDef):
|
class AggregateRateDef(RateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = AggregateRate
|
SCHEMA = schemas.AggregateRate
|
||||||
|
|
||||||
|
|
||||||
class WorkbenchRateDef(RateDef):
|
class WorkbenchRateDef(RateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = WorkbenchRate
|
SCHEMA = schemas.WorkbenchRate
|
||||||
|
|
||||||
|
|
||||||
class PhotoboxUserDef(RateDef):
|
class PhotoboxUserDef(RateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = PhotoboxUserRate
|
SCHEMA = schemas.PhotoboxUserRate
|
||||||
|
|
||||||
|
|
||||||
class PhotoboxSystemRateDef(RateDef):
|
class PhotoboxSystemRateDef(RateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = PhotoboxSystemRate
|
SCHEMA = schemas.PhotoboxSystemRate
|
||||||
|
|
||||||
|
|
||||||
class AppRateDef(RateDef):
|
class AppRateDef(RateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = AppRate
|
SCHEMA = schemas.AppRate
|
||||||
|
|
||||||
|
|
||||||
class PriceDef(EventDef):
|
class PriceDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Price
|
SCHEMA = schemas.Price
|
||||||
|
|
||||||
|
|
||||||
class EreusePriceDef(EventDef):
|
class EreusePriceDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = EreusePrice
|
SCHEMA = schemas.EreusePrice
|
||||||
|
|
||||||
|
|
||||||
class InstallDef(EventDef):
|
class InstallDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Install
|
SCHEMA = schemas.Install
|
||||||
|
|
||||||
|
|
||||||
class SnapshotDef(EventDef):
|
class SnapshotDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Snapshot
|
SCHEMA = schemas.Snapshot
|
||||||
VIEW = SnapshotView
|
VIEW = SnapshotView
|
||||||
|
|
||||||
def __init__(self, app, import_name=__package__, static_folder=None, static_url_path=None,
|
def __init__(self, app, import_name=__package__, static_folder=None, static_url_path=None,
|
||||||
|
@ -112,44 +108,74 @@ class SnapshotDef(EventDef):
|
||||||
|
|
||||||
class TestDef(EventDef):
|
class TestDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Test
|
SCHEMA = schemas.Test
|
||||||
|
|
||||||
|
|
||||||
class TestDataStorageDef(TestDef):
|
class TestDataStorageDef(TestDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = TestDataStorage
|
SCHEMA = schemas.TestDataStorage
|
||||||
|
|
||||||
|
|
||||||
class StressTestDef(TestDef):
|
class StressTestDef(TestDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = StressTest
|
SCHEMA = schemas.StressTest
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkDef(EventDef):
|
class BenchmarkDef(EventDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = Benchmark
|
SCHEMA = schemas.Benchmark
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkDataStorageDef(BenchmarkDef):
|
class BenchmarkDataStorageDef(BenchmarkDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = BenchmarkDataStorage
|
SCHEMA = schemas.BenchmarkDataStorage
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkWithRateDef(BenchmarkDef):
|
class BenchmarkWithRateDef(BenchmarkDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = BenchmarkWithRate
|
SCHEMA = schemas.BenchmarkWithRate
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkProcessorDef(BenchmarkWithRateDef):
|
class BenchmarkProcessorDef(BenchmarkWithRateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = BenchmarkProcessor
|
SCHEMA = schemas.BenchmarkProcessor
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkProcessorSysbenchDef(BenchmarkProcessorDef):
|
class BenchmarkProcessorSysbenchDef(BenchmarkProcessorDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = BenchmarkProcessorSysbench
|
SCHEMA = schemas.BenchmarkProcessorSysbench
|
||||||
|
|
||||||
|
|
||||||
class BenchmarkRamSysbenchDef(BenchmarkWithRateDef):
|
class BenchmarkRamSysbenchDef(BenchmarkWithRateDef):
|
||||||
VIEW = None
|
VIEW = None
|
||||||
SCHEMA = BenchmarkRamSysbench
|
SCHEMA = schemas.BenchmarkRamSysbench
|
||||||
|
|
||||||
|
|
||||||
|
class ToRepairDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.ToRepair
|
||||||
|
|
||||||
|
|
||||||
|
class RepairDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.Repair
|
||||||
|
|
||||||
|
|
||||||
|
class ToPrepareDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.ToPrepare
|
||||||
|
|
||||||
|
|
||||||
|
class PrepareDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.Prepare
|
||||||
|
|
||||||
|
|
||||||
|
class ToDisposeDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.ToDispose
|
||||||
|
|
||||||
|
|
||||||
|
class DisposeDef(EventDef):
|
||||||
|
VIEW = None
|
||||||
|
SCHEMA = schemas.Dispose
|
||||||
|
|
|
@ -581,6 +581,30 @@ class BenchmarkRamSysbench(BenchmarkWithRate):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToRepair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Repair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToPrepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Prepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToDispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Dispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# Listeners
|
# Listeners
|
||||||
# Listeners validate values and keep relationships synced
|
# Listeners validate values and keep relationships synced
|
||||||
|
|
||||||
|
|
|
@ -301,3 +301,27 @@ class BenchmarkProcessorSysbench(BenchmarkProcessor):
|
||||||
|
|
||||||
class BenchmarkRamSysbench(BenchmarkWithRate):
|
class BenchmarkRamSysbench(BenchmarkWithRate):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToRepair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Repair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToPrepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Prepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToDispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Dispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
|
@ -5,7 +5,7 @@ from marshmallow.fields import Boolean, DateTime, Float, Integer, List, Nested,
|
||||||
from marshmallow.validate import Length, Range
|
from marshmallow.validate import Length, Range
|
||||||
|
|
||||||
from ereuse_devicehub.marshmallow import NestedOn
|
from ereuse_devicehub.marshmallow import NestedOn
|
||||||
from ereuse_devicehub.resources.device.schemas import Component, Device, Computer
|
from ereuse_devicehub.resources.device.schemas import Component, Computer, Device
|
||||||
from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \
|
from ereuse_devicehub.resources.enums import AppearanceRange, Bios, FunctionalityRange, \
|
||||||
PriceSoftware, RATE_POSITIVE, RatingSoftware, SnapshotExpectedEvents, SnapshotSoftware, \
|
PriceSoftware, RATE_POSITIVE, RatingSoftware, SnapshotExpectedEvents, SnapshotSoftware, \
|
||||||
TestHardDriveLength
|
TestHardDriveLength
|
||||||
|
@ -299,3 +299,27 @@ class BenchmarkProcessorSysbench(BenchmarkProcessor):
|
||||||
|
|
||||||
class BenchmarkRamSysbench(BenchmarkWithRate):
|
class BenchmarkRamSysbench(BenchmarkWithRate):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToRepair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Repair(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToPrepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Prepare(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class ToDispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Dispose(EventWithMultipleDevices):
|
||||||
|
pass
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
from flask import current_app, current_app as app, jsonify
|
from flask import current_app as app, jsonify
|
||||||
from flask_sqlalchemy import Pagination
|
from flask_sqlalchemy import Pagination
|
||||||
from marshmallow import Schema as MarshmallowSchema
|
from marshmallow import Schema as MarshmallowSchema
|
||||||
from marshmallow.fields import Float, Integer, Nested, Str
|
from marshmallow.fields import Float, Integer, Nested, Str
|
||||||
|
@ -35,7 +35,7 @@ class OfType(Str):
|
||||||
|
|
||||||
def _deserialize(self, value, attr, data):
|
def _deserialize(self, value, attr, data):
|
||||||
v = super()._deserialize(value, attr, data)
|
v = super()._deserialize(value, attr, data)
|
||||||
return self.column.in_(current_app.resources[v].subresources_types)
|
return self.column.in_(app.resources[v].subresources_types)
|
||||||
|
|
||||||
|
|
||||||
class Filters(Query):
|
class Filters(Query):
|
||||||
|
|
|
@ -3,15 +3,15 @@ from typing import Tuple
|
||||||
from click import argument, option
|
from click import argument, option
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.tag import schema
|
||||||
from ereuse_devicehub.resources.tag.model import Tag
|
from ereuse_devicehub.resources.tag.model import Tag
|
||||||
from ereuse_devicehub.resources.tag.schema import Tag as TagS
|
|
||||||
from ereuse_devicehub.resources.tag.view import TagView, get_device_from_tag
|
from ereuse_devicehub.resources.tag.view import TagView, get_device_from_tag
|
||||||
from teal.resource import Resource
|
from teal.resource import Resource
|
||||||
from teal.teal import Teal
|
from teal.teal import Teal
|
||||||
|
|
||||||
|
|
||||||
class TagDef(Resource):
|
class TagDef(Resource):
|
||||||
SCHEMA = TagS
|
SCHEMA = schema.Tag
|
||||||
VIEW = TagView
|
VIEW = TagView
|
||||||
|
|
||||||
def __init__(self, app: Teal, import_name=__package__, static_folder=None,
|
def __init__(self, app: Teal, import_name=__package__, static_folder=None,
|
||||||
|
@ -37,7 +37,7 @@ class TagDef(Resource):
|
||||||
@argument('ids', nargs=-1, required=True)
|
@argument('ids', nargs=-1, required=True)
|
||||||
def create_tags(self, ids: Tuple[str], org: str = None, provider: str = None):
|
def create_tags(self, ids: Tuple[str], org: str = None, provider: str = None):
|
||||||
"""Create TAGS and associates them to a specific PROVIDER."""
|
"""Create TAGS and associates them to a specific PROVIDER."""
|
||||||
tag_schema = TagS(only=('id', 'provider', 'org'))
|
tag_schema = schema.Tag(only=('id', 'provider', 'org'))
|
||||||
|
|
||||||
db.session.add_all(
|
db.session.add_all(
|
||||||
Tag(**tag_schema.load({'id': tag_id, 'provider': provider, 'org': org}))
|
Tag(**tag_schema.load({'id': tag_id, 'provider': provider, 'org': org}))
|
||||||
|
|
|
@ -1,16 +1,15 @@
|
||||||
from click import argument, option
|
from click import argument, option
|
||||||
from flask import current_app as app
|
|
||||||
|
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
|
from ereuse_devicehub.resources.user import schemas
|
||||||
from ereuse_devicehub.resources.user.models import Organization, User
|
from ereuse_devicehub.resources.user.models import Organization, User
|
||||||
from ereuse_devicehub.resources.user.schemas import User as UserS
|
|
||||||
from ereuse_devicehub.resources.user.views import UserView, login
|
from ereuse_devicehub.resources.user.views import UserView, login
|
||||||
from teal.db import SQLAlchemy
|
from teal.db import SQLAlchemy
|
||||||
from teal.resource import Converters, Resource
|
from teal.resource import Converters, Resource
|
||||||
|
|
||||||
|
|
||||||
class UserDef(Resource):
|
class UserDef(Resource):
|
||||||
SCHEMA = UserS
|
SCHEMA = schemas.User
|
||||||
VIEW = UserView
|
VIEW = UserView
|
||||||
ID_CONVERTER = Converters.uuid
|
ID_CONVERTER = Converters.uuid
|
||||||
AUTH = True
|
AUTH = True
|
||||||
|
@ -64,5 +63,6 @@ class OrganizationDef(Resource):
|
||||||
|
|
||||||
def init_db(self, db: SQLAlchemy):
|
def init_db(self, db: SQLAlchemy):
|
||||||
"""Creates the default organization."""
|
"""Creates the default organization."""
|
||||||
|
from flask import current_app as app
|
||||||
org = Organization(**app.config.get_namespace('ORGANIZATION_'))
|
org = Organization(**app.config.get_namespace('ORGANIZATION_'))
|
||||||
db.session.add(org)
|
db.session.add(org)
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -35,7 +35,7 @@ setup(
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type='text/markdown',
|
long_description_content_type='text/markdown',
|
||||||
install_requires=[
|
install_requires=[
|
||||||
'teal>=0.2.0a8',
|
'teal>=0.2.0a9',
|
||||||
'marshmallow_enum',
|
'marshmallow_enum',
|
||||||
'ereuse-utils[Naming]>=0.4b1',
|
'ereuse-utils[Naming]>=0.4b1',
|
||||||
'psycopg2-binary',
|
'psycopg2-binary',
|
||||||
|
|
|
@ -35,4 +35,4 @@ def test_api_docs(client: Client):
|
||||||
'scheme': 'basic',
|
'scheme': 'basic',
|
||||||
'name': 'Authorization'
|
'name': 'Authorization'
|
||||||
}
|
}
|
||||||
assert 54 == len(docs['definitions'])
|
assert 60 == len(docs['definitions'])
|
||||||
|
|
|
@ -4,13 +4,13 @@ import pytest
|
||||||
from flask import g
|
from flask import g
|
||||||
from sqlalchemy.util import OrderedSet
|
from sqlalchemy.util import OrderedSet
|
||||||
|
|
||||||
|
from ereuse_devicehub.client import UserClient
|
||||||
from ereuse_devicehub.db import db
|
from ereuse_devicehub.db import db
|
||||||
from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \
|
from ereuse_devicehub.resources.device.models import Desktop, 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 import models
|
||||||
EventWithOneDevice, Install, Ready, StepRandom, StepZero, StressTest, TestDataStorage
|
from tests.conftest import create_user, file
|
||||||
from tests.conftest import create_user
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('app_context')
|
@pytest.mark.usefixtures('app_context')
|
||||||
|
@ -22,7 +22,7 @@ def test_author():
|
||||||
"""
|
"""
|
||||||
user = create_user()
|
user = create_user()
|
||||||
g.user = user
|
g.user = user
|
||||||
e = EventWithOneDevice(device=Device())
|
e = models.EventWithOneDevice(device=Device())
|
||||||
db.session.add(e)
|
db.session.add(e)
|
||||||
assert e.author is None
|
assert e.author is None
|
||||||
assert e.author_id is None
|
assert e.author_id is None
|
||||||
|
@ -32,7 +32,7 @@ def test_author():
|
||||||
|
|
||||||
@pytest.mark.usefixtures('auth_app_context')
|
@pytest.mark.usefixtures('auth_app_context')
|
||||||
def test_erase_basic():
|
def test_erase_basic():
|
||||||
erasure = EraseBasic(
|
erasure = models.EraseBasic(
|
||||||
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
zeros=True,
|
zeros=True,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
|
@ -41,7 +41,7 @@ def test_erase_basic():
|
||||||
)
|
)
|
||||||
db.session.add(erasure)
|
db.session.add(erasure)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db_erasure = EraseBasic.query.one()
|
db_erasure = models.EraseBasic.query.one()
|
||||||
assert erasure == db_erasure
|
assert erasure == db_erasure
|
||||||
assert next(iter(db_erasure.device.events)) == erasure
|
assert next(iter(db_erasure.device.events)) == erasure
|
||||||
|
|
||||||
|
@ -53,7 +53,7 @@ def test_validate_device_data_storage():
|
||||||
with pytest.raises(TypeError,
|
with pytest.raises(TypeError,
|
||||||
message='EraseBasic.device must be a DataStorage '
|
message='EraseBasic.device must be a DataStorage '
|
||||||
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'):
|
'but you passed <GraphicCard None model=\'foo-bar\' S/N=\'foo\'>'):
|
||||||
EraseBasic(
|
models.EraseBasic(
|
||||||
device=GraphicCard(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=GraphicCard(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
clean_with_zeros=True,
|
clean_with_zeros=True,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
|
@ -64,27 +64,27 @@ def test_validate_device_data_storage():
|
||||||
|
|
||||||
@pytest.mark.usefixtures('auth_app_context')
|
@pytest.mark.usefixtures('auth_app_context')
|
||||||
def test_erase_sectors_steps():
|
def test_erase_sectors_steps():
|
||||||
erasure = EraseSectors(
|
erasure = models.EraseSectors(
|
||||||
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=SolidStateDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
zeros=True,
|
zeros=True,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
end_time=datetime.now(),
|
end_time=datetime.now(),
|
||||||
error=False,
|
error=False,
|
||||||
steps=[
|
steps=[
|
||||||
StepZero(error=False,
|
models.StepZero(error=False,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
end_time=datetime.now()),
|
end_time=datetime.now()),
|
||||||
StepRandom(error=False,
|
models.StepRandom(error=False,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
end_time=datetime.now()),
|
end_time=datetime.now()),
|
||||||
StepZero(error=False,
|
models.StepZero(error=False,
|
||||||
start_time=datetime.now(),
|
start_time=datetime.now(),
|
||||||
end_time=datetime.now())
|
end_time=datetime.now())
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
db.session.add(erasure)
|
db.session.add(erasure)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
db_erasure = EraseSectors.query.one()
|
db_erasure = models.EraseSectors.query.one()
|
||||||
# Steps are in order
|
# Steps are in order
|
||||||
assert db_erasure.steps[0].num == 0
|
assert db_erasure.steps[0].num == 0
|
||||||
assert db_erasure.steps[1].num == 1
|
assert db_erasure.steps[1].num == 1
|
||||||
|
@ -93,7 +93,7 @@ def test_erase_sectors_steps():
|
||||||
|
|
||||||
@pytest.mark.usefixtures('auth_app_context')
|
@pytest.mark.usefixtures('auth_app_context')
|
||||||
def test_test_data_storage():
|
def test_test_data_storage():
|
||||||
test = TestDataStorage(
|
test = models.TestDataStorage(
|
||||||
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
device=HardDrive(serial_number='foo', manufacturer='bar', model='foo-bar'),
|
||||||
error=False,
|
error=False,
|
||||||
elapsed=timedelta(minutes=25),
|
elapsed=timedelta(minutes=25),
|
||||||
|
@ -103,13 +103,13 @@ def test_test_data_storage():
|
||||||
)
|
)
|
||||||
db.session.add(test)
|
db.session.add(test)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
assert TestDataStorage.query.one()
|
assert models.TestDataStorage.query.one()
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.usefixtures('auth_app_context')
|
@pytest.mark.usefixtures('auth_app_context')
|
||||||
def test_install():
|
def test_install():
|
||||||
hdd = HardDrive(serial_number='sn')
|
hdd = HardDrive(serial_number='sn')
|
||||||
install = Install(name='LinuxMint 18.04 es',
|
install = models.Install(name='LinuxMint 18.04 es',
|
||||||
elapsed=timedelta(seconds=25),
|
elapsed=timedelta(seconds=25),
|
||||||
device=hdd)
|
device=hdd)
|
||||||
db.session.add(install)
|
db.session.add(install)
|
||||||
|
@ -123,7 +123,7 @@ def test_update_components_event_one():
|
||||||
computer.components.add(hdd)
|
computer.components.add(hdd)
|
||||||
|
|
||||||
# Add event
|
# Add event
|
||||||
test = StressTest(elapsed=timedelta(seconds=1))
|
test = models.StressTest(elapsed=timedelta(seconds=1))
|
||||||
computer.events_one.add(test)
|
computer.events_one.add(test)
|
||||||
assert test.device == computer
|
assert test.device == computer
|
||||||
assert next(iter(test.components)) == hdd, 'Event has to have new components'
|
assert next(iter(test.components)) == hdd, 'Event has to have new components'
|
||||||
|
@ -147,7 +147,7 @@ def test_update_components_event_multiple():
|
||||||
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)
|
||||||
|
|
||||||
ready = Ready()
|
ready = models.Ready()
|
||||||
assert not ready.devices
|
assert not ready.devices
|
||||||
assert not ready.components
|
assert not ready.components
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ def test_update_parent():
|
||||||
computer.components.add(hdd)
|
computer.components.add(hdd)
|
||||||
|
|
||||||
# Add
|
# Add
|
||||||
benchmark = BenchmarkDataStorage()
|
benchmark = models.BenchmarkDataStorage()
|
||||||
benchmark.device = hdd
|
benchmark.device = hdd
|
||||||
assert benchmark.parent == computer
|
assert benchmark.parent == computer
|
||||||
assert not benchmark.components
|
assert not benchmark.components
|
||||||
|
@ -182,3 +182,23 @@ def test_update_parent():
|
||||||
# Remove
|
# Remove
|
||||||
benchmark.device = None
|
benchmark.device = None
|
||||||
assert not benchmark.parent
|
assert not benchmark.parent
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.xfail(reason='No POST view for generic tests')
|
||||||
|
@pytest.mark.parametrize('event_model', [
|
||||||
|
models.ToRepair,
|
||||||
|
models.Repair,
|
||||||
|
models.ToPrepare,
|
||||||
|
models.Prepare,
|
||||||
|
models.ToDispose,
|
||||||
|
models.Dispose,
|
||||||
|
models.Ready
|
||||||
|
])
|
||||||
|
def test_generic_event(event_model: models.Event, user: UserClient):
|
||||||
|
"""Tests POSTing all generic events."""
|
||||||
|
snapshot, _ = user.post(file('basic.snapshot'), res=models.Snapshot)
|
||||||
|
event = {'type': event_model.t, 'devices': [snapshot['device']['id']]}
|
||||||
|
event, _ = user.post(event, res=event_model)
|
||||||
|
assert event['device'][0]['id'] == snapshot['device']['id']
|
||||||
|
device, _ = user.get(res=Device, item=snapshot['device']['id'])
|
||||||
|
assert device['events'][0]['id'] == event['id']
|
||||||
|
|
Reference in a new issue