2020-11-13 11:29:37 +00:00
|
|
|
|
import copy
|
2020-11-25 17:42:36 +00:00
|
|
|
|
import datetime
|
2018-05-13 13:13:12 +00:00
|
|
|
|
from uuid import UUID
|
|
|
|
|
|
2022-09-29 09:44:43 +00:00
|
|
|
|
import pytest
|
2018-06-10 16:47:49 +00:00
|
|
|
|
from colour import Color
|
2018-09-20 07:28:52 +00:00
|
|
|
|
from ereuse_utils.naming import Naming
|
2018-10-03 12:51:22 +00:00
|
|
|
|
from ereuse_utils.test import ANY
|
2022-09-29 09:44:43 +00:00
|
|
|
|
from flask import g
|
2018-05-30 10:49:40 +00:00
|
|
|
|
from pytest import raises
|
|
|
|
|
from sqlalchemy.util import OrderedSet
|
2018-09-20 07:28:52 +00:00
|
|
|
|
from teal.db import ResourceNotFound
|
2018-10-23 13:37:37 +00:00
|
|
|
|
from teal.enums import Layouts
|
2018-04-30 17:58:19 +00:00
|
|
|
|
|
2018-10-03 12:51:22 +00:00
|
|
|
|
from ereuse_devicehub.client import Client, UserClient
|
2018-04-10 15:06:39 +00:00
|
|
|
|
from ereuse_devicehub.db import db
|
|
|
|
|
from ereuse_devicehub.devicehub import Devicehub
|
2019-05-11 14:27:22 +00:00
|
|
|
|
from ereuse_devicehub.resources.action import models as m
|
|
|
|
|
from ereuse_devicehub.resources.action.models import Remove, TestConnectivity
|
2018-08-03 16:15:08 +00:00
|
|
|
|
from ereuse_devicehub.resources.agent.models import Person
|
2018-10-23 13:37:37 +00:00
|
|
|
|
from ereuse_devicehub.resources.device import models as d
|
2018-04-27 17:16:43 +00:00
|
|
|
|
from ereuse_devicehub.resources.device.schemas import Device as DeviceS
|
2022-09-29 09:44:43 +00:00
|
|
|
|
from ereuse_devicehub.resources.device.sync import (
|
|
|
|
|
MismatchBetweenTags,
|
|
|
|
|
MismatchBetweenTagsAndHid,
|
|
|
|
|
Sync,
|
|
|
|
|
)
|
|
|
|
|
from ereuse_devicehub.resources.enums import (
|
|
|
|
|
ComputerChassis,
|
|
|
|
|
DisplayTech,
|
|
|
|
|
Severity,
|
|
|
|
|
SnapshotSoftware,
|
|
|
|
|
TransferState,
|
|
|
|
|
)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
from ereuse_devicehub.resources.tag.model import Tag
|
2018-05-13 13:13:12 +00:00
|
|
|
|
from ereuse_devicehub.resources.user import User
|
2018-08-03 18:07:05 +00:00
|
|
|
|
from tests import conftest
|
2022-09-29 09:44:43 +00:00
|
|
|
|
from tests.conftest import file, json_encode, yaml2json
|
2018-04-10 15:06:39 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-11 16:58:48 +00:00
|
|
|
|
def test_device_model():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Tests that the correctness of the device model and its relationships."""
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
model='p1mo',
|
|
|
|
|
manufacturer='p1ma',
|
|
|
|
|
serial_number='p1s',
|
|
|
|
|
chassis=ComputerChassis.Tower,
|
|
|
|
|
)
|
2018-10-23 13:37:37 +00:00
|
|
|
|
net = d.NetworkAdapter(model='c1mo', manufacturer='c1ma', serial_number='c1s')
|
|
|
|
|
graphic = d.GraphicCard(model='c2mo', manufacturer='c2ma', memory=1500)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc.components.add(net)
|
|
|
|
|
pc.components.add(graphic)
|
2018-05-11 16:58:48 +00:00
|
|
|
|
db.session.add(pc)
|
|
|
|
|
db.session.commit()
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc = d.Desktop.query.one()
|
2018-05-11 16:58:48 +00:00
|
|
|
|
assert pc.serial_number == 'p1s'
|
2018-05-30 10:49:40 +00:00
|
|
|
|
assert pc.components == OrderedSet([net, graphic])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
network_adapter = d.NetworkAdapter.query.one()
|
2018-05-11 16:58:48 +00:00
|
|
|
|
assert network_adapter.parent == pc
|
|
|
|
|
|
|
|
|
|
# Removing a component from pc doesn't delete the component
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc.components.remove(net)
|
2018-05-11 16:58:48 +00:00
|
|
|
|
db.session.commit()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Device.query.filter_by(
|
|
|
|
|
id=pc.id
|
|
|
|
|
).first() # this is the same as querying for d.Desktop directly
|
2018-05-30 10:49:40 +00:00
|
|
|
|
assert pc.components == {graphic}
|
2018-10-23 13:37:37 +00:00
|
|
|
|
network_adapter = d.NetworkAdapter.query.one()
|
2018-05-11 16:58:48 +00:00
|
|
|
|
assert network_adapter not in pc.components
|
|
|
|
|
assert network_adapter.parent is None
|
|
|
|
|
|
|
|
|
|
# Deleting the pc deletes everything
|
2018-10-23 13:37:37 +00:00
|
|
|
|
gcard = d.GraphicCard.query.one()
|
2018-05-11 16:58:48 +00:00
|
|
|
|
db.session.delete(pc)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.flush()
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert pc.id == 3
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert d.Desktop.query.first() is None
|
2018-05-11 16:58:48 +00:00
|
|
|
|
db.session.commit()
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert d.Desktop.query.first() is None
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert network_adapter.id == 4
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert d.NetworkAdapter.query.first() is not None, 'We removed the network adaptor'
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert gcard.id == 5, 'We should still hold a reference to a zombie graphic card'
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
d.GraphicCard.query.first() is None
|
|
|
|
|
), 'We should have deleted it –it was inside the pc'
|
2018-04-27 17:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
2018-11-09 10:22:13 +00:00
|
|
|
|
@pytest.mark.xfail(reason='Test not developed')
|
|
|
|
|
def test_device_problems():
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-08-03 18:07:05 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2018-04-27 17:16:43 +00:00
|
|
|
|
def test_device_schema():
|
|
|
|
|
"""Ensures the user does not upload non-writable or extra fields."""
|
|
|
|
|
device_s = DeviceS()
|
2018-04-30 17:58:19 +00:00
|
|
|
|
device_s.load({'serialNumber': 'foo1', 'model': 'foo', 'manufacturer': 'bar2'})
|
2018-10-23 13:37:37 +00:00
|
|
|
|
device_s.dump(d.Device(id=1))
|
2018-04-30 17:58:19 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
def test_physical_properties():
|
2022-09-29 09:44:43 +00:00
|
|
|
|
c = d.Motherboard(
|
|
|
|
|
slots=2,
|
|
|
|
|
usb=3,
|
|
|
|
|
serial_number='sn',
|
|
|
|
|
model='ml',
|
|
|
|
|
manufacturer='mr',
|
|
|
|
|
width=2.0,
|
|
|
|
|
color=Color(),
|
|
|
|
|
)
|
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
chassis=ComputerChassis.Tower,
|
|
|
|
|
model='foo',
|
|
|
|
|
manufacturer='bar',
|
|
|
|
|
serial_number='foo-bar',
|
|
|
|
|
weight=2.8,
|
|
|
|
|
width=1.4,
|
|
|
|
|
height=2.1,
|
|
|
|
|
color=Color('LightSeaGreen'),
|
|
|
|
|
)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc.components.add(c)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
db.session.add(pc)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
assert c.physical_properties == {
|
|
|
|
|
'usb': 3,
|
|
|
|
|
'serial_number': 'sn',
|
2022-09-13 17:53:44 +00:00
|
|
|
|
'part_number': None,
|
2018-04-30 17:58:19 +00:00
|
|
|
|
'pcmcia': None,
|
|
|
|
|
'model': 'ml',
|
|
|
|
|
'slots': 2,
|
|
|
|
|
'serial': None,
|
|
|
|
|
'firewire': None,
|
|
|
|
|
'manufacturer': 'mr',
|
2019-06-29 14:26:14 +00:00
|
|
|
|
'bios_date': None,
|
|
|
|
|
'ram_max_size': None,
|
2022-09-29 09:44:43 +00:00
|
|
|
|
'ram_slots': None,
|
2018-04-30 17:58:19 +00:00
|
|
|
|
}
|
2018-10-13 12:53:46 +00:00
|
|
|
|
assert pc.physical_properties == {
|
2020-07-07 15:17:41 +00:00
|
|
|
|
'chassis': ComputerChassis.Tower,
|
2021-02-05 12:21:20 +00:00
|
|
|
|
'amount': 0,
|
2018-10-13 12:53:46 +00:00
|
|
|
|
'manufacturer': 'bar',
|
2020-07-07 15:17:41 +00:00
|
|
|
|
'model': 'foo',
|
|
|
|
|
'receiver_id': None,
|
2018-10-13 12:53:46 +00:00
|
|
|
|
'serial_number': 'foo-bar',
|
2022-09-13 17:53:44 +00:00
|
|
|
|
'part_number': None,
|
2022-09-29 09:44:43 +00:00
|
|
|
|
'transfer_state': TransferState.Initial,
|
2018-10-13 12:53:46 +00:00
|
|
|
|
}
|
2018-04-30 17:58:19 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
def test_component_similar_one():
|
2020-11-06 16:14:16 +00:00
|
|
|
|
user = User.query.filter().first()
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('pc-components.db')
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc = snapshot['device']
|
2022-09-29 09:44:43 +00:00
|
|
|
|
snapshot['components'][0]['serial_number'] = snapshot['components'][1][
|
|
|
|
|
'serial_number'
|
|
|
|
|
] = None
|
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
**pc, components=OrderedSet(d.Component(**c) for c in snapshot['components'])
|
|
|
|
|
)
|
2018-10-23 13:37:37 +00:00
|
|
|
|
component1, component2 = pc.components # type: d.Component
|
2018-04-30 17:58:19 +00:00
|
|
|
|
db.session.add(pc)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.flush()
|
2018-04-30 17:58:19 +00:00
|
|
|
|
# Let's create a new component named 'A' similar to 1
|
2022-09-29 09:44:43 +00:00
|
|
|
|
componentA = d.Component(
|
|
|
|
|
model=component1.model, manufacturer=component1.manufacturer, owner_id=user.id
|
|
|
|
|
)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
similar_to_a = componentA.similar_one(pc, set())
|
|
|
|
|
assert similar_to_a == component1
|
2018-10-23 13:37:37 +00:00
|
|
|
|
# d.Component B does not have the same model
|
|
|
|
|
componentB = d.Component(model='nope', manufacturer=component1.manufacturer)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
with pytest.raises(ResourceNotFound):
|
|
|
|
|
assert componentB.similar_one(pc, set())
|
|
|
|
|
# If we blacklist component A we won't get anything
|
|
|
|
|
with pytest.raises(ResourceNotFound):
|
|
|
|
|
assert componentA.similar_one(pc, blacklist={componentA.id})
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
def test_add_remove():
|
|
|
|
|
# Original state:
|
|
|
|
|
# pc has c1 and c2
|
|
|
|
|
# pc2 has c3
|
|
|
|
|
# c4 is not with any pc
|
2020-11-06 16:14:16 +00:00
|
|
|
|
user = User.query.filter().first()
|
2021-07-02 15:40:20 +00:00
|
|
|
|
values = yaml2json('pc-components.db')
|
2018-04-30 17:58:19 +00:00
|
|
|
|
pc = values['device']
|
2018-10-23 13:37:37 +00:00
|
|
|
|
c1, c2 = (d.Component(**c) for c in values['components'])
|
|
|
|
|
pc = d.Desktop(**pc, components=OrderedSet([c1, c2]))
|
2018-04-30 17:58:19 +00:00
|
|
|
|
db.session.add(pc)
|
2020-11-06 16:14:16 +00:00
|
|
|
|
c3 = d.Component(serial_number='nc1', owner_id=user.id)
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc2 = d.Desktop(
|
|
|
|
|
serial_number='s2',
|
|
|
|
|
components=OrderedSet([c3]),
|
|
|
|
|
chassis=ComputerChassis.Microtower,
|
|
|
|
|
)
|
2020-11-06 16:14:16 +00:00
|
|
|
|
c4 = d.Component(serial_number='c4s', owner_id=user.id)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
db.session.add(pc2)
|
|
|
|
|
db.session.add(c4)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
# Test:
|
|
|
|
|
# pc has only c3
|
2019-05-11 14:27:22 +00:00
|
|
|
|
actions = Sync.add_remove(device=pc, components={c3, c4})
|
|
|
|
|
db.session.add_all(actions)
|
2018-05-13 13:13:12 +00:00
|
|
|
|
db.session.commit() # We enforce the appliance of order_by
|
2019-05-11 14:27:22 +00:00
|
|
|
|
assert len(actions) == 1
|
|
|
|
|
assert isinstance(actions[0], Remove)
|
|
|
|
|
assert actions[0].device == pc2
|
|
|
|
|
assert actions[0].components == OrderedSet([c3])
|
2018-04-30 17:58:19 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_run_components_empty():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs a device that has an empty components list. The system should
|
2018-05-30 10:49:40 +00:00
|
|
|
|
remove all the components from the device.
|
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
s = yaml2json('pc-components.db')
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
**s['device'], components=OrderedSet(d.Component(**c) for c in s['components'])
|
|
|
|
|
)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(pc)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
# Create a new transient non-db synced object
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc = d.Desktop(**s['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db_pc, _ = Sync().run(pc, components=OrderedSet())
|
|
|
|
|
assert not db_pc.components
|
|
|
|
|
assert not pc.components
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_run_components_none():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs a device that has a None components. The system should
|
2018-05-30 10:49:40 +00:00
|
|
|
|
keep all the components from the device.
|
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
s = yaml2json('pc-components.db')
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
**s['device'], components=OrderedSet(d.Component(**c) for c in s['components'])
|
|
|
|
|
)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(pc)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
# Create a new transient non-db synced object
|
2018-10-23 13:37:37 +00:00
|
|
|
|
transient_pc = d.Desktop(**s['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db_pc, _ = Sync().run(transient_pc, components=None)
|
|
|
|
|
assert db_pc.components
|
|
|
|
|
assert db_pc.components == pc.components
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-10-23 13:37:37 +00:00
|
|
|
|
def test_sync_execute_register_desktop_new_desktop_no_tag():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs a new d.Desktop with HID and without a tag, creating it."""
|
2018-04-30 17:58:19 +00:00
|
|
|
|
# Case 1: device does not exist on DB
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db_pc = Sync().execute_register(pc)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
assert pc.physical_properties == db_pc.physical_properties
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-09-30 10:29:33 +00:00
|
|
|
|
def test_sync_execute_register_desktop_existing_no_tag():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs an existing d.Desktop with HID and without a tag."""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-04-30 17:58:19 +00:00
|
|
|
|
db.session.add(pc)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.commit()
|
|
|
|
|
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc = d.Desktop(
|
2022-09-29 09:44:43 +00:00
|
|
|
|
**yaml2json('pc-components.db')['device']
|
|
|
|
|
) # Create a new transient non-db object
|
2018-04-30 17:58:19 +00:00
|
|
|
|
# 1: device exists on DB
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db_pc = Sync().execute_register(pc)
|
2021-02-05 12:21:20 +00:00
|
|
|
|
pc.amount = 0
|
2020-07-07 15:17:41 +00:00
|
|
|
|
pc.owner_id = db_pc.owner_id
|
|
|
|
|
pc.transfer_state = TransferState.Initial
|
2018-04-30 17:58:19 +00:00
|
|
|
|
assert pc.physical_properties == db_pc.physical_properties
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-08-03 18:07:05 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-07-22 12:22:42 +00:00
|
|
|
|
def test_sync_execute_register_desktop_no_hid_no_tag(user: UserClient):
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs a d.Desktop without HID and no tag.
|
2020-07-23 11:56:19 +00:00
|
|
|
|
This should not fail as we don't have a way to identify it.
|
2018-05-30 10:49:40 +00:00
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
device = yaml2json('pc-components.db')['device']
|
2020-07-22 12:22:42 +00:00
|
|
|
|
device['owner_id'] = user.user['id']
|
|
|
|
|
pc = d.Desktop(**device)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
# 1: device has no HID
|
|
|
|
|
pc.hid = pc.model = None
|
2020-07-23 11:56:19 +00:00
|
|
|
|
returned_pc = Sync().execute_register(pc)
|
|
|
|
|
assert returned_pc == pc
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-09-30 10:29:33 +00:00
|
|
|
|
def test_sync_execute_register_desktop_tag_not_linked():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Syncs a new d.Desktop with HID and a non-linked tag.
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
It is OK if the tag was not linked, it will be linked in this process.
|
|
|
|
|
"""
|
2018-09-30 10:29:33 +00:00
|
|
|
|
tag = Tag(id='foo')
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(tag)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
# Create a new transient non-db object
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
**yaml2json('pc-components.db')['device'], tags=OrderedSet([Tag(id='foo')])
|
|
|
|
|
)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
returned_pc = Sync().execute_register(pc)
|
|
|
|
|
assert returned_pc == pc
|
|
|
|
|
assert tag.device == pc, 'Tag has to be linked'
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert d.Desktop.query.one() == pc, 'd.Desktop had to be set to db'
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_execute_register_no_hid_tag_not_linked(tag_id: str):
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Validates registering a d.Desktop without HID and a non-linked tag.
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
In this case it is ok still, as the non-linked tag proves that
|
2018-10-23 13:37:37 +00:00
|
|
|
|
the d.Desktop was not existing before (otherwise the tag would
|
|
|
|
|
be linked), and thus it creates a new d.Desktop.
|
2018-05-30 10:49:40 +00:00
|
|
|
|
"""
|
|
|
|
|
tag = Tag(id=tag_id)
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc = d.Desktop(**yaml2json('pc-components.db')['device'], tags=OrderedSet([tag]))
|
2020-07-07 15:17:41 +00:00
|
|
|
|
db.session.add(g.user)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
returned_pc = Sync().execute_register(pc)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
assert returned_pc == pc
|
|
|
|
|
db_tag = next(iter(returned_pc.tags))
|
|
|
|
|
# they are not the same tags though
|
|
|
|
|
# tag is a transient obj and db_tag the one from the db
|
|
|
|
|
# they have the same pk though
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert d.Desktop.query.one() == pc, 'd.Desktop had to be set to db'
|
2021-10-22 20:34:32 +00:00
|
|
|
|
assert tag != db_tag, 'They are not the same tags though'
|
|
|
|
|
for tag in pc.tags:
|
|
|
|
|
assert tag.id in ['foo', pc.devicehub_id]
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2020-11-06 16:14:16 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_execute_register_tag_does_not_exist():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Ensures not being able to register if the tag does not exist,
|
2018-05-30 10:49:40 +00:00
|
|
|
|
even if the device has HID or it existed before.
|
|
|
|
|
|
|
|
|
|
Tags have to be created before trying to link them through a Snapshot.
|
|
|
|
|
"""
|
2020-11-06 16:14:16 +00:00
|
|
|
|
user = User.query.filter().first()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
**yaml2json('pc-components.db')['device'], tags=OrderedSet([Tag('foo')])
|
|
|
|
|
)
|
2020-11-06 16:14:16 +00:00
|
|
|
|
pc.owner_id = user.id
|
2018-05-30 10:49:40 +00:00
|
|
|
|
with raises(ResourceNotFound):
|
|
|
|
|
Sync().execute_register(pc)
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_execute_register_tag_linked_same_device():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""If the tag is linked to the device, regardless if it has HID,
|
2018-05-30 10:49:40 +00:00
|
|
|
|
the system should match the device through the tag.
|
|
|
|
|
(If it has HID it validates both HID and tag point at the same
|
|
|
|
|
device, this his checked in ).
|
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
orig_pc = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(Tag(id='foo', device=orig_pc))
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc = d.Desktop(
|
2022-09-29 09:44:43 +00:00
|
|
|
|
**yaml2json('pc-components.db')['device']
|
|
|
|
|
) # Create a new transient non-db object
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc.tags.add(Tag(id='foo'))
|
|
|
|
|
db_pc = Sync().execute_register(pc)
|
|
|
|
|
assert db_pc.id == orig_pc.id
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(db_pc.tags) == 1
|
2021-10-22 20:34:32 +00:00
|
|
|
|
for tag in db_pc.tags:
|
|
|
|
|
assert tag.id in ['foo', db_pc.devicehub_id]
|
2018-05-30 10:49:40 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_execute_register_tag_linked_other_device_mismatch_between_tags():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Checks that sync raises an error if finds that at least two passed-in
|
2018-05-30 10:49:40 +00:00
|
|
|
|
tags are not linked to the same device.
|
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc1 = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(Tag(id='foo-1', device=pc1))
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc2 = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc2.serial_number = 'pc2-serial'
|
2019-01-02 16:52:43 +00:00
|
|
|
|
pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model, pc2.serial_number)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(Tag(id='foo-2', device=pc2))
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc1 = d.Desktop(
|
2022-09-29 09:44:43 +00:00
|
|
|
|
**yaml2json('pc-components.db')['device']
|
|
|
|
|
) # Create a new transient non-db object
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc1.tags.add(Tag(id='foo-1'))
|
|
|
|
|
pc1.tags.add(Tag(id='foo-2'))
|
|
|
|
|
with raises(MismatchBetweenTags):
|
|
|
|
|
Sync().execute_register(pc1)
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
def test_sync_execute_register_mismatch_between_tags_and_hid():
|
2019-06-19 11:35:26 +00:00
|
|
|
|
"""Checks that sync raises an error if it finds that the HID does
|
2018-05-30 10:49:40 +00:00
|
|
|
|
not point at the same device as the tag does.
|
|
|
|
|
|
|
|
|
|
In this case we set HID -> pc1 but tag -> pc2
|
|
|
|
|
"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc1 = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(Tag(id='foo-1', device=pc1))
|
2021-07-02 15:40:20 +00:00
|
|
|
|
pc2 = d.Desktop(**yaml2json('pc-components.db')['device'])
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc2.serial_number = 'pc2-serial'
|
2019-01-02 16:52:43 +00:00
|
|
|
|
pc2.hid = Naming.hid(pc2.type, pc2.manufacturer, pc2.model, pc2.serial_number)
|
2018-05-30 10:49:40 +00:00
|
|
|
|
db.session.add(Tag(id='foo-2', device=pc2))
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
2018-10-23 13:37:37 +00:00
|
|
|
|
pc1 = d.Desktop(
|
2022-09-29 09:44:43 +00:00
|
|
|
|
**yaml2json('pc-components.db')['device']
|
|
|
|
|
) # Create a new transient non-db object
|
2018-05-30 10:49:40 +00:00
|
|
|
|
pc1.tags.add(Tag(id='foo-2'))
|
|
|
|
|
with raises(MismatchBetweenTagsAndHid):
|
|
|
|
|
Sync().execute_register(pc1)
|
2018-04-30 17:58:19 +00:00
|
|
|
|
|
2018-05-11 16:58:48 +00:00
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2021-04-16 10:45:14 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
|
def test_get_device(user: UserClient):
|
2018-10-23 13:37:37 +00:00
|
|
|
|
"""Checks GETting a d.Desktop with its components."""
|
2021-10-22 20:34:32 +00:00
|
|
|
|
g.user = User.query.one()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
model='p1mo',
|
|
|
|
|
manufacturer='p1ma',
|
|
|
|
|
serial_number='p1s',
|
|
|
|
|
chassis=ComputerChassis.Tower,
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
)
|
|
|
|
|
pc.components = OrderedSet(
|
|
|
|
|
[
|
|
|
|
|
d.NetworkAdapter(
|
|
|
|
|
model='c1mo',
|
|
|
|
|
manufacturer='c1ma',
|
|
|
|
|
serial_number='c1s',
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
),
|
|
|
|
|
d.GraphicCard(
|
|
|
|
|
model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
db.session.add(pc)
|
|
|
|
|
# todo test is an abstract class. replace with another one
|
2022-09-29 09:44:43 +00:00
|
|
|
|
db.session.add(
|
|
|
|
|
TestConnectivity(
|
|
|
|
|
device=pc,
|
|
|
|
|
severity=Severity.Info,
|
|
|
|
|
agent=Person(name='Timmy'),
|
|
|
|
|
author=User(email='bar@bar.com'),
|
|
|
|
|
)
|
|
|
|
|
)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
db.session.commit()
|
2021-04-16 16:16:07 +00:00
|
|
|
|
pc_api, _ = user.get(res=d.Device, item=pc.devicehub_id)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert len(pc_api['actions']) == 1
|
|
|
|
|
assert pc_api['actions'][0]['type'] == 'TestConnectivity'
|
|
|
|
|
assert pc_api['actions'][0]['device'] == pc.id
|
|
|
|
|
assert pc_api['actions'][0]['severity'] == 'Info'
|
|
|
|
|
assert UUID(pc_api['actions'][0]['author'])
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
'actions_components' not in pc_api
|
|
|
|
|
), 'actions_components are internal use only'
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert 'actions_one' not in pc_api, 'they are internal use only'
|
|
|
|
|
assert 'author' not in pc_api
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert tuple(c['id'] for c in pc_api['components']) == tuple(
|
|
|
|
|
c.id for c in pc.components
|
|
|
|
|
)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert pc_api['hid'] == 'desktop-p1ma-p1mo-p1s'
|
|
|
|
|
assert pc_api['model'] == 'p1mo'
|
|
|
|
|
assert pc_api['manufacturer'] == 'p1ma'
|
|
|
|
|
assert pc_api['serialNumber'] == 'p1s'
|
|
|
|
|
assert pc_api['type'] == d.Desktop.t
|
2018-05-11 16:58:48 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2021-04-16 10:45:14 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2018-05-11 16:58:48 +00:00
|
|
|
|
def test_get_devices(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks GETting multiple devices."""
|
2021-10-22 20:34:32 +00:00
|
|
|
|
g.user = User.query.one()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
pc = d.Desktop(
|
|
|
|
|
model='p1mo',
|
|
|
|
|
manufacturer='p1ma',
|
|
|
|
|
serial_number='p1s',
|
|
|
|
|
chassis=ComputerChassis.Tower,
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
)
|
|
|
|
|
pc.components = OrderedSet(
|
|
|
|
|
[
|
|
|
|
|
d.NetworkAdapter(
|
|
|
|
|
model='c1mo',
|
|
|
|
|
manufacturer='c1ma',
|
|
|
|
|
serial_number='c1s',
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
),
|
|
|
|
|
d.GraphicCard(
|
|
|
|
|
model='c2mo', manufacturer='c2ma', memory=1500, owner_id=user.user['id']
|
|
|
|
|
),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
pc1 = d.Desktop(
|
|
|
|
|
model='p2mo',
|
|
|
|
|
manufacturer='p2ma',
|
|
|
|
|
serial_number='p2s',
|
|
|
|
|
chassis=ComputerChassis.Tower,
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
)
|
|
|
|
|
pc2 = d.Laptop(
|
|
|
|
|
model='p3mo',
|
|
|
|
|
manufacturer='p3ma',
|
|
|
|
|
serial_number='p3s',
|
|
|
|
|
chassis=ComputerChassis.Netbook,
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
db.session.add_all((pc, pc1, pc2))
|
|
|
|
|
db.session.commit()
|
2018-10-23 13:37:37 +00:00
|
|
|
|
devices, _ = user.get(res=d.Device)
|
2021-04-16 10:45:14 +00:00
|
|
|
|
ids = (pc.id, pc1.id, pc2.id, pc.components[0].id, pc.components[1].id)
|
|
|
|
|
assert tuple(dev['id'] for dev in devices['items']) == ids
|
2018-10-23 13:37:37 +00:00
|
|
|
|
assert tuple(dev['type'] for dev in devices['items']) == (
|
2022-09-29 09:44:43 +00:00
|
|
|
|
d.Desktop.t,
|
|
|
|
|
d.Desktop.t,
|
|
|
|
|
d.Laptop.t,
|
|
|
|
|
d.NetworkAdapter.t,
|
|
|
|
|
d.GraphicCard.t,
|
2018-09-29 10:24:22 +00:00
|
|
|
|
)
|
2018-06-20 21:18:15 +00:00
|
|
|
|
|
|
|
|
|
|
2020-09-22 10:52:15 +00:00
|
|
|
|
@pytest.mark.mvp
|
2022-08-31 15:25:38 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2022-09-29 09:44:43 +00:00
|
|
|
|
def test_get_device_permissions(
|
|
|
|
|
app: Devicehub, user: UserClient, user2: UserClient, client: Client
|
|
|
|
|
):
|
2020-09-22 10:52:15 +00:00
|
|
|
|
"""Checks GETting a d.Desktop with its components."""
|
|
|
|
|
|
2020-11-06 16:14:16 +00:00
|
|
|
|
s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc, res = user.get(res=d.Device, item=s['device']['devicehubID'])
|
2020-09-22 10:52:15 +00:00
|
|
|
|
assert res.status_code == 200
|
2022-08-31 15:25:38 +00:00
|
|
|
|
assert len(pc['actions']) == 0
|
|
|
|
|
pc = d.Device.query.filter_by(devicehub_id=s['device']['devicehubID']).one()
|
|
|
|
|
assert len(pc.placeholder.binding.actions) == 7
|
2020-09-22 10:52:15 +00:00
|
|
|
|
|
2021-03-08 21:43:24 +00:00
|
|
|
|
html, _ = client.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY)
|
2020-11-06 16:14:16 +00:00
|
|
|
|
assert 'intel atom cpu n270 @ 1.60ghz' in html
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc2, res2 = user2.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY)
|
2020-09-22 10:52:15 +00:00
|
|
|
|
assert res2.status_code == 200
|
2020-11-06 16:14:16 +00:00
|
|
|
|
assert pc2 == html
|
2020-09-22 10:52:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserClient):
|
|
|
|
|
"""Checks GETting multiple devices."""
|
|
|
|
|
|
|
|
|
|
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
|
|
|
|
url = '/devices/?filter={"type":["Computer"]}'
|
|
|
|
|
|
|
|
|
|
devices, res = user.get(url, None)
|
|
|
|
|
devices2, res2 = user2.get(url, None)
|
|
|
|
|
assert res.status_code == 200
|
|
|
|
|
assert res2.status_code == 200
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(devices['items']) == 2
|
2020-09-22 10:52:15 +00:00
|
|
|
|
assert len(devices2['items']) == 0
|
|
|
|
|
|
2021-08-17 09:06:04 +00:00
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
2021-11-18 10:48:57 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
|
|
|
|
def test_get_devices_unassigned(user: UserClient):
|
2021-08-17 09:06:04 +00:00
|
|
|
|
"""Checks GETting multiple devices."""
|
|
|
|
|
|
|
|
|
|
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
|
|
|
|
url = '/devices/?filter={"type":["Computer"]}&unassign=0'
|
|
|
|
|
|
|
|
|
|
devices, res = user.get(url, None)
|
|
|
|
|
assert res.status_code == 200
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(devices['items']) == 2
|
2021-08-17 09:06:04 +00:00
|
|
|
|
|
2021-08-17 09:22:50 +00:00
|
|
|
|
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
|
|
|
|
|
|
|
|
|
|
devices, res = user.get(url, None)
|
|
|
|
|
assert res.status_code == 200
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(devices['items']) == 2
|
2021-08-17 09:22:50 +00:00
|
|
|
|
|
|
|
|
|
from ereuse_devicehub.resources.lot.models import Lot
|
2022-09-29 09:44:43 +00:00
|
|
|
|
|
2021-08-17 09:22:50 +00:00
|
|
|
|
device_id = devices['items'][0]['id']
|
|
|
|
|
my_lot, _ = user.post(({'name': 'My_lot'}), res=Lot)
|
2022-09-29 09:44:43 +00:00
|
|
|
|
lot, _ = user.post(
|
|
|
|
|
{}, res=Lot, item='{}/devices'.format(my_lot['id']), query=[('id', device_id)]
|
|
|
|
|
)
|
2021-11-18 10:48:57 +00:00
|
|
|
|
lot = Lot.query.filter_by(id=lot['id']).one()
|
|
|
|
|
assert next(iter(lot.devices)).id == device_id
|
2021-08-17 09:22:50 +00:00
|
|
|
|
|
|
|
|
|
url = '/devices/?filter={"type":["Computer"]}&unassign=0'
|
|
|
|
|
|
|
|
|
|
devices, res = user.get(url, None)
|
|
|
|
|
assert res.status_code == 200
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(devices['items']) == 2
|
2021-08-17 09:22:50 +00:00
|
|
|
|
|
|
|
|
|
url = '/devices/?filter={"type":["Computer"]}&unassign=1'
|
|
|
|
|
|
|
|
|
|
devices, res = user.get(url, None)
|
|
|
|
|
assert res.status_code == 200
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(devices['items']) == 1
|
2021-08-17 09:22:50 +00:00
|
|
|
|
|
2021-08-17 09:06:04 +00:00
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
@pytest.mark.usefixtures(conftest.auth_app_context.__name__)
|
2018-06-20 21:18:15 +00:00
|
|
|
|
def test_computer_monitor():
|
2022-09-29 09:44:43 +00:00
|
|
|
|
m = d.ComputerMonitor(
|
|
|
|
|
technology=DisplayTech.LCD,
|
|
|
|
|
manufacturer='foo',
|
|
|
|
|
model='bar',
|
|
|
|
|
serial_number='foo-bar',
|
|
|
|
|
resolution_width=1920,
|
|
|
|
|
resolution_height=1080,
|
|
|
|
|
size=14.5,
|
|
|
|
|
)
|
2018-06-20 21:18:15 +00:00
|
|
|
|
db.session.add(m)
|
|
|
|
|
db.session.commit()
|
2018-06-26 13:35:13 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-09-30 17:40:28 +00:00
|
|
|
|
def test_manufacturer(user: UserClient):
|
2018-10-18 11:08:42 +00:00
|
|
|
|
m, r = user.get(res='Manufacturer', query=[('search', 'asus')])
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert m == {
|
|
|
|
|
'items': [{'name': 'Asus', 'url': 'https://en.wikipedia.org/wiki/Asus'}]
|
|
|
|
|
}
|
2018-10-03 12:51:22 +00:00
|
|
|
|
assert r.cache_control.public
|
2022-09-29 09:42:50 +00:00
|
|
|
|
assert r.expires.timestamp() > datetime.datetime.now().timestamp()
|
2018-09-30 17:40:28 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-09-30 17:40:28 +00:00
|
|
|
|
@pytest.mark.xfail(reason='Develop functionality')
|
|
|
|
|
def test_manufacturer_enforced():
|
|
|
|
|
"""Ensures that non-computer devices can submit only
|
2019-06-19 11:35:26 +00:00
|
|
|
|
manufacturers from the Manufacturer table.
|
|
|
|
|
"""
|
2018-10-03 12:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-10-03 12:51:22 +00:00
|
|
|
|
def test_device_properties_format(app: Devicehub, user: UserClient):
|
|
|
|
|
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
|
|
|
|
with app.app_context():
|
2022-07-18 15:57:23 +00:00
|
|
|
|
pc = d.Laptop.query.filter_by(placeholder=None).one() # type: d.Laptop
|
2021-04-16 10:45:14 +00:00
|
|
|
|
assert format(pc) == 'Laptop 3: model 1000h, S/N 94oaaq021116'
|
2018-10-16 14:30:10 +00:00
|
|
|
|
assert format(pc, 't') == 'Netbook 1000h'
|
|
|
|
|
assert format(pc, 's') == '(asustek computer inc.) S/N 94OAAQ021116'
|
2018-10-03 12:51:22 +00:00
|
|
|
|
assert pc.ram_size == 1024
|
|
|
|
|
assert pc.data_storage_size == 152627
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
pc.graphic_card_model
|
|
|
|
|
== 'mobile 945gse express integrated graphics controller'
|
|
|
|
|
)
|
2018-10-03 12:51:22 +00:00
|
|
|
|
assert pc.processor_model == 'intel atom cpu n270 @ 1.60ghz'
|
2018-10-23 13:37:37 +00:00
|
|
|
|
net = next(c for c in pc.components if isinstance(c, d.NetworkAdapter))
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
format(net) == 'NetworkAdapter 5: model ar8121/ar8113/ar8114 '
|
|
|
|
|
'gigabit or fast ethernet, S/N 00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
|
|
|
|
assert (
|
|
|
|
|
format(net, 't')
|
|
|
|
|
== 'NetworkAdapter ar8121/ar8113/ar8114 gigabit or fast ethernet'
|
|
|
|
|
)
|
2019-07-07 19:36:09 +00:00
|
|
|
|
assert format(net, 's') == 'qualcomm atheros 00:24:8C:7F:CF:2D – 100 Mbps'
|
2018-10-23 13:37:37 +00:00
|
|
|
|
hdd = next(c for c in pc.components if isinstance(c, d.DataStorage))
|
2022-07-18 15:57:23 +00:00
|
|
|
|
assert format(hdd) == 'HardDrive 10: model st9160310as, S/N 5sv4tqa6'
|
2018-10-03 12:51:22 +00:00
|
|
|
|
assert format(hdd, 't') == 'HardDrive st9160310as'
|
2019-07-07 19:36:09 +00:00
|
|
|
|
assert format(hdd, 's') == 'seagate 5SV4TQA6 – 152 GB'
|
2018-10-03 12:51:22 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-10-03 12:51:22 +00:00
|
|
|
|
def test_device_public(user: UserClient, client: Client):
|
|
|
|
|
s, _ = user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
html, _ = client.get(res=d.Device, item=s['device']['devicehubID'], accept=ANY)
|
2018-10-03 12:51:22 +00:00
|
|
|
|
assert 'intel atom cpu n270 @ 1.60ghz' in html
|
2018-10-23 13:37:37 +00:00
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-10-23 13:37:37 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-03 19:26:32 +00:00
|
|
|
|
def test_computer_accessory_model(user: UserClient):
|
2021-10-22 20:34:32 +00:00
|
|
|
|
g.user = User.query.one()
|
2020-11-03 19:26:32 +00:00
|
|
|
|
sai = d.SAI(owner_id=user.user['id'])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
db.session.add(sai)
|
2020-11-03 19:26:32 +00:00
|
|
|
|
keyboard = d.Keyboard(layout=Layouts.ES, owner_id=user.user['id'])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
db.session.add(keyboard)
|
2020-11-03 19:26:32 +00:00
|
|
|
|
mouse = d.Mouse(owner_id=user.user['id'])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
db.session.add(mouse)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
2020-07-07 15:17:41 +00:00
|
|
|
|
@pytest.mark.mvp
|
2018-10-23 13:37:37 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-03 19:26:32 +00:00
|
|
|
|
def test_networking_model(user: UserClient):
|
2021-10-22 20:34:32 +00:00
|
|
|
|
g.user = User.query.one()
|
2020-11-03 19:26:32 +00:00
|
|
|
|
router = d.Router(speed=1000, wireless=True, owner_id=user.user['id'])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
db.session.add(router)
|
2020-11-03 19:26:32 +00:00
|
|
|
|
switch = d.Switch(speed=1000, wireless=False, owner_id=user.user['id'])
|
2018-10-23 13:37:37 +00:00
|
|
|
|
db.session.add(switch)
|
|
|
|
|
db.session.commit()
|
2018-11-12 10:59:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-05 15:31:57 +00:00
|
|
|
|
def test_cooking_mixer(user: UserClient):
|
2022-09-29 09:44:43 +00:00
|
|
|
|
mixer = d.Mixer(
|
|
|
|
|
serial_number='foo',
|
|
|
|
|
model='bar',
|
|
|
|
|
manufacturer='foobar',
|
|
|
|
|
owner_id=user.user['id'],
|
|
|
|
|
)
|
2018-11-12 10:59:49 +00:00
|
|
|
|
db.session.add(mixer)
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_cooking_mixer_api(user: UserClient):
|
|
|
|
|
snapshot, _ = user.post(
|
|
|
|
|
{
|
|
|
|
|
'type': 'Snapshot',
|
|
|
|
|
'device': {
|
|
|
|
|
'serialNumber': 'foo',
|
|
|
|
|
'model': 'bar',
|
|
|
|
|
'manufacturer': 'foobar',
|
2022-09-29 09:44:43 +00:00
|
|
|
|
'type': 'Mixer',
|
2018-11-12 10:59:49 +00:00
|
|
|
|
},
|
|
|
|
|
'version': '11.0',
|
2022-09-29 09:44:43 +00:00
|
|
|
|
'software': SnapshotSoftware.Web.name,
|
2018-11-12 10:59:49 +00:00
|
|
|
|
},
|
2022-09-29 09:44:43 +00:00
|
|
|
|
res=m.Snapshot,
|
2018-11-12 10:59:49 +00:00
|
|
|
|
)
|
|
|
|
|
mixer, _ = user.get(res=d.Device, item=snapshot['device']['id'])
|
|
|
|
|
assert mixer['type'] == 'Mixer'
|
|
|
|
|
assert mixer['serialNumber'] == 'foo'
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
2022-08-31 15:25:38 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
def test_hid_with_mac(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid with mac."""
|
|
|
|
|
snapshot = file('asus-eee-1000h.snapshot.11')
|
2021-03-08 21:43:24 +00:00
|
|
|
|
snap, _ = user.post(snapshot, res=m.Snapshot)
|
|
|
|
|
pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID'])
|
2022-08-31 15:25:38 +00:00
|
|
|
|
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
|
|
|
|
|
pc = d.Device.query.filter_by(devicehub_id=snap['device']['devicehubID']).one()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
pc.placeholder.binding.hid
|
|
|
|
|
== 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
def test_hid_without_mac(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid without mac."""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('asus-eee-1000h.snapshot.11')
|
2022-09-29 09:44:43 +00:00
|
|
|
|
snapshot['components'] = [
|
|
|
|
|
c for c in snapshot['components'] if c['type'] != 'NetworkAdapter'
|
|
|
|
|
]
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snap, _ = user.post(json_encode(snapshot), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID'])
|
2020-11-13 11:29:37 +00:00
|
|
|
|
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
def test_hid_with_mac_none(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid with mac = None."""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('asus-eee-1000h.snapshot.11')
|
2020-11-13 11:29:37 +00:00
|
|
|
|
network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0]
|
|
|
|
|
network['serialNumber'] = None
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snap, _ = user.post(json_encode(snapshot), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID'])
|
2020-11-13 11:29:37 +00:00
|
|
|
|
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
|
|
|
|
def test_hid_with_2networkadapters(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid with 2 networks adapters"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('asus-eee-1000h.snapshot.11')
|
2020-11-13 11:29:37 +00:00
|
|
|
|
network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0]
|
|
|
|
|
network2 = copy.copy(network)
|
|
|
|
|
snapshot['components'].append(network2)
|
|
|
|
|
network['serialNumber'] = 'a0:24:8c:7f:cf:2d'
|
2021-07-02 15:40:20 +00:00
|
|
|
|
user.post(json_encode(snapshot), res=m.Snapshot)
|
2020-11-13 11:44:20 +00:00
|
|
|
|
devices, _ = user.get(res=d.Device)
|
2020-11-13 12:05:25 +00:00
|
|
|
|
|
|
|
|
|
laptop = devices['items'][0]
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
laptop['hid']
|
|
|
|
|
== 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
2022-08-31 15:25:38 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
def test_hid_with_2network_and_drop_no_mac_in_hid(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid with 2 networks adapters and next drop the network is not used in hid"""
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('asus-eee-1000h.snapshot.11')
|
2020-11-13 11:29:37 +00:00
|
|
|
|
network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0]
|
|
|
|
|
network2 = copy.copy(network)
|
|
|
|
|
snapshot['components'].append(network2)
|
|
|
|
|
network['serialNumber'] = 'a0:24:8c:7f:cf:2d'
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snap, _ = user.post(json_encode(snapshot), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID'])
|
2022-08-31 15:25:38 +00:00
|
|
|
|
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
|
|
|
|
|
pc = d.Device.query.filter_by(devicehub_id=snap['device']['devicehubID']).one()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
pc.placeholder.binding.hid
|
|
|
|
|
== 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb'
|
|
|
|
|
snapshot['components'] = [c for c in snapshot['components'] if c != network]
|
2021-07-02 15:40:20 +00:00
|
|
|
|
user.post(json_encode(snapshot), res=m.Snapshot)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
devices, _ = user.get(res=d.Device)
|
2020-11-13 12:05:25 +00:00
|
|
|
|
laptop = devices['items'][0]
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
pc.placeholder.binding.hid
|
|
|
|
|
== 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len([c for c in devices['items'] if c['type'] == 'Laptop']) == 2
|
2020-11-13 12:05:25 +00:00
|
|
|
|
assert len([c for c in laptop['components'] if c['type'] == 'NetworkAdapter']) == 1
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.mvp
|
2022-08-31 15:25:38 +00:00
|
|
|
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
def test_hid_with_2network_and_drop_mac_in_hid(app: Devicehub, user: UserClient):
|
|
|
|
|
"""Checks hid with 2 networks adapters and next drop the network is used in hid"""
|
|
|
|
|
# One tipical snapshot with 2 network cards
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snapshot = yaml2json('asus-eee-1000h.snapshot.11')
|
2020-11-13 11:29:37 +00:00
|
|
|
|
network = [c for c in snapshot['components'] if c['type'] == 'NetworkAdapter'][0]
|
|
|
|
|
network2 = copy.copy(network)
|
|
|
|
|
snapshot['components'].append(network2)
|
|
|
|
|
network['serialNumber'] = 'a0:24:8c:7f:cf:2d'
|
2021-07-02 15:40:20 +00:00
|
|
|
|
snap, _ = user.post(json_encode(snapshot), res=m.Snapshot)
|
2021-03-08 21:43:24 +00:00
|
|
|
|
pc, _ = user.get(res=d.Device, item=snap['device']['devicehubID'])
|
2022-08-31 15:25:38 +00:00
|
|
|
|
assert pc['hid'] == 'laptop-asustek_computer_inc-1000h-94oaaq021116'
|
|
|
|
|
pc = d.Device.query.filter_by(devicehub_id=snap['device']['devicehubID']).one()
|
2022-09-29 09:44:43 +00:00
|
|
|
|
assert (
|
|
|
|
|
pc.placeholder.binding.hid
|
|
|
|
|
== 'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d'
|
|
|
|
|
)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
|
|
|
|
|
# we drop the network card then is used for to build the hid
|
|
|
|
|
snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abb'
|
|
|
|
|
snapshot['components'] = [c for c in snapshot['components'] if c != network2]
|
2021-07-02 15:40:20 +00:00
|
|
|
|
user.post(json_encode(snapshot), res=m.Snapshot)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
devices, _ = user.get(res=d.Device)
|
|
|
|
|
laptops = [c for c in devices['items'] if c['type'] == 'Laptop']
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(laptops) == 4
|
|
|
|
|
hids = [laptops[0]['hid'], laptops[2]['hid']]
|
2022-09-29 09:44:43 +00:00
|
|
|
|
proof_hid = [
|
|
|
|
|
'laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d',
|
|
|
|
|
'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d',
|
|
|
|
|
]
|
2020-11-13 11:29:37 +00:00
|
|
|
|
assert all([h in proof_hid for h in hids])
|
|
|
|
|
|
|
|
|
|
# we drop all network cards
|
|
|
|
|
snapshot['uuid'] = 'd1b70cb8-8929-4f36-99b7-fe052cec0abc'
|
2022-09-29 09:44:43 +00:00
|
|
|
|
snapshot['components'] = [
|
|
|
|
|
c for c in snapshot['components'] if c not in [network, network2]
|
|
|
|
|
]
|
2021-07-02 15:40:20 +00:00
|
|
|
|
user.post(json_encode(snapshot), res=m.Snapshot)
|
2020-11-13 11:29:37 +00:00
|
|
|
|
devices, _ = user.get(res=d.Device)
|
|
|
|
|
laptops = [c for c in devices['items'] if c['type'] == 'Laptop']
|
2022-07-20 12:58:32 +00:00
|
|
|
|
assert len(laptops) == 4
|
|
|
|
|
hids = [laptops[0]['hid'], laptops[2]['hid']]
|
2022-09-29 09:44:43 +00:00
|
|
|
|
proof_hid = [
|
|
|
|
|
'laptop-asustek_computer_inc-1000h-94oaaq021116-a0:24:8c:7f:cf:2d',
|
|
|
|
|
'laptop-asustek_computer_inc-1000h-94oaaq021116-00:24:8c:7f:cf:2d',
|
|
|
|
|
'laptop-asustek_computer_inc-1000h-94oaaq021116',
|
|
|
|
|
]
|
2020-11-13 11:29:37 +00:00
|
|
|
|
assert all([h in proof_hid for h in hids])
|