enhance testing

This commit is contained in:
Xavier Bustamante Talavera 2018-08-03 20:07:05 +02:00
parent 42b0b0ebbc
commit bc433d80e9
10 changed files with 52 additions and 750 deletions

View file

@ -9,6 +9,7 @@ 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]
elapsed: 500 elapsed: 500
device: device:
type: Desktop type: Desktop
@ -25,9 +26,6 @@ device:
functionalityRange: B functionalityRange: B
- type: BenchmarkRamSysbench - type: BenchmarkRamSysbench
rate: 2444 rate: 2444
- type: StressTest
elapsed: 300
error: False
components: components:
- type: GraphicCard - type: GraphicCard
serialNumber: gc1-1s serialNumber: gc1-1s
@ -67,22 +65,11 @@ components:
assessment: True assessment: True
powerCycleCount: 11 powerCycleCount: 11
reallocatedSectorCount: 2 reallocatedSectorCount: 2
powerCycleCount: 4
reportedUncorrectableErrors: 1 reportedUncorrectableErrors: 1
commandTimeout: 11 commandTimeout: 11
currentPendingSectorCount: 1 currentPendingSectorCount: 1
offlineUncorrectable: 33 offlineUncorrectable: 33
remainingLifetimePercentage: 1 remainingLifetimePercentage: 1
- type: EraseSectors
error: False
zeros: False
startTime: 2018-01-01T10:10:10
endTime: 2018-01-01T12:10:10
steps:
- type: StepRandom
startTime: 2018-01-01T10:10:10
endTime: 2018-01-01T12:10:10
error: False
- type: HardDrive - type: HardDrive
serialNumber: hdd1-1s serialNumber: hdd1-1s
model: hdd1-1ml model: hdd1-1ml
@ -91,20 +78,6 @@ components:
- type: BenchmarkDataStorage - type: BenchmarkDataStorage
readSpeed: 10 readSpeed: 10
writeSpeed: 5 writeSpeed: 5
- type: EraseSectors
error: False
zeros: False
startTime: 2018-01-01T10:10:10
endTime: 2018-01-01T12:10:10
steps:
- type: StepRandom
startTime: 2018-01-01T10:10:10
endTime: 2018-01-01T12:10:10
error: False
- type: Install
elapsed: 420
error: False
name: LinuxMint 18.01 32b
- type: Motherboard - type: Motherboard
serialNumber: mb1-1s serialNumber: mb1-1s
model: mb1-1ml model: mb1-1ml

View file

@ -1,17 +0,0 @@
type: Snapshot
software: AndroidApp
version: '1.0'
device:
type: ComputerMonitor
technology: LCD
manufacturer: Dell
model: 1707FPF
serialNumber: CN0FP446728728541C8S
resolutionWidth: 1920
resolutionHeight: 1080
size: 21.5
events:
- type: AppRate
appearanceRange: A
functionalityRange: C
labelling: False

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/computer-monitor.snapshot.yaml

View file

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

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/real-eee-1001pxd.snapshot.11.yaml

View file

