From 0a657a3b45c25b999ff94d09c14174bd1919f623 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 10 Oct 2022 11:10:39 +0200 Subject: [PATCH] fix tests transfer --- ereuse_devicehub/inventory/forms.py | 12 ++++++++--- .../templates/inventory/new_transfer.html | 2 +- tests/test_render_2_0.py | 20 +++++++++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index ed69f202..25dcba02 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -1259,6 +1259,12 @@ class TradeDocumentForm(FlaskForm): class TransferForm(FlaskForm): + lot_name = StringField( + 'Lot Name', + [validators.DataRequired()], + render_kw={'class': "form-control"}, + description="You need put a lot name", + ) code = StringField( 'Code', [validators.DataRequired()], @@ -1303,9 +1309,7 @@ class TransferForm(FlaskForm): return self._obj def set_obj(self): - name = self.code.data - if self._tmp_lot: - name = self._tmp_lot.name + name = self.lot_name.data self.newlot = Lot(name=name) if self._tmp_lot: self.newlot.devices = self._tmp_lot.devices @@ -1339,6 +1343,7 @@ class EditTransferForm(TransferForm): self.code.data = self._obj.code self.description.data = self._obj.description self.date.data = self._obj.date + self.lot_name.data = self._obj.lot.name def validate(self, extra_validators=None): is_valid = super().validate(extra_validators) @@ -1350,6 +1355,7 @@ class EditTransferForm(TransferForm): def set_obj(self, commit=True): self.populate_obj(self._obj) + self._obj.lot.name = self.lot_name.data class NotesForm(FlaskForm): diff --git a/ereuse_devicehub/templates/inventory/new_transfer.html b/ereuse_devicehub/templates/inventory/new_transfer.html index 428e10fe..f76bb525 100644 --- a/ereuse_devicehub/templates/inventory/new_transfer.html +++ b/ereuse_devicehub/templates/inventory/new_transfer.html @@ -38,7 +38,7 @@
{% if field != form.type %} {{ field.label(class_="form-label") }} - {% if field == form.code %} + {% if field in [form.code, form.lot_name] %} * {% endif %} {{ field }} diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index f918cb80..27672c01 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1374,6 +1374,7 @@ def test_wb_settings_register(user3: UserClientFlask): def test_create_transfer(user3: UserClientFlask): user3.get('/inventory/lot/add/') lot_name = 'lot1' + lot_name2 = 'lot2' data = { 'name': lot_name, 'csrf_token': generate_csrf(), @@ -1390,13 +1391,14 @@ def test_create_transfer(user3: UserClientFlask): assert 'Description' in body assert 'Save' in body - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name2} body, status = user3.post(uri, data=data) assert status == '200 OK' assert 'Transfer created successfully!' in body assert 'Delete Lot' in body assert 'Incoming Lot' in body + assert lot_name2 in body @pytest.mark.mvp @@ -1405,6 +1407,8 @@ def test_edit_transfer(user3: UserClientFlask): # create lot user3.get('/inventory/lot/add/') lot_name = 'lot1' + lot_name2 = 'lot2' + lot_name3 = 'lot3' data = { 'name': lot_name, 'csrf_token': generate_csrf(), @@ -1422,12 +1426,13 @@ def test_edit_transfer(user3: UserClientFlask): # create new incoming lot uri = f'/inventory/lot/{lot_id}/transfer/incoming/' - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name2} body, status = user3.post(uri, data=data) assert 'Transfer (Open)' in body assert ' Delete Lot' in body lot = Lot.query.filter()[1] assert lot.transfer is not None + assert lot_name2 in body # edit transfer with errors lot_id = lot.id @@ -1436,6 +1441,7 @@ def test_edit_transfer(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'code': 'AAA', 'description': 'one one one', + 'lot_name': lot_name3, 'date': datetime.datetime.now().date() + datetime.timedelta(15), } body, status = user3.post(uri, data=data) @@ -1450,6 +1456,7 @@ def test_edit_transfer(user3: UserClientFlask): 'csrf_token': generate_csrf(), 'code': 'AAA', 'description': 'one one one', + 'lot_name': lot_name3, 'date': datetime.datetime.now().date() - datetime.timedelta(15), } body, status = user3.post(uri, data=data) @@ -1458,6 +1465,7 @@ def test_edit_transfer(user3: UserClientFlask): assert 'one one one' in body assert ' Delete Lot' not in body assert 'Transfer (Closed)' in body + assert lot_name3 in body @pytest.mark.mvp @@ -1476,7 +1484,7 @@ def test_edit_deliverynote(user3: UserClientFlask): # create new incoming lot uri = f'/inventory/lot/{lot_id}/transfer/incoming/' - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name} user3.post(uri, data=data) lot = Lot.query.filter()[1] lot_id = lot.id @@ -1517,7 +1525,7 @@ def test_edit_receivernote(user3: UserClientFlask): # create new incoming lot uri = f'/inventory/lot/{lot_id}/transfer/incoming/' - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name} user3.post(uri, data=data) lot = Lot.query.filter()[1] lot_id = lot.id @@ -1558,7 +1566,7 @@ def test_edit_notes_with_closed_transfer(user3: UserClientFlask): # create new incoming lot uri = f'/inventory/lot/{lot_id}/transfer/incoming/' - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name} user3.post(uri, data=data) lot = Lot.query.filter()[1] lot_id = lot.id @@ -2403,7 +2411,7 @@ def test_bug_3831_documents(user3: UserClientFlask): uri = f'/inventory/lot/{lot_id}/transfer/incoming/' user3.get(uri) - data = {'csrf_token': generate_csrf(), 'code': 'AAA'} + data = {'csrf_token': generate_csrf(), 'code': 'AAA', 'lot_name': lot_name} body, status = user3.post(uri, data=data) assert status == '200 OK'