mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
* Handle AttributeError in convert_physical_value
* Added new unit test
(cherry picked from commit 9abcc0ec34
)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
parent
4a5ebf8f01
commit
c59eee7359
@ -91,7 +91,7 @@ def convert_physical_value(value: str, unit: str = None):
|
||||
# At this point we *should* have a valid pint value
|
||||
# To double check, look at the maginitude
|
||||
float(val.magnitude)
|
||||
except (TypeError, ValueError):
|
||||
except (TypeError, ValueError, AttributeError):
|
||||
error = _('Provided value is not a valid number')
|
||||
except (pint.errors.UndefinedUnitError, pint.errors.DefinitionSyntaxError):
|
||||
error = _('Provided value has an invalid unit')
|
||||
|
@ -56,6 +56,23 @@ class ConversionTest(TestCase):
|
||||
q = InvenTree.conversion.convert_physical_value(val).to_base_units()
|
||||
self.assertEqual(q.magnitude, expected)
|
||||
|
||||
def test_invalid_values(self):
|
||||
"""Test conversion of invalid inputs"""
|
||||
|
||||
inputs = [
|
||||
'-',
|
||||
';;',
|
||||
'-x',
|
||||
'?',
|
||||
'--',
|
||||
'+',
|
||||
'++',
|
||||
]
|
||||
|
||||
for val in inputs:
|
||||
with self.assertRaises(ValidationError):
|
||||
InvenTree.conversion.convert_physical_value(val)
|
||||
|
||||
|
||||
class ValidatorTest(TestCase):
|
||||
"""Simple tests for custom field validators."""
|
||||
|
@ -1404,6 +1404,7 @@ function createPartParameter(part_id, options={}) {
|
||||
function editPartParameter(param_id, options={}) {
|
||||
options.fields = partParameterFields();
|
||||
options.title = '{% trans "Edit Parameter" %}';
|
||||
options.focus = 'data';
|
||||
|
||||
options.processBeforeUpload = function(data) {
|
||||
// Convert data to string
|
||||
|
Loading…
Reference in New Issue
Block a user