Merge branch 'testing' into feature/3598-binding

This commit is contained in:
Cayo Puigdefabregas 2022-07-18 11:54:11 +02:00
commit b039e491dc
10 changed files with 102 additions and 19 deletions

View File

@ -47,7 +47,7 @@ jobs:
sudo apt-get update -qy sudo apt-get update -qy
sudo apt-get -y install postgresql-client --no-install-recommends sudo apt-get -y install postgresql-client --no-install-recommends
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flake8 pytest coverage pip install -r requirements-dev.txt
pip install -r requirements.txt pip install -r requirements.txt
- name: Prepare database - name: Prepare database

View File

@ -47,7 +47,7 @@ jobs:
sudo apt-get update -qy sudo apt-get update -qy
sudo apt-get -y install postgresql-client --no-install-recommends sudo apt-get -y install postgresql-client --no-install-recommends
python -m pip install --upgrade pip python -m pip install --upgrade pip
pip install flake8 pytest coverage pip install -r requirements-dev.txt
pip install -r requirements.txt pip install -r requirements.txt
pip install -e . pip install -e .
mkdir bin mkdir bin

View File

@ -29,6 +29,7 @@ alembic -x inventory=dbtest upgrade head
## [2.2.0] - 2022-06-24 ## [2.2.0] - 2022-06-24
- [changed] #304 change anchor of link devices lots. - [changed] #304 change anchor of link devices lots.
- [fixed] #315 create in a lot a new placeholder.
## [2.2.0 rc2] - 2022-06-22 ## [2.2.0 rc2] - 2022-06-22
- [added] #299 Multiselect with Shift. - [added] #299 Multiselect with Shift.

View File

@ -339,6 +339,7 @@ class NewDeviceForm(FlaskForm):
screen = FloatField('Screen size', [validators.Optional()]) screen = FloatField('Screen size', [validators.Optional()])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
self.objs = set()
self._obj = kwargs.pop('_obj', None) self._obj = kwargs.pop('_obj', None)
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
if self._obj: if self._obj:
@ -549,6 +550,7 @@ class NewDeviceForm(FlaskForm):
type="New device", source='Web form', placeholder=device.placeholder type="New device", source='Web form', placeholder=device.placeholder
) )
db.session.add(placeholder_log) db.session.add(placeholder_log)
self.objs.add(device)
def reset_ids(self): def reset_ids(self):
if self.amount.data > 1: if self.amount.data > 1:

View File

@ -258,14 +258,16 @@ class DeviceCreateView(GenericMixin):
} }
) )
if form.validate_on_submit(): if form.validate_on_submit():
snapshot = form.save(commit=False) form.save(commit=False)
next_url = url_for('inventory.devicelist') next_url = url_for('inventory.devicelist')
if lot_id: if lot_id:
next_url = url_for('inventory.lotdevicelist', lot_id=lot_id) next_url = url_for('inventory.lotdevicelist', lot_id=lot_id)
lots = self.context['lots'] if form.objs:
lot = lots.filter(Lot.id == lot_id).one() lots = self.context['lots']
lot.devices.add(snapshot.device) lot = lots.filter(Lot.id == lot_id).one()
db.session.add(lot) lot.devices = lot.devices.union(form.objs)
else:
messages.error('Sorry, the device could not be created')
db.session.commit() db.session.commit()
messages.success('Device "{}" created successfully!'.format(form.type.data)) messages.success('Device "{}" created successfully!'.format(form.type.data))

View File

@ -3,11 +3,8 @@ Example app with minimal configuration.
Use this as a starting point. Use this as a starting point.
""" """
import sentry_sdk
from decouple import config
# from flask_wtf.csrf import CSRFProtect from decouple import config
from sentry_sdk.integrations.flask import FlaskIntegration
from ereuse_devicehub.api.views import api from ereuse_devicehub.api.views import api
from ereuse_devicehub.config import DevicehubConfig 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.views import core
from ereuse_devicehub.workbench.views import workbench from ereuse_devicehub.workbench.views import workbench
# from flask_wtf.csrf import CSRFProtect
# from werkzeug.contrib.profiler import ProfilerMiddleware # from werkzeug.contrib.profiler import ProfilerMiddleware
SENTRY_DSN = config('SENTRY_DSN', None) SENTRY_DSN = config('SENTRY_DSN', None)
if SENTRY_DSN: if SENTRY_DSN:
import sentry_sdk
from sentry_sdk.integrations.flask import FlaskIntegration
sentry_sdk.init( sentry_sdk.init(
dsn=SENTRY_DSN, dsn=SENTRY_DSN,
integrations=[ integrations=[

View File

@ -1,4 +1,7 @@
black black
coverage
isort isort
flake8 flake8
pre-commit pre-commit
pytest
selenium==4.1.5

2
requirements-prod.txt Normal file
View File

@ -0,0 +1,2 @@
sentry_sdk==1.6.0
blinker==1.4

View File

@ -42,15 +42,12 @@ sortedcontainers==2.1.0
tqdm==4.32.2 tqdm==4.32.2
python-decouple==3.3 python-decouple==3.3
python-dotenv==0.14.0 python-dotenv==0.14.0
selenium==4.1.5
pyjwt==2.4.0 pyjwt==2.4.0
pint==0.9 pint==0.9
py-dmidecode==0.1.0 py-dmidecode==0.1.0
pandas==1.3.5 pandas==1.3.5
numpy==1.21.6 numpy==1.22.0 # pandas dependency
odfpy==1.4.1 odfpy==1.4.1 # pandas dependency
xlrd==2.0.1 xlrd==2.0.1 # pandas dependency
openpyxl==3.0.10 openpyxl==3.0.10 # pandas dependency
et_xmlfile==1.1.0 et_xmlfile==1.1.0 # pandas dependency
sentry_sdk==1.6.0
blinker==1.4

View File

@ -1938,3 +1938,76 @@ def test_placeholder_log_excel_update(user3: UserClientFlask):
assert "Excel" in body assert "Excel" in body
assert "placeholder_test.xls" in body assert "placeholder_test.xls" in body
assert "placeholder_test.csv" in body assert "placeholder_test.csv" in body
@pytest.mark.mvp
@pytest.mark.usefixtures(conftest.app_context.__name__)
def test_add_placeholder_excel_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()
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'
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