From 03a18df080efe5bc6da768a361d474521fcd44d0 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 6 Jun 2022 13:38:22 +0200 Subject: [PATCH] add tests for notes --- tests/test_basic.py | 2 + tests/test_render_2_0.py | 134 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 136 insertions(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index e933dea7..bb9196a2 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -61,6 +61,8 @@ def test_api_docs(client: Client): '/inventory/lot/{id}/del/', '/inventory/lot/{lot_id}/device/', '/inventory/lot/{lot_id}/device/add/', + '/inventory/lot/{lot_id}/deliverynote/', + '/inventory/lot/{lot_id}/receivernote/', '/inventory/lot/{lot_id}/trade-document/add/', '/inventory/lot/{lot_id}/transfer/{type_id}/', '/inventory/lot/{lot_id}/transfer/', diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 37c06004..90ae4b4c 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1175,3 +1175,137 @@ def test_edit_transfer(user3: UserClientFlask): assert 'one one one' in body assert ' Delete Lot' not in body assert 'Transfer (Closed)' in body + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_edit_deliverynote(user3: UserClientFlask): + # create lot + user3.get('/inventory/lot/add/') + lot_name = 'lot1' + data = { + 'name': lot_name, + 'csrf_token': generate_csrf(), + } + user3.post('/inventory/lot/add/', data=data) + lot = Lot.query.filter_by(name=lot_name).one() + lot_id = lot.id + + # create new incoming lot + uri = f'/inventory/lot/{lot_id}/transfer/incoming/' + data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + user3.post(uri, data=data) + lot = Lot.query.filter()[1] + lot_id = lot.id + + # edit delivery with errors + uri = f'/inventory/lot/{lot_id}/deliverynote/' + data = { + 'csrf_token': generate_csrf(), + 'number': 'AAA', + 'units': 10, + 'weight': 50, + 'date': datetime.datetime.now().date() + datetime.timedelta(15), + } + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Delivery Note updated error!' in body + + # # edit transfer successfully + data['date'] = datetime.datetime.now().date() - datetime.timedelta(15) + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Delivery Note updated successfully!' in body + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_edit_receivernote(user3: UserClientFlask): + # create lot + user3.get('/inventory/lot/add/') + lot_name = 'lot1' + data = { + 'name': lot_name, + 'csrf_token': generate_csrf(), + } + user3.post('/inventory/lot/add/', data=data) + lot = Lot.query.filter_by(name=lot_name).one() + lot_id = lot.id + + # create new incoming lot + uri = f'/inventory/lot/{lot_id}/transfer/incoming/' + data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + user3.post(uri, data=data) + lot = Lot.query.filter()[1] + lot_id = lot.id + + # edit delivery with errors + uri = f'/inventory/lot/{lot_id}/receivernote/' + data = { + 'csrf_token': generate_csrf(), + 'number': 'AAA', + 'units': 10, + 'weight': 50, + 'date': datetime.datetime.now().date() + datetime.timedelta(15), + } + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Receiver Note updated error!' in body + + # # edit transfer successfully + data['date'] = datetime.datetime.now().date() - datetime.timedelta(15) + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Receiver Note updated successfully!' in body + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_edit_notes_with_closed_transfer(user3: UserClientFlask): + # create lot + user3.get('/inventory/lot/add/') + lot_name = 'lot1' + data = { + 'name': lot_name, + 'csrf_token': generate_csrf(), + } + user3.post('/inventory/lot/add/', data=data) + lot = Lot.query.filter_by(name=lot_name).one() + lot_id = lot.id + + # create new incoming lot + uri = f'/inventory/lot/{lot_id}/transfer/incoming/' + data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + user3.post(uri, data=data) + lot = Lot.query.filter()[1] + lot_id = lot.id + + # edit transfer adding date + uri = f'/inventory/lot/{lot_id}/transfer/' + data['date'] = datetime.datetime.now().date() - datetime.timedelta(15) + user3.post(uri, data=data) + assert lot.transfer.closed is True + + # edit delivery with errors + uri = f'/inventory/lot/{lot_id}/deliverynote/' + data = { + 'csrf_token': generate_csrf(), + 'number': 'AAA', + 'units': 10, + 'weight': 50, + } + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Delivery Note updated error!' in body + + # edit receiver with errors + uri = f'/inventory/lot/{lot_id}/receivernote/' + data = { + 'csrf_token': generate_csrf(), + 'number': 'AAA', + 'units': 10, + 'weight': 50, + } + body, status = user3.post(uri, data=data) + assert status == '200 OK' + assert 'Receiver Note updated error!' in body