Merge pull request #184 from eReuse/bugfix/light-query
Bugfix/light query
This commit is contained in:
commit
47185aa956
|
@ -139,7 +139,7 @@ class Dummy:
|
||||||
res=Lot,
|
res=Lot,
|
||||||
item='{}/devices'.format(lot_user['id']),
|
item='{}/devices'.format(lot_user['id']),
|
||||||
query=[('id', pc) for pc in itertools.islice(pcs, 1, 4)])
|
query=[('id', pc) for pc in itertools.islice(pcs, 1, 4)])
|
||||||
assert len(lot['devices'])
|
# assert len(lot['devices'])
|
||||||
|
|
||||||
lot2, _ = user2.post({},
|
lot2, _ = user2.post({},
|
||||||
res=Lot,
|
res=Lot,
|
||||||
|
|
|
@ -40,10 +40,13 @@ class Device(Thing):
|
||||||
width = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.width.comment)
|
width = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.width.comment)
|
||||||
height = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.height.comment)
|
height = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.height.comment)
|
||||||
depth = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.depth.comment)
|
depth = Float(validate=Range(0.1, 5), unit=UnitCodes.m, description=m.Device.depth.comment)
|
||||||
|
# TODO TimeOut 2. Comment actions and lots if there are time out.
|
||||||
actions = NestedOn('Action', many=True, dump_only=True, description=m.Device.actions.__doc__)
|
actions = NestedOn('Action', many=True, dump_only=True, description=m.Device.actions.__doc__)
|
||||||
|
# TODO TimeOut 2. Comment actions_one and lots if there are time out.
|
||||||
actions_one = NestedOn('Action', many=True, load_only=True, collection_class=OrderedSet)
|
actions_one = NestedOn('Action', many=True, load_only=True, collection_class=OrderedSet)
|
||||||
problems = NestedOn('Action', many=True, dump_only=True, description=m.Device.problems.__doc__)
|
problems = NestedOn('Action', many=True, dump_only=True, description=m.Device.problems.__doc__)
|
||||||
url = URL(dump_only=True, description=m.Device.url.__doc__)
|
url = URL(dump_only=True, description=m.Device.url.__doc__)
|
||||||
|
# TODO TimeOut 2. Comment actions and lots if there are time out.
|
||||||
lots = NestedOn('Lot',
|
lots = NestedOn('Lot',
|
||||||
many=True,
|
many=True,
|
||||||
dump_only=True,
|
dump_only=True,
|
||||||
|
@ -98,6 +101,7 @@ class Device(Thing):
|
||||||
|
|
||||||
class Computer(Device):
|
class Computer(Device):
|
||||||
__doc__ = m.Computer.__doc__
|
__doc__ = m.Computer.__doc__
|
||||||
|
# TODO TimeOut 1. Comment components if there are time out.
|
||||||
components = NestedOn('Component',
|
components = NestedOn('Component',
|
||||||
many=True,
|
many=True,
|
||||||
dump_only=True,
|
dump_only=True,
|
||||||
|
@ -128,7 +132,7 @@ class Computer(Device):
|
||||||
description=m.Computer.privacy.__doc__)
|
description=m.Computer.privacy.__doc__)
|
||||||
amount = Integer(validate=f.validate.Range(min=0, max=100),
|
amount = Integer(validate=f.validate.Range(min=0, max=100),
|
||||||
description=m.Computer.amount.__doc__)
|
description=m.Computer.amount.__doc__)
|
||||||
# author_id = NestedOn(s_user.User,only_query='author_id')
|
# author_id = NestedOn(s_user.User, only_query='author_id')
|
||||||
owner_id = UUID(data_key='ownerID')
|
owner_id = UUID(data_key='ownerID')
|
||||||
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)
|
transfer_state = EnumField(enums.TransferState, description=m.Computer.transfer_state.comment)
|
||||||
receiver_id = UUID(data_key='receiverID')
|
receiver_id = UUID(data_key='receiverID')
|
||||||
|
|
|
@ -5,14 +5,32 @@ from ereuse_devicehub.marshmallow import NestedOn
|
||||||
from ereuse_devicehub.resources.deliverynote import schemas as s_deliverynote
|
from ereuse_devicehub.resources.deliverynote import schemas as s_deliverynote
|
||||||
from ereuse_devicehub.resources.device import schemas as s_device
|
from ereuse_devicehub.resources.device import schemas as s_device
|
||||||
from ereuse_devicehub.resources.action import schemas as s_action
|
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.enums import TransferState
|
||||||
from ereuse_devicehub.resources.lot import models as m
|
from ereuse_devicehub.resources.lot import models as m
|
||||||
from ereuse_devicehub.resources.models import STR_SIZE
|
from ereuse_devicehub.resources.models import STR_SIZE
|
||||||
from ereuse_devicehub.resources.schemas import Thing
|
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)
|
id = f.UUID(dump_only=True)
|
||||||
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
|
name = SanitizedStr(validate=f.validate.Length(max=STR_SIZE), required=True)
|
||||||
description = SanitizedStr(description=m.Lot.description.comment)
|
description = SanitizedStr(description=m.Lot.description.comment)
|
||||||
|
@ -29,4 +47,11 @@ class Lot(Thing):
|
||||||
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
|
receiver_address = SanitizedStr(validate=f.validate.Length(max=42))
|
||||||
deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True)
|
deliverynote = NestedOn(s_deliverynote.Deliverynote, dump_only=True)
|
||||||
documents = NestedOn('TradeDocument', many=True, 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)
|
||||||
|
|
|
@ -506,7 +506,8 @@ def test_get_devices_permissions(app: Devicehub, user: UserClient, user2: UserCl
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@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."""
|
"""Checks GETting multiple devices."""
|
||||||
|
|
||||||
user.post(file('asus-eee-1000h.snapshot.11'), res=m.Snapshot)
|
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,
|
res=Lot,
|
||||||
item='{}/devices'.format(my_lot['id']),
|
item='{}/devices'.format(my_lot['id']),
|
||||||
query=[('id', device_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'
|
url = '/devices/?filter={"type":["Computer"]}&unassign=0'
|
||||||
|
|
||||||
|
|
|
@ -313,7 +313,6 @@ def test_post_get_lot(user: UserClient):
|
||||||
assert l['name'] == 'Foo'
|
assert l['name'] == 'Foo'
|
||||||
l, _ = user.get(res=Lot, item=l['id'])
|
l, _ = user.get(res=Lot, item=l['id'])
|
||||||
assert l['name'] == 'Foo'
|
assert l['name'] == 'Foo'
|
||||||
assert not l['children']
|
|
||||||
|
|
||||||
|
|
||||||
def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
|
def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
|
||||||
|
@ -355,38 +354,40 @@ def test_lot_post_add_children_view_ui_tree_normal(user: UserClient):
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@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
|
"""Tests adding a device to a lot using POST and
|
||||||
removing it with DELETE.
|
removing it with DELETE.
|
||||||
"""
|
"""
|
||||||
# todo check with components
|
# todo check with components
|
||||||
with app.app_context():
|
g.user = User.query.one()
|
||||||
g.user = User.query.one()
|
device = Desktop(serial_number='foo',
|
||||||
device = Desktop(serial_number='foo',
|
model='bar',
|
||||||
model='bar',
|
manufacturer='foobar',
|
||||||
manufacturer='foobar',
|
chassis=ComputerChassis.Lunchbox,
|
||||||
chassis=ComputerChassis.Lunchbox,
|
owner_id=user.user['id'])
|
||||||
owner_id=user.user['id'])
|
db.session.add(device)
|
||||||
db.session.add(device)
|
db.session.commit()
|
||||||
db.session.commit()
|
device_id = device.id
|
||||||
device_id = device.id
|
devicehub_id = device.devicehub_id
|
||||||
devicehub_id = device.devicehub_id
|
|
||||||
parent, _ = user.post(({'name': 'lot'}), res=Lot)
|
parent, _ = user.post(({'name': 'lot'}), res=Lot)
|
||||||
lot, _ = user.post({},
|
lot, _ = user.post({},
|
||||||
res=Lot,
|
res=Lot,
|
||||||
item='{}/devices'.format(parent['id']),
|
item='{}/devices'.format(parent['id']),
|
||||||
query=[('id', device_id)])
|
query=[('id', device_id)])
|
||||||
assert lot['devices'][0]['id'] == device_id, 'Lot contains device'
|
lot = Lot.query.filter_by(id=lot['id']).one()
|
||||||
device, _ = user.get(res=Device, item=devicehub_id)
|
assert list(lot.devices)[0].id == device_id, 'Lot contains device'
|
||||||
assert len(device['lots']) == 1
|
device = Device.query.filter_by(devicehub_id=devicehub_id).one()
|
||||||
assert device['lots'][0]['id'] == lot['id'], 'Device is inside lot'
|
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
|
# Remove the device
|
||||||
lot, _ = user.delete(res=Lot,
|
user.delete(res=Lot,
|
||||||
item='{}/devices'.format(parent['id']),
|
item='{}/devices'.format(parent['id']),
|
||||||
query=[('id', device_id)],
|
query=[('id', device_id)],
|
||||||
status=200)
|
status=200)
|
||||||
assert not len(lot['devices'])
|
assert not len(lot.devices)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
@ -416,8 +417,9 @@ def test_lot_error_add_device_from_other_user(user: UserClient):
|
||||||
res=Lot,
|
res=Lot,
|
||||||
item='{}/devices'.format(parent['id']),
|
item='{}/devices'.format(parent['id']),
|
||||||
query=[('id', device_id)])
|
query=[('id', device_id)])
|
||||||
assert lot['devices'] == [], 'Lot contains device'
|
lot = Lot.query.filter_by(id=lot['id']).one()
|
||||||
assert len(lot['devices']) == 0
|
assert list(lot.devices) == [], 'Lot contains device'
|
||||||
|
assert len(lot.devices) == 0
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.mvp
|
@pytest.mark.mvp
|
||||||
|
|
Reference in New Issue