From eeb6db7bc2a08a82408a2d832a715df0012d2a58 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Wed, 29 Sep 2021 21:12:46 +0200 Subject: [PATCH] test for recycling documents --- ereuse_devicehub/resources/action/schemas.py | 5 +++++ tests/test_action.py | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/ereuse_devicehub/resources/action/schemas.py b/ereuse_devicehub/resources/action/schemas.py index 0c69aad9..3dc22160 100644 --- a/ereuse_devicehub/resources/action/schemas.py +++ b/ereuse_devicehub/resources/action/schemas.py @@ -426,6 +426,11 @@ class Ready(ActionWithMultipleDevices): class ActionStatus(ActionWithMultipleDevices): rol_user = NestedOn(s_user.User, dump_only=True, exclude=('token',)) + documents = NestedOn(s_document.TradeDocument, + many=True, + required=False, # todo test ensuring len(devices) >= 1 + only_query='id', + collection_class=OrderedSet) @post_load def put_rol_user(self, data: dict): diff --git a/tests/test_action.py b/tests/test_action.py index f82d0bac..d0decb93 100644 --- a/tests/test_action.py +++ b/tests/test_action.py @@ -470,6 +470,25 @@ def test_use_changing_owner(user: UserClient, user2: UserClient): assert device.owner.email == user2.email +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_recycling_container(user: UserClient): + lot, _ = user.post({'name': 'MyLotOut'}, res=Lot) + url = 'http://www.ereuse.org/', + request_post = { + 'filename': 'test.pdf', + 'hash': 'bbbbbbbb', + 'url': url, + 'weight': 150, + 'lot': lot['id'] + } + tradedocument, _ = user.post(res=TradeDocument, data=request_post) + action = {'type': models.Recycling.t, 'devices': [], 'documents': [tradedocument['id']]} + action, _ = user.post(action, res=models.Action) + trade = TradeDocument.query.one() + assert str(trade.actions[0].id) == action['id'] + + @pytest.mark.mvp def test_reuse(user: UserClient): snap, _ = user.post(file('basic.snapshot'), res=models.Snapshot)