new endpoint tests of tradedocuments

This commit is contained in:
Cayo Puigdefabregas 2021-05-14 12:57:54 +02:00
parent 5e36cca340
commit 6fc0e71833
1 changed files with 23 additions and 7 deletions

View File

@ -28,7 +28,7 @@ from ereuse_devicehub.resources.device import states
from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \ from ereuse_devicehub.resources.device.models import Desktop, Device, GraphicCard, HardDrive, \
RamModule, SolidStateDrive RamModule, SolidStateDrive
from ereuse_devicehub.resources.enums import ComputerChassis, Severity, TestDataStorageLength from ereuse_devicehub.resources.enums import ComputerChassis, Severity, TestDataStorageLength
from ereuse_devicehub.resources.tradedocument.models import Document from ereuse_devicehub.resources.tradedocument.models import TradeDocument
from tests import conftest from tests import conftest
from tests.conftest import create_user, file from tests.conftest import create_user, file
@ -662,15 +662,31 @@ def test_confirmRevoke(user: UserClient, user2: UserClient):
@pytest.mark.mvp @pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_add_document_to_lot(user: UserClient, user2: UserClient): def test_simple_add_document(user: UserClient):
"""Example of one document inserted into one lot""" """Example of one document inserted into one lot"""
lot, _ = user.post({'name': 'MyLot'}, res=Lot) doc = TradeDocument(**{'file_name': 'test', 'owner_id': user.user['id']})
db.session.add(doc)
db.session.flush()
@pytest.mark.mvp @pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__) @pytest.mark.usefixtures(conftest.app_context.__name__)
def test_simple_add_document(user: UserClient): def test_add_document_to_lot(user: UserClient, user2: UserClient, client: Client):
"""Example of one document inserted into one lot""" """Example of one document inserted into one lot"""
doc = Document(**{'file_name': 'test', 'owner_id': user.user['id']}) lot, _ = user.post({'name': 'MyLot'}, res=Lot)
db.session.add(doc) # data = {'file_name': 'test', 'lot': lot['id']}
db.session.flush() data = {'file_name': 'test'}
doc, _ = user.post(res=TradeDocument, data=data)
user.get(res=TradeDocument, item=doc['id'])
user.delete(res=TradeDocument, item=doc['id'])
# check permitions
doc, _ = user.post(res=TradeDocument, data=data)
# anonyms users
client.get(res=TradeDocument, item=doc['id'], status=401)
client.delete(res=TradeDocument, item=doc['id'], status=401)
# other user
user2.get(res=TradeDocument, item=doc['id'], status=404)
user2.delete(res=TradeDocument, item=doc['id'], status=404)