@ -1,116 +0,0 @@
{
"elapsed": 4,
"type": "Snapshot",
"uuid": "0c822fb7-6e51-4781-86cf-994bd306212e",
"software": "Workbench",
"closed": false,
"endTime": "2018-07-05T11:57:17.284891",
"components": [
{
"type": "NetworkAdapter",
"model": "82567LM-3 Gigabit Network Connection",
"speed": 1000,
"serialNumber": "00:23:24:0d:86:28",
"manufacturer": "Intel Corporation",
"wireless": false,
"events": []
},
{
"type": "NetworkAdapter",
"model": "82541PI Gigabit Ethernet Controller",
"speed": 1000,
"serialNumber": "00:0e:0c:b6:f2:91",
"manufacturer": "Intel Corporation",
"wireless": false,
"events": []
},
{
"cores": 4,
"type": "Processor",
"model": "Intel Core2 Quad CPU Q8400 @ 2.66GHz",
"speed": 1.9980000000000002,
"serialNumber": null,
"manufacturer": "Intel Corp.",
"events": [],
"address": 64
},
{
"type": "GraphicCard",
"model": "4 Series Chipset Integrated Graphics Controller",
"serialNumber": null,
"manufacturer": "Intel Corporation",
"events": [],
"memory": 256.0
},
{
"type": "SoundCard",
"model": "82801JD/DO HD Audio Controller",
"serialNumber": null,
"manufacturer": "Intel Corporation",
"events": []
},
{
"size": 2048,
"interface": "DDR3",
"type": "RamModule",
"model": "16JTF25664AZ-1G4F",
"speed": 1333.0,
"serialNumber": "F8482E29",
"format": "DIMM",
"manufacturer": "JEDEC ID:80 2C",
"events": []
},
{
"size": 2048,
"interface": "DDR3",
"type": "RamModule",
"model": "16JTF25664AZ-1G4F",
"speed": 1333.0,
"serialNumber": "62072F30",
"format": "DIMM",
"manufacturer": "JEDEC ID:80 2C",
"events": []
},
{
"size": 238475,
"interface": "ATA",
"type": "HardDrive",
"model": "ST3250318AS",
"serialNumber": "9VY6HBKE",
"manufacturer": "Seagate",
"events": [
{
"elapsed": 0,
"type": "TestDataStorage",
"status": "Unspecified Error. Self-test not started.",
"error": true,
"length": "Short"
}
]
},
{
"slots": 0,
"pcmcia": 0,
"type": "Motherboard",
"model": "3646h",
"serialNumber": "CZC03217S7",
"firewire": 0,
"manufacturer": "Hewlett-Packard",
"events": [],
"serial": 0,
"usb": 8
}
],
"version": "11.0a3",
"device": {
"type": "Desktop",
"model": "HP Compaq 8000 Elite SFF",
"chassis": "Tower",
"serialNumber": "CZC03217S7",
"manufacturer": "Hewlett-Packard",
"events": []
},
"expectedEvents": [
"SmartTest"
]
}

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/real-hp-quad-core.snapshot.11.yaml

View file

@ -1,161 +0,0 @@
{
"closed": false,
"uuid": "f9e5e587-baee-44e1-9a94-255d216bbda9",
"components": [
{
"events": [],
"serialNumber": "6c:62:6d:81:22:9f",
"type": "NetworkAdapter",
"manufacturer": "Intel Corporation",
"speed": 1000,
"wireless": false,
"model": "82578DM Gigabit Network Connection"
},
{
"format": "DIMM",
"events": [
],
"interface": "DDR3",
"serialNumber": "B4012F30",
"size": 2048,
"type": "RamModule",
"manufacturer": "JEDEC ID:80 2C",
"speed": 1333.0,
"model": "16JTF25664AZ-1G4F"
},
{
"format": "DIMM",
"events": [],
"interface": "DDR3",
"serialNumber": "8E9F2E29",
"size": 2048,
"type": "RamModule",
"manufacturer": "JEDEC ID:80 2C",
"speed": 1333.0,
"model": "16JTF25664AZ-1G4F"
},
{
"format": "DIMM",
"events": [],
"interface": "DDR3",
"serialNumber": "9A012F30",
"size": 2048,
"type": "RamModule",
"manufacturer": "JEDEC ID:80 2C",
"speed": 1333.0,
"model": "16JTF25664AZ-1G4F"
},
{
"format": "DIMM",
"events": [
],
"interface": "DDR3",
"serialNumber": "8F9F2E29",
"size": 2048,
"type": "RamModule",
"manufacturer": "JEDEC ID:80 2C",
"speed": 1333.0,
"model": "16JTF25664AZ-1G4F"
},
{
"cores": 2,
"events": [
{
"rate": 23410.76,
"type": "BenchmarkProcessor",
"elapsed": 1
},
{
"rate": 17.0186,
"type": "BenchmarkProcessorSysbench",
"elapsed": 18
}
],
"serialNumber": null,
"type": "Processor",
"manufacturer": "Intel Corp.",
"address": 64,
"speed": 1.199,
"model": "Intel Core i3 CPU 530 @ 2.93GHz"
},
{
"events": [
{
"writeSpeed": 24.5,
"readSpeed": 111.0,
"type": "BenchmarkDataStorage",
"elapsed": 14
},
{
"status": "Unspecified Error. Self-test not started.",
"error": true,
"type": "TestDataStorage",
"elapsed": 1,
"length": Short
}
],
"interface": "ATA",
"serialNumber": "WD-WCAV2U909540",
"size": 305245,
"type": "HardDrive",
"manufacturer": "Western Digital",
"model": "WDC WD3200AAJS-6"
},
{
"events": [],
"serialNumber": null,
"type": "SoundCard",
"manufacturer": "Intel Corporation",
"model": "5 Series/3400 Series Chipset High Definition Audio"
},
{
"memory": 256.0,
"events": [],
"serialNumber": null,
"type": "GraphicCard",
"manufacturer": "Intel Corporation",
"model": "Core Processor Integrated Graphics Controller"
},
{
"events": [],
"firewire": 0,
"pcmcia": 0,
"serialNumber": "CZC0408YJG",
"slots": 0,
"type": "Motherboard",
"manufacturer": "Hewlett-Packard",
"usb": 2,
"serial": 0,
"model": "304Ah"
}
],
"software": "Workbench",
"elapsed": 96,
"version": "11.0a1",
"expectedEvents": [
"StressTest",
"Benchmark",
"SmartTest"
],
"device": {
"events": [
{
"type": "StressTest",
"elapsed": 60,
"error": false
},
{
"rate": 0.9759,
"type": "BenchmarkRamSysbench",
"elapsed": 1
}
],
"serialNumber": "CZC0408YJG",
"type": "Desktop",
"manufacturer": "Hewlett-Packard",
"chassis": "Tower",
"model": "HP Compaq 8100 Elite SFF"
},
"type": "Snapshot",
"endTime": "2018-06-29T12:28:54.508266"
}

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/real-hp.snapshot.11.yaml

