Merge pull request #363 from eReuse/bugfix/3831-bug-documents
fix bug and test
This commit is contained in:
commit
2ecec6590a
|
@ -1247,10 +1247,13 @@ class TradeDocumentForm(FlaskForm):
|
|||
super().__init__(*args, **kwargs)
|
||||
self._lot = Lot.query.filter(Lot.id == lot_id).one()
|
||||
|
||||
if not self._lot.transfer:
|
||||
self.form_errors = ['Error, this lot is not a transfer lot.']
|
||||
|
||||
def validate(self, extra_validators=None):
|
||||
is_valid = super().validate(extra_validators)
|
||||
|
||||
if g.user not in [self._lot.trade.user_from, self._lot.trade.user_to]:
|
||||
if g.user not in [self._lot.transfer.user_from, self._lot.transfer.user_to]:
|
||||
is_valid = False
|
||||
|
||||
return is_valid
|
||||
|
@ -1268,7 +1271,7 @@ class TradeDocumentForm(FlaskForm):
|
|||
self._obj.file_name = file_name
|
||||
self._obj.file_hash = file_hash
|
||||
db.session.add(self._obj)
|
||||
self._lot.trade.documents.add(self._obj)
|
||||
self._lot.documents.add(self._obj)
|
||||
if commit:
|
||||
db.session.commit()
|
||||
|
||||
|
|
|
@ -724,7 +724,7 @@ class NewTradeView(DeviceListMixin, NewActionView):
|
|||
return flask.redirect(next_url)
|
||||
|
||||
|
||||
class NewTradeDocumentView(View):
|
||||
class NewTradeDocumentView(GenericMixin):
|
||||
methods = ['POST', 'GET']
|
||||
decorators = [login_required]
|
||||
template_name = 'inventory/trade_document.html'
|
||||
|
|
|
@ -462,10 +462,24 @@
|
|||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for doc in lot.documents %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if doc.url.to_text() %}
|
||||
<a href="{{ doc.url.to_text() }}" target="_blank">{{ doc.file_name}}</a>
|
||||
{% else %}
|
||||
{{ doc.file_name}}
|
||||
{% endif %}
|
||||
</td>
|
||||
<td>
|
||||
{{ doc.created.strftime('%H:%M %d-%m-%Y')}}
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
{% for doc in lot.trade.documents %}
|
||||
<tr>
|
||||
<td>
|
||||
{% if doc.url %}
|
||||
{% if doc.url.to_text() %}
|
||||
<a href="{{ doc.url.to_text() }}" target="_blank">{{ doc.file_name}}</a>
|
||||
{% else %}
|
||||
{{ doc.file_name}}
|
||||
|
|
|
@ -184,7 +184,6 @@ def test_upload_snapshot(user3: UserClientFlask):
|
|||
@pytest.mark.mvp
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
def test_upload_snapshot_to_lot(user3: UserClientFlask):
|
||||
# TODO
|
||||
user3.get('/inventory/lot/add/')
|
||||
lot_name = 'lot1'
|
||||
data = {
|
||||
|
@ -2406,3 +2405,55 @@ def test_bug_3821_binding(user3: UserClientFlask):
|
|||
body, status = user3.get(uri)
|
||||
assert status == '200 OK'
|
||||
assert 'is not a Snapshot device!' in body
|
||||
|
||||
|
||||
@pytest.mark.mvp
|
||||
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||
def test_bug_3831_documents(user3: UserClientFlask):
|
||||
uri = '/inventory/lot/add/'
|
||||
user3.get(uri)
|
||||
lot_name = 'lot1'
|
||||
data = {
|
||||
'name': lot_name,
|
||||
'csrf_token': generate_csrf(),
|
||||
}
|
||||
user3.post(uri, data=data)
|
||||
lot = Lot.query.filter_by(name=lot_name).one()
|
||||
|
||||
lot_id = lot.id
|
||||
uri = f'/inventory/lot/{lot_id}/trade-document/add/'
|
||||
body, status = user3.get(uri)
|
||||
txt = 'Error, this lot is not a transfer lot.'
|
||||
|
||||
assert status == '200 OK'
|
||||
assert txt in body
|
||||
|
||||
uri = f'/inventory/lot/{lot_id}/transfer/incoming/'
|
||||
user3.get(uri)
|
||||
data = {'csrf_token': generate_csrf(), 'code': 'AAA'}
|
||||
|
||||
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
|
||||
|
||||
uri = f'/inventory/lot/{lot_id}/trade-document/add/'
|
||||
body, status = user3.get(uri)
|
||||
|
||||
b_file = b'1234567890'
|
||||
file_name = "my_file.doc"
|
||||
file_upload = (BytesIO(b_file), file_name)
|
||||
|
||||
data = {
|
||||
'csrf_token': generate_csrf(),
|
||||
'url': "",
|
||||
'description': "",
|
||||
'document_id': "",
|
||||
'date': "",
|
||||
'file': file_upload,
|
||||
}
|
||||
|
||||
uri = f'/inventory/lot/{lot_id}/trade-document/add/'
|
||||
# body, status = user3.post(uri, data=data, content_type="multipart/form-data")
|
||||
# assert status == '200 OK'
|
||||
|
|
Reference in New Issue