Fix inventory not nesting devices

This commit is contained in:
Xavier Bustamante Talavera 2018-07-17 19:00:07 +02:00
parent c1a3b23d8b
commit 6f3ea001fe
4 changed files with 18 additions and 6 deletions

View File

@ -1,4 +1,4 @@
from distutils.version import StrictVersion from distutils.version import StrictVersion
__version__ = '0.2.0a10' __version__ = '0.2.0a11'
version = StrictVersion(__version__) version = StrictVersion(__version__)

View File

@ -96,7 +96,7 @@ class InventoryView(View):
.order_by(*args['sort']) \ .order_by(*args['sort']) \
.paginate(page=args['page'], per_page=30) # type: Pagination .paginate(page=args['page'], per_page=30) # type: Pagination
inventory = { inventory = {
'devices': app.resources[Device.t].schema.dump(devices.items, many=True), 'devices': app.resources[Device.t].schema.dump(devices.items, many=True, nested=1),
'groups': [], 'groups': [],
'widgets': {}, 'widgets': {},
'pagination': { 'pagination': {

View File

@ -67,7 +67,7 @@ setup(
'Environment :: Web Environment', 'Environment :: Web Environment',
'Framework :: Flask', 'Framework :: Flask',
'Intended Audience :: Developers', 'Intended Audience :: Developers',
'License :: OSI Approved :: GNU Affero General Public License v3' 'License :: OSI Approved :: GNU Affero General Public License v3',
'Operating System :: OS Independent', 'Operating System :: OS Independent',
'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5', 'Programming Language :: Python :: 3.5',

View File

@ -5,8 +5,10 @@ from ereuse_devicehub.db import db
from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.devicehub import Devicehub
from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, SolidStateDrive from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, SolidStateDrive
from ereuse_devicehub.resources.enums import ComputerChassis from ereuse_devicehub.resources.enums import ComputerChassis
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
@pytest.mark.usefixtures('app_context') @pytest.mark.usefixtures('app_context')
@ -69,7 +71,7 @@ def inventory_query_dummy(app: Devicehub):
db.session.commit() db.session.commit()
@pytest.mark.usefixtures('inventory_query_dummy') @pytest.mark.usefixtures(inventory_query_dummy.__name__)
def test_inventory_query_no_filters(user: UserClient): def test_inventory_query_no_filters(user: UserClient):
i, _ = user.get(res=Inventory) i, _ = user.get(res=Inventory)
assert tuple(d['type'] for d in i['devices']) == ( assert tuple(d['type'] for d in i['devices']) == (
@ -77,16 +79,26 @@ def test_inventory_query_no_filters(user: UserClient):
) )
@pytest.mark.usefixtures('inventory_query_dummy') @pytest.mark.usefixtures(inventory_query_dummy.__name__)
def test_inventory_query_filter_type(user: UserClient): def test_inventory_query_filter_type(user: UserClient):
i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Desktop', 'Laptop']})]) i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Desktop', 'Laptop']})])
assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop') assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop')
@pytest.mark.usefixtures('inventory_query_dummy') @pytest.mark.usefixtures(inventory_query_dummy.__name__)
def test_inventory_query_filter_sort(user: UserClient): def test_inventory_query_filter_sort(user: UserClient):
i, _ = user.get(res=Inventory, query=[ i, _ = user.get(res=Inventory, query=[
('sort', {'created': Sorting.ASCENDING}), ('sort', {'created': Sorting.ASCENDING}),
('filter', {'type': ['Computer']}) ('filter', {'type': ['Computer']})
]) ])
assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop') assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop')
def test_inventory_query(user: UserClient):
"""Checks result of inventory."""
user.post(file('basic.snapshot'), res=Snapshot)
i, _ = user.get(res=Inventory)
pc = next(d for d in i['devices'] if d['type'] == 'Desktop')
assert len(pc['events']) == 4
assert len(pc['components']) == 3
assert not pc['tags']