View file

@ -1,141 +0,0 @@
{
"expectedEvents": [
"SmartTest",
"Benchmark",
"StressTest"
],
"endTime": "2018-06-29T15:29:29.322424",
"elapsed": 391,
"software": "Workbench",
"components": [
{
"serialNumber": null,
"interface": "DDR",
"size": 1024,
"manufacturer": null,
"format": "SODIMM",
"events": [
],
"speed": 533.0,
"type": "RamModule",
"model": null
},
{
"serialNumber": null,
"manufacturer": "Intel Corporation",
"events": [],
"type": "SoundCard",
"model": "NM10/ICH7 Family High Definition Audio Controller"
},
{
"serialNumber": null,
"manufacturer": "Chicony Electronics Co., Ltd.",
"events": [],
"type": "SoundCard",
"model": "USB2.0 UVC WebCam"
},
{
"serialNumber": "00:23:08:a5:07:6d",
"manufacturer": "Qualcomm Atheros",
"events": [],
"type": "NetworkAdapter",
"wireless": true,
"model": "AR9285 Wireless Network Adapter"
},
{
"serialNumber": "00:23:5a:fe:d7:14",
"manufacturer": "Realtek Semiconductor Co., Ltd.",
"events": [],
"speed": 100,
"type": "NetworkAdapter",
"wireless": false,
"model": "RTL810xE PCI Express Fast Ethernet controller"
},
{
"serialNumber": null,
"address": 32,
"manufacturer": "Intel Corp.",
"events": [
{
"rate": 171.3049,
"type": "BenchmarkProcessorSysbench",
"elapsed": 171
},
{
"rate": 6383.9,
"type": "BenchmarkProcessor",
"elapsed": 1
}
],
"speed": 1.3330000000000002,
"type": "Processor",
"model": "Intel Atom CPU N270 @ 1.60GHz"
},
{
"memory": 256.0,
"serialNumber": null,
"manufacturer": "Intel Corporation",
"events": [],
"type": "GraphicCard",
"model": "Mobile 945GSE Express Integrated Graphics Controller"
},
{
"serialNumber": "090623PB5B00QCGREMAH",
"interface": "ATA",
"size": 152627,
"manufacturer": "Hitachi",
"events": [
{
"elapsed": 71,
"readSpeed": 19.1,
"type": "BenchmarkDataStorage",
"writeSpeed": 4.7
},
{
"elapsed": 2,
"status": "Unspecified Error. Self-test not started.",
"type": "TestDataStorage",
"length": Short,
"error": true
}
],
"type": "HardDrive",
"model": "HTS54501"
},
{
"slots": 0,
"serialNumber": "0123456789AB",
"manufacturer": "TOSHIBA",
"firewire": 0,
"events": [],
"pcmcia": 0,
"usb": 5,
"serial": 1,
"type": "Motherboard",
"model": "KAVAA"
}
],
"version": "11.0a1",
"device": {
"serialNumber": "79545417K",
"manufacturer": "TOSHIBA",
"events": [
{
"type": "StressTest",
"error": false,
"elapsed": 120
},
{
"rate": 19.0443,
"type": "BenchmarkRamSysbench",
"elapsed": 19
}
],
"type": "Laptop",
"chassis": "Netbook",
"model": "NB200"
},
"uuid": "918726ae-c6bc-40aa-97cf-ad80d69268f9",
"closed": false,
"type": "Snapshot"
}

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/real-toshiba.snapshot.11.yaml

View file

@ -1,85 +0,0 @@
# 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
# All numbers are invented
type: Snapshot
uuid: cb8ce6b5-6a1b-4084-b5b9-d8fadad2a015
version: '11.0'
software: Workbench
expectedEvents: [TestDataStorage, StressTest, EraseSectors, Install]
elapsed: 500
device:
type: Desktop
chassis: Tower
serialNumber: d1s
model: d1ml
manufacturer: d1mr
tags:
- type: Tag
id: tag1
events:
- 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
events:
- type: BenchmarkProcessor
rate: 2410
- type: BenchmarkProcessorSysbench
rate: 4400
- type: SolidStateDrive
serialNumber: ssd1-1s
model: ssd1-1ml
manufacturer: ssd1-1mr
events:
- type: BenchmarkDataStorage
readSpeed: 20
writeSpeed: 15
elapsed: 21
- type: TestDataStorage
elapsed: 233
error: False
status: Completed without error
length: Short
lifetime: 99
assessment: True
powerCycleCount: 11
reallocatedSectorCount: 2
powerCycleCount: 4
reportedUncorrectableErrors: 1
commandTimeout: 11
currentPendingSectorCount: 1
offlineUncorrectable: 33
remainingLifetimePercentage: 1
- type: HardDrive
serialNumber: hdd1-1s
model: hdd1-1ml
manufacturer: hdd1-1mr
events:
- type: BenchmarkDataStorage
readSpeed: 10
writeSpeed: 5
- type: Motherboard
serialNumber: mb1-1s
model: mb1-1ml
manufacturer: mb1-1mr

View file

@ -0,0 +1 @@
../../ereuse_devicehub/dummy/files/workbench-server-1.snapshot.yaml

View file

@ -22,10 +22,10 @@ from ereuse_devicehub.resources.tag.model import Tag
from ereuse_devicehub.resources.user import User from ereuse_devicehub.resources.user import User
from ereuse_utils.naming import Naming from ereuse_utils.naming import Naming
from teal.db import ResourceNotFound from teal.db import ResourceNotFound
from tests.conftest import file from tests import conftest
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_device_model(): 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.
@ -69,7 +69,7 @@ def test_device_model():
assert GraphicCard.query.first() is None, 'We should have deleted it it was inside the pc' assert GraphicCard.query.first() is None, 'We should have deleted it it was inside the pc'
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_device_schema(): def test_device_schema():
"""Ensures the user does not upload non-writable or extra fields.""" """Ensures the user does not upload non-writable or extra fields."""
device_s = DeviceS() device_s = DeviceS()
@ -77,7 +77,7 @@ def test_device_schema():
device_s.dump(Device(id=1)) device_s.dump(Device(id=1))
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_physical_properties(): def test_physical_properties():
c = Motherboard(slots=2, c = Motherboard(slots=2,
usb=3, usb=3,
@ -107,9 +107,9 @@ def test_physical_properties():
} }
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_component_similar_one(): def test_component_similar_one():
snapshot = file('pc-components.db') snapshot = conftest.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 = Desktop(**d, components=OrderedSet(Component(**c) for c in snapshot['components'])) pc = Desktop(**d, components=OrderedSet(Component(**c) for c in snapshot['components']))
@ -135,7 +135,7 @@ def test_add_remove():
# pc has c1 and c2 # pc has c1 and c2
# pc2 has c3 # pc2 has c3
# c4 is not with any pc # c4 is not with any pc
values = file('pc-components.db') values = conftest.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 = Desktop(**pc, components=OrderedSet([c1, c2])) pc = Desktop(**pc, components=OrderedSet([c1, c2]))
@ -160,13 +160,13 @@ def test_add_remove():
assert events[0].components == OrderedSet([c3]) assert events[0].components == OrderedSet([c3])
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_run_components_empty(): def test_sync_run_components_empty():
""" """
Syncs a device that has an empty components list. The system should Syncs a device that has an empty components list. The system should
remove all the components from the device. remove all the components from the device.
""" """
s = file('pc-components.db') s = conftest.file('pc-components.db')
pc = Desktop(**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()
@ -178,13 +178,13 @@ def test_sync_run_components_empty():
assert not pc.components assert not pc.components
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_run_components_none(): def test_sync_run_components_none():
""" """
Syncs a device that has a None components. The system should Syncs a device that has a None components. The system should
keep all the components from the device. keep all the components from the device.
""" """
s = file('pc-components.db') s = conftest.file('pc-components.db')
pc = Desktop(**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()
@ -196,48 +196,48 @@ def test_sync_run_components_none():
assert db_pc.components == pc.components assert db_pc.components == pc.components
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_execute_register_Desktop_new_Desktop_no_tag(): def test_sync_execute_register_Desktop_new_Desktop_no_tag():
""" """
Syncs a new Desktop 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 = Desktop(**file('pc-components.db')['device']) pc = Desktop(**conftest.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(conftest.app_context.__name__)
def test_sync_execute_register_Desktop_existing_no_tag(): def test_sync_execute_register_Desktop_existing_no_tag():
""" """
Syncs an existing Desktop with HID and without a tag. Syncs an existing Desktop with HID and without a tag.
""" """
pc = Desktop(**file('pc-components.db')['device']) pc = Desktop(**conftest.file('pc-components.db')['device'])
db.session.add(pc) db.session.add(pc)
db.session.commit() db.session.commit()
pc = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object pc = Desktop(**conftest.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(conftest.app_context.__name__)
def test_sync_execute_register_Desktop_no_hid_no_tag(): def test_sync_execute_register_Desktop_no_hid_no_tag():
""" """
Syncs a Desktop 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 = Desktop(**file('pc-components.db')['device']) pc = Desktop(**conftest.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):
Sync().execute_register(pc) Sync().execute_register(pc)
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_execute_register_Desktop_tag_not_linked(): def test_sync_execute_register_Desktop_tag_not_linked():
""" """
Syncs a new Desktop with HID and a non-linked tag. Syncs a new Desktop with HID and a non-linked tag.
@ -249,14 +249,14 @@ def test_sync_execute_register_Desktop_tag_not_linked():
db.session.commit() db.session.commit()
# Create a new transient non-db object # Create a new transient non-db object
pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([Tag(id='FOO')])) pc = Desktop(**conftest.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 Desktop.query.one() == pc, 'Desktop 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(conftest.app_context.__name__)
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 Desktop without HID and a non-linked tag. Validates registering a Desktop without HID and a non-linked tag.
@ -266,7 +266,7 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
be linked), and thus it creates a new Desktop. be linked), and thus it creates a new Desktop.
""" """
tag = Tag(id=tag_id) tag = Tag(id=tag_id)
pc = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([tag])) pc = Desktop(**conftest.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
@ -279,7 +279,7 @@ def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
assert Desktop.query.one() == pc, 'Desktop 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(conftest.app_context.__name__)
def test_sync_execute_register_tag_does_not_exist(): def test_sync_execute_register_tag_does_not_exist():
""" """
Ensures not being able to register if the tag does not exist, Ensures not being able to register if the tag does not exist,
@ -287,12 +287,12 @@ 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 = Desktop(**file('pc-components.db')['device'], tags=OrderedSet([Tag()])) pc = Desktop(**conftest.file('pc-components.db')['device'], tags=OrderedSet([Tag()]))
with raises(ResourceNotFound): with raises(ResourceNotFound):
Sync().execute_register(pc) Sync().execute_register(pc)
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_execute_register_tag_linked_same_device(): def test_sync_execute_register_tag_linked_same_device():
""" """
If the tag is linked to the device, regardless if it has HID, If the tag is linked to the device, regardless if it has HID,
@ -300,11 +300,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 = Desktop(**file('pc-components.db')['device']) orig_pc = Desktop(**conftest.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 = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object pc = Desktop(**conftest.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,28 +312,28 @@ def test_sync_execute_register_tag_linked_same_device():
assert next(iter(db_pc.tags)).id == 'foo' assert next(iter(db_pc.tags)).id == 'foo'
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags(): 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 = Desktop(**file('pc-components.db')['device']) pc1 = Desktop(**conftest.file('pc-components.db')['device'])
db.session.add(Tag(id='foo-1', device=pc1)) db.session.add(Tag(id='foo-1', device=pc1))
pc2 = Desktop(**file('pc-components.db')['device']) pc2 = Desktop(**conftest.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 = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object pc1 = Desktop(**conftest.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):
Sync().execute_register(pc1) Sync().execute_register(pc1)
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_sync_execute_register_mismatch_between_tags_and_hid(): def test_sync_execute_register_mismatch_between_tags_and_hid():
""" """
Checks that sync raises an error if it finds that the HID does Checks that sync raises an error if it finds that the HID does
@ -341,15 +341,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 = Desktop(**file('pc-components.db')['device']) pc1 = Desktop(**conftest.file('pc-components.db')['device'])
db.session.add(Tag(id='foo-1', device=pc1)) db.session.add(Tag(id='foo-1', device=pc1))
pc2 = Desktop(**file('pc-components.db')['device']) pc2 = Desktop(**conftest.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 = Desktop(**file('pc-components.db')['device']) # Create a new transient non-db object pc1 = Desktop(**conftest.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)
@ -418,7 +418,7 @@ def test_get_devices(app: Devicehub, user: UserClient):
'NetworkAdapter', 'GraphicCard') 'NetworkAdapter', 'GraphicCard')
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_computer_monitor(): def test_computer_monitor():
m = ComputerMonitor(technology=DisplayTech.LCD, m = ComputerMonitor(technology=DisplayTech.LCD,
manufacturer='foo', manufacturer='foo',

View file

@ -8,10 +8,10 @@ from ereuse_devicehub.resources.enums import ComputerChassis
from ereuse_devicehub.resources.event.models import Snapshot from ereuse_devicehub.resources.event.models import Snapshot
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
from tests.conftest import file from tests import conftest
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_inventory_filters(): def test_inventory_filters():
schema = Filters() schema = Filters()
q = schema.load({ q = schema.load({
@ -43,7 +43,7 @@ def test_inventory_filters():
'Server', 'Dell%', 'Computer', 'bcn-%'} 'Server', 'Dell%', 'Computer', 'bcn-%'}
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_inventory_sort(): def test_inventory_sort():
schema = Sorting() schema = Sorting()
r = next(schema.load({'created': True})) r = next(schema.load({'created': True}))
@ -96,7 +96,7 @@ def test_inventory_query_filter_sort(user: UserClient):
def test_inventory_query(user: UserClient): def test_inventory_query(user: UserClient):
"""Checks result of inventory.""" """Checks result of inventory."""
user.post(file('basic.snapshot'), res=Snapshot) user.post(conftest.file('basic.snapshot'), res=Snapshot)
i, _ = user.get(res=Inventory) i, _ = user.get(res=Inventory)
pc = next(d for d in i['devices'] if d['type'] == 'Desktop') pc = next(d for d in i['devices'] if d['type'] == 'Desktop')
assert len(pc['events']) == 4 assert len(pc['events']) == 4

View file

@ -12,9 +12,10 @@ 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 teal.db import MultipleResourcesFound, ResourceNotFound from teal.db import MultipleResourcesFound, ResourceNotFound
from teal.marshmallow import ValidationError from teal.marshmallow import ValidationError
from tests import conftest
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_create_tag(): def test_create_tag():
"""Creates a tag specifying a custom organization.""" """Creates a tag specifying a custom organization."""
org = Organization(name='Bar', tax_id='BarTax') org = Organization(name='Bar', tax_id='BarTax')
@ -23,7 +24,7 @@ def test_create_tag():
db.session.commit() db.session.commit()
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_create_tag_default_org(): def test_create_tag_default_org():
"""Creates a tag using the default organization.""" """Creates a tag using the default organization."""
tag = Tag(id='foo-1') tag = Tag(id='foo-1')
@ -36,14 +37,14 @@ def test_create_tag_default_org():
assert tag.org.name == 'FooOrg' # as defined in the settings assert tag.org.name == 'FooOrg' # as defined in the settings
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_create_tag_no_slash(): def test_create_tag_no_slash():
"""Checks that no tags can be created that contain a slash.""" """Checks that no tags can be created that contain a slash."""
with raises(ValidationError): with raises(ValidationError):
Tag(id='/') Tag(id='/')
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_create_two_same_tags(): def test_create_two_same_tags():
"""Ensures there cannot be two tags with the same ID and organization.""" """Ensures there cannot be two tags with the same ID and organization."""
db.session.add(Tag(id='foo-bar')) db.session.add(Tag(id='foo-bar'))