reduce latency for timeout for lots

This commit is contained in:
Cayo Puigdefabregas 2021-11-18 11:48:57 +01:00
parent e447e15aeb
commit 5510417125
3 changed files with 58 additions and 29 deletions

View File

@ -5,14 +5,32 @@ from ereuse_devicehub.marshmallow import NestedOn
from ereuse_devicehub.resources.deliverynote import schemas as s_deliverynote
from ereuse_devicehub.resources.device import schemas as s_device
from ereuse_devicehub.resources.action import schemas as s_action
from ereuse_devicehub.resources.tradedocument import schemas as s_document
from ereuse_devicehub.resources.enums import TransferState
from ereuse_devicehub.resources.lot import models as m
from ereuse_devicehub.resources.models import STR_SIZE
from ereuse_devicehub.resources.schemas import Thing
class Lot(Thing):
TRADE_VALUES = (
'id',
'user_from.email',
'user_to.email',
'user_from.id',
'user_to.id',
'user_to.code',
'user_from.code'
)
DOCUMENTS_VALUES = (
'id',
'file_name',
'total_weight',
'trading'
)
class Old_Lot(Thing):
id = f.UUID(dump_only=True)
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
description = SanitizedStr(description=m.Lot.description.comment)
@ -29,4 +47,11 @@ class Lot(Thing):
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True)
documents = NestedOn('TradeDocument', many=True, dump_only=True)
trade = NestedOn(s_action.Trade, dump_only=True)
class Lot(Thing):
id = f.UUID(dump_only=True)
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
description = SanitizedStr(description=m.Lot.description.comment)
trade = f.Nested(s_action.Trade, dump_only=True, only=TRADE_VALUES)
documents = f.Nested('TradeDocument', many=True, dump_only=True, only=DOCUMENTS_VALUES)

View File

@ -506,7 +506,8 @@ def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserCl
@pytest.mark.mvp
def test_get_devices_unassigned(app: Devicehub, user: UserClient):
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_get_devices_unassigned(user: UserClient):
"""Checks GETting multiple devices."""
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
@ -529,7 +530,8 @@ def test_get_devices_unassigned(app: Devicehub, user: UserClient):
res=Lot,
item='{}/devices'.format(my_lot['id']),
query=[('id', device_id)])
assert lot['devices'][0]['id'] == device_id, 'Lot contains device'
lot = Lot.query.filter_by(id=lot['id']).one()
assert next(iter(lot.devices)).id == device_id
url = '/devices/?filter={"type":["Computer"]}&unassign=0'

View File

@ -313,7 +313,6 @@ def test_post_get_lot(user: UserClient):
assert l['name'] == 'Foo'
l, _ = user.get(res=Lot, item=l['id'])
assert l['name'] == 'Foo'
assert not l['children']
def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
@ -355,12 +354,12 @@ def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
@pytest.mark.mvp
def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient):
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_lot_post_add_remove_device_view(user: UserClient):
"""Tests adding a device to a lot using POST and
removing it with DELETE.
"""
# todo check with components
with app.app_context():
g.user = User.query.one()
device = Desktop(serial_number='foo',
model='bar',
@ -376,17 +375,19 @@ def test_lot_post_add_remove_device_view(app: Devicehub, user: UserClient):
res=Lot,
item='{}/devices'.format(parent['id']),
query=[('id', device_id)])
assert lot['devices'][0]['id'] == device_id, 'Lot contains device'
device, _ = user.get(res=Device, item=devicehub_id)
assert len(device['lots']) == 1
assert device['lots'][0]['id'] == lot['id'], 'Device is inside lot'
lot = Lot.query.filter_by(id=lot['id']).one()
assert list(lot.devices)[0].id == device_id, 'Lot contains device'
device = Device.query.filter_by(devicehub_id=devicehub_id).one()
assert len(device.lots) == 1
# assert device['lots'][0]['id'] == lot['id'], 'Device is inside lot'
assert list(device.lots)[0].id == lot.id, 'Device is inside lot'
# Remove the device
lot, _ = user.delete(res=Lot,
user.delete(res=Lot,
item='{}/devices'.format(parent['id']),
query=[('id', device_id)],
status=200)
assert not len(lot['devices'])
assert not len(lot.devices)
@pytest.mark.mvp
@ -416,8 +417,9 @@ def test_lot_error_add_device_from_other_user(user: UserClient):
res=Lot,
item='{}/devices'.format(parent['id']),
query=[('id', device_id)])
assert lot['devices'] == [], 'Lot contains device'
assert len(lot['devices']) == 0
lot = Lot.query.filter_by(id=lot['id']).one()
assert list(lot.devices) == [], 'Lot contains device'
assert len(lot.devices) == 0
@pytest.mark.mvp