From dc083f9c168d6f1b9335ec3a215f53285584e970 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 12 Jul 2022 11:49:52 +0000 Subject: [PATCH 1/9] Bump numpy from 1.21.6 to 1.22.0 Bumps [numpy](https://github.com/numpy/numpy) from 1.21.6 to 1.22.0. - [Release notes](https://github.com/numpy/numpy/releases) - [Changelog](https://github.com/numpy/numpy/blob/main/doc/RELEASE_WALKTHROUGH.rst) - [Commits](https://github.com/numpy/numpy/compare/v1.21.6...v1.22.0) --- updated-dependencies: - dependency-name: numpy dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index 91d7e79a..de6a4069 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,7 +47,7 @@ pyjwt==2.4.0 pint==0.9 py-dmidecode==0.1.0 pandas==1.3.5 -numpy==1.21.6 +numpy==1.22.0 odfpy==1.4.1 xlrd==2.0.1 openpyxl==3.0.10 From 05c6b9f47bd8c34ae2f74c458a79f1a7270b7c27 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 15 Jul 2022 11:58:27 +0200 Subject: [PATCH 2/9] Add comment to pandas dependencies --- requirements.txt | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/requirements.txt b/requirements.txt index de6a4069..99abf67a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -47,10 +47,10 @@ pyjwt==2.4.0 pint==0.9 py-dmidecode==0.1.0 pandas==1.3.5 -numpy==1.22.0 -odfpy==1.4.1 -xlrd==2.0.1 -openpyxl==3.0.10 -et_xmlfile==1.1.0 +numpy==1.22.0 # pandas dependency +odfpy==1.4.1 # pandas dependency +xlrd==2.0.1 # pandas dependency +openpyxl==3.0.10 # pandas dependency +et_xmlfile==1.1.0 # pandas dependency sentry_sdk==1.6.0 blinker==1.4 From 09412f9ee607617f8d149615ba63a5f730f1a1ff Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 15 Jul 2022 11:59:06 +0200 Subject: [PATCH 3/9] Move sentry & blinker to requirements-prod.txt Use a separate file to requirements of production environment --- requirements-prod.txt | 2 ++ requirements.txt | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) create mode 100644 requirements-prod.txt diff --git a/requirements-prod.txt b/requirements-prod.txt new file mode 100644 index 00000000..50a04d5d --- /dev/null +++ b/requirements-prod.txt @@ -0,0 +1,2 @@ +sentry_sdk==1.6.0 +blinker==1.4 diff --git a/requirements.txt b/requirements.txt index 99abf67a..b886ac57 100644 --- a/requirements.txt +++ b/requirements.txt @@ -52,5 +52,3 @@ odfpy==1.4.1 # pandas dependency xlrd==2.0.1 # pandas dependency openpyxl==3.0.10 # pandas dependency et_xmlfile==1.1.0 # pandas dependency -sentry_sdk==1.6.0 -blinker==1.4 From 5aa6f16ae05f74d0c0d9f8bed643ef7819d521c2 Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 15 Jul 2022 12:03:06 +0200 Subject: [PATCH 4/9] Move selenium to requirements-dev.txt and update actions to install dependencies from this file. --- .github/workflows/flask.yml | 2 +- .github/workflows/selenium.yml | 2 +- requirements-dev.txt | 3 +++ requirements.txt | 1 - 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/flask.yml b/.github/workflows/flask.yml index 43fbe8e7..0c801216 100644 --- a/.github/workflows/flask.yml +++ b/.github/workflows/flask.yml @@ -47,7 +47,7 @@ jobs: sudo apt-get update -qy sudo apt-get -y install postgresql-client --no-install-recommends python -m pip install --upgrade pip - pip install flake8 pytest coverage + pip install -r requirements-dev.txt pip install -r requirements.txt - name: Prepare database diff --git a/.github/workflows/selenium.yml b/.github/workflows/selenium.yml index f9209484..fab0faab 100644 --- a/.github/workflows/selenium.yml +++ b/.github/workflows/selenium.yml @@ -47,7 +47,7 @@ jobs: sudo apt-get update -qy sudo apt-get -y install postgresql-client --no-install-recommends python -m pip install --upgrade pip - pip install flake8 pytest coverage + pip install -r requirements-dev.txt pip install -r requirements.txt pip install -e . mkdir bin diff --git a/requirements-dev.txt b/requirements-dev.txt index 02778f7d..c7110e32 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,7 @@ black +coverage isort flake8 pre-commit +pytest +selenium==4.1.5 diff --git a/requirements.txt b/requirements.txt index b886ac57..8ec1e0a4 100644 --- a/requirements.txt +++ b/requirements.txt @@ -42,7 +42,6 @@ sortedcontainers==2.1.0 tqdm==4.32.2 python-decouple==3.3 python-dotenv==0.14.0 -selenium==4.1.5 pyjwt==2.4.0 pint==0.9 py-dmidecode==0.1.0 From b2f8fe3ed5fa60075eae8dcf1f7b434c5ed9f2eb Mon Sep 17 00:00:00 2001 From: Santiago Lamora Date: Fri, 15 Jul 2022 12:10:10 +0200 Subject: [PATCH 5/9] Reorder imports because sentry is an optional dep --- examples/app.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/examples/app.py b/examples/app.py index 3a6a25a6..47671ec9 100644 --- a/examples/app.py +++ b/examples/app.py @@ -3,11 +3,8 @@ Example app with minimal configuration. Use this as a starting point. """ -import sentry_sdk -from decouple import config -# from flask_wtf.csrf import CSRFProtect -from sentry_sdk.integrations.flask import FlaskIntegration +from decouple import config from ereuse_devicehub.api.views import api from ereuse_devicehub.config import DevicehubConfig @@ -17,11 +14,17 @@ from ereuse_devicehub.labels.views import labels from ereuse_devicehub.views import core from ereuse_devicehub.workbench.views import workbench +# from flask_wtf.csrf import CSRFProtect + + # from werkzeug.contrib.profiler import ProfilerMiddleware SENTRY_DSN = config('SENTRY_DSN', None) if SENTRY_DSN: + import sentry_sdk + from sentry_sdk.integrations.flask import FlaskIntegration + sentry_sdk.init( dsn=SENTRY_DSN, integrations=[ From 6a6c0e5182db3addaa3f42b8c199a6c1e1261f0e Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 18 Jul 2022 10:07:37 +0200 Subject: [PATCH 6/9] show a error message creating placeholder device --- ereuse_devicehub/inventory/views.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 52a1a04a..649cb0ca 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -261,10 +261,13 @@ class DeviceCreateView(GenericMixin): next_url = url_for('inventory.devicelist') if lot_id: next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) - lots = self.context['lots'] - lot = lots.filter(Lot.id == lot_id).one() - lot.devices.add(snapshot.device) - db.session.add(lot) + if snapshot and snapshot.device: + lots = self.context['lots'] + lot = lots.filter(Lot.id == lot_id).one() + lot.devices.add(snapshot.device) + db.session.add(lot) + else: + messages.error('Sorry, the device could not be created') db.session.commit() messages.success('Device "{}" created successfully!'.format(form.type.data)) From 83ea86705d870667f646695e8c41059a0629c5c2 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 18 Jul 2022 10:56:05 +0200 Subject: [PATCH 7/9] test for add new placeholder in a lot --- tests/test_render_2_0.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 96415935..23ddf2d9 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1938,3 +1938,38 @@ def test_placeholder_log_excel_update(user3: UserClientFlask): assert "Excel" in body assert "placeholder_test.xls" in body assert "placeholder_test.csv" in body + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_add_placeholder_excel_to_lot(user3: UserClientFlask): + 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 + + uri = f'/inventory/lot/{lot_id}/upload-placeholder/' + body, status = user3.get(uri) + assert status == '200 OK' + assert "Upload Placeholder" in body + + file_path = Path(__file__).parent.joinpath('files').joinpath('placeholder_test.xls') + with open(file_path, 'rb') as excel: + data = { + 'csrf_token': generate_csrf(), + 'type': "Laptop", + 'placeholder_file': excel, + } + user3.post(uri, data=data, content_type="multipart/form-data") + assert Device.query.count() == 3 + dev = Device.query.first() + assert dev.hid == 'laptop-sony-vaio-12345678' + assert dev.placeholder.phid == 'a123' + assert dev.placeholder.info == 'Good conditions' + assert dev.placeholder.pallet == '24A' + assert dev.placeholder.id_device_supplier == 'TTT' From 26b322ba701b40998e7bd64e96b248366385dc99 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 18 Jul 2022 10:56:36 +0200 Subject: [PATCH 8/9] fix bug --- ereuse_devicehub/inventory/forms.py | 2 ++ ereuse_devicehub/inventory/views.py | 7 +++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ereuse_devicehub/inventory/forms.py b/ereuse_devicehub/inventory/forms.py index 65d2b5c3..7bf53d4f 100644 --- a/ereuse_devicehub/inventory/forms.py +++ b/ereuse_devicehub/inventory/forms.py @@ -335,6 +335,7 @@ class NewDeviceForm(FlaskForm): screen = FloatField('Screen size', [validators.Optional()]) def __init__(self, *args, **kwargs): + self.objs = set() self._obj = kwargs.pop('_obj', None) super().__init__(*args, **kwargs) if self._obj: @@ -545,6 +546,7 @@ class NewDeviceForm(FlaskForm): type="New device", source='Web form', placeholder=device.placeholder ) db.session.add(placeholder_log) + self.objs.add(device) def reset_ids(self): if self.amount.data > 1: diff --git a/ereuse_devicehub/inventory/views.py b/ereuse_devicehub/inventory/views.py index 649cb0ca..8749bf8e 100644 --- a/ereuse_devicehub/inventory/views.py +++ b/ereuse_devicehub/inventory/views.py @@ -257,15 +257,14 @@ class DeviceCreateView(GenericMixin): } ) if form.validate_on_submit(): - snapshot = form.save(commit=False) + form.save(commit=False) next_url = url_for('inventory.devicelist') if lot_id: next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) - if snapshot and snapshot.device: + if form.objs: lots = self.context['lots'] lot = lots.filter(Lot.id == lot_id).one() - lot.devices.add(snapshot.device) - db.session.add(lot) + lot.devices = lot.devices.union(form.objs) else: messages.error('Sorry, the device could not be created') From 3a6032c17d9493d16466d895c116ae0d3242e451 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Mon, 18 Jul 2022 11:28:02 +0200 Subject: [PATCH 9/9] add test for new placeholder from a lot adding from form --- tests/test_render_2_0.py | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/tests/test_render_2_0.py b/tests/test_render_2_0.py index 23ddf2d9..944995e6 100644 --- a/tests/test_render_2_0.py +++ b/tests/test_render_2_0.py @@ -1942,7 +1942,7 @@ def test_placeholder_log_excel_update(user3: UserClientFlask): @pytest.mark.mvp @pytest.mark.usefixtures(conftest.app_context.__name__) -def test_add_placeholder_excel_to_lot(user3: UserClientFlask): +def test_add_placeholder_excel_from_lot(user3: UserClientFlask): user3.get('/inventory/lot/add/') lot_name = 'lot1' data = { @@ -1973,3 +1973,41 @@ def test_add_placeholder_excel_to_lot(user3: UserClientFlask): assert dev.placeholder.info == 'Good conditions' assert dev.placeholder.pallet == '24A' assert dev.placeholder.id_device_supplier == 'TTT' + assert len(lot.devices) == 3 + + +@pytest.mark.mvp +@pytest.mark.usefixtures(conftest.app_context.__name__) +def test_add_new_placeholder_from_lot(user3: UserClientFlask): + 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() + assert len(lot.devices) == 0 + lot_id = lot.id + + uri = f'/inventory/lot/{lot_id}/device/add/' + + user3.get(uri) + data = { + 'csrf_token': generate_csrf(), + 'type': "Laptop", + 'phid': 'ace', + 'serial_number': "AAAAB", + 'model': "LC27T55", + 'manufacturer': "Samsung", + 'generation': 1, + 'weight': 0.1, + 'height': 0.1, + 'depth': 0.1, + 'id_device_supplier': "b2", + } + user3.post(uri, data=data) + dev = Device.query.one() + assert dev.hid == 'laptop-samsung-lc27t55-aaaab' + assert dev.placeholder.phid == 'ace' + assert len(lot.devices) == 1