From 863d3b56394e10df7facfe33bea23e6dfd1358c4 Mon Sep 17 00:00:00 2001 From: Xavier Bustamante Talavera Date: Fri, 21 Sep 2018 11:25:22 +0200 Subject: [PATCH] Fix getting wrong lots from inventory --- ereuse_devicehub/dummy/dummy.py | 6 ++++-- ereuse_devicehub/resources/inventory.py | 2 +- tests/test_inventory.py | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/dummy/dummy.py b/ereuse_devicehub/dummy/dummy.py index 8da2d93c..4d871864 100644 --- a/ereuse_devicehub/dummy/dummy.py +++ b/ereuse_devicehub/dummy/dummy.py @@ -68,8 +68,6 @@ class Dummy: snapshot = yaml.load(f) s, _ = user.post(res=m.Snapshot, data=snapshot) pcs.add(s['device']['id']) - inventory, _ = user.get(res=Inventory) - assert len(inventory['devices']) # Link tags and eTags for tag, pc in zip((self.TAGS[1], self.TAGS[2], self.ET[0][0], self.ET[1][1]), pcs): @@ -99,6 +97,10 @@ class Dummy: query=[('id', pc) for pc in itertools.islice(pcs, len(pcs) // 3)]) assert len(lot['devices']) + # Keep this at the bottom + inventory, _ = user.get(res=Inventory) + assert len(inventory['devices']) + assert len(inventory['lots']) print('⭐ Done.') def user_client(self, email: str, password: str): diff --git a/ereuse_devicehub/resources/inventory.py b/ereuse_devicehub/resources/inventory.py index e3977cf9..83fc3d92 100644 --- a/ereuse_devicehub/resources/inventory.py +++ b/ereuse_devicehub/resources/inventory.py @@ -98,7 +98,7 @@ class InventoryView(View): .paginate(page=args['page'], per_page=30) # type: Pagination inventory = { 'devices': app.resources[Device.t].schema.dump(devices.items, many=True, nested=1), - 'lots': Lot.roots(), + 'lots': app.resources[Lot.t].schema.dump(Lot.roots(), many=True, nested=1), 'widgets': {}, 'pagination': { 'page': devices.page, diff --git a/tests/test_inventory.py b/tests/test_inventory.py index c0f1c0d7..d9559bf5 100644 --- a/tests/test_inventory.py +++ b/tests/test_inventory.py @@ -1,4 +1,5 @@ import pytest +from teal.utils import compiled from ereuse_devicehub.client import UserClient from ereuse_devicehub.db import db @@ -7,7 +8,6 @@ from ereuse_devicehub.resources.device.models import Desktop, Device, Laptop, So 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 import conftest @@ -102,3 +102,8 @@ def test_inventory_query(user: UserClient): assert len(pc['events']) == 4 assert len(pc['components']) == 3 assert not pc['tags'] + + +@pytest.mark.xfail(reason='Functionality not yet developed.') +def test_inventory_lots_query(user: UserClient): + pass