From 6f3ea001fe51a2403d7348dc61aee487213184a8 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Tue, 17 Jul 2018 19:00:07 +0200 Subject: [PATCH] Fix inventory not nesting devices --- ereuse_devicehub/__init__.py | 2 +- ereuse_devicehub/resources/inventory.py | 2 +- setup.py | 2 +- tests/test_inventory.py | 18 +++++++++++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ereuse_devicehub/__init__.py b/ereuse_devicehub/__init__.py index 157edf70..6a37c560 100644 --- a/ereuse_devicehub/__init__.py +++ b/ereuse_devicehub/__init__.py @@ -1,4 +1,4 @@ from distutils.version import StrictVersion -__version__ = '0.2.0a10' +__version__ = '0.2.0a11' version = StrictVersion(__version__) diff --git a/ereuse_devicehub/resources/inventory.py b/ereuse_devicehub/resources/inventory.py index cf614e15..3004c27c 100644 --- a/ereuse_devicehub/resources/inventory.py +++ b/ereuse_devicehub/resources/inventory.py @@ -96,7 +96,7 @@ class InventoryView(View): .order_by(*args['sort']) \ .paginate(page=args['page'], per_page=30) # type: Pagination 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': [], 'widgets': {}, 'pagination': { diff --git a/setup.py b/setup.py index afb4fd81..c6c99840 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ setup( 'Environment :: Web Environment', 'Framework :: Flask', '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', 'Programming Language :: Python :: 3 :: Only', 'Programming Language :: Python :: 3.5', diff --git a/tests/test_inventory.py b/tests/test_inventory.py index 365a4aae..53fbe932 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -5,8 +5,10 @@ from ereuse_devicehub.db import db from ereuse_devicehub.devicehub import Devicehub from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, SolidStateDrive 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 teal.utils import compiled +from tests.conftest import file @pytest.mark.usefixtures('app_context') @@ -69,7 +71,7 @@ def inventory_query_dummy(app: Devicehub): db.session.commit() -@pytest.mark.usefixtures('inventory_query_dummy') +@pytest.mark.usefixtures(inventory_query_dummy.__name__) def test_inventory_query_no_filters(user: UserClient): i, _ = user.get(res=Inventory) 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): i, _ = user.get(res=Inventory, query=[('filter', {'type': ['Desktop', 'Laptop']})]) assert tuple(d['type'] for d in i['devices']) == ('Desktop', 'Laptop', 'Desktop') -@pytest.mark.usefixtures('inventory_query_dummy') +@pytest.mark.usefixtures(inventory_query_dummy.__name__) def test_inventory_query_filter_sort(user: UserClient): i, _ = user.get(res=Inventory, query=[ ('sort', {'created': Sorting.ASCENDING}), ('filter', {'type': ['Computer']}) ]) 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']