ignore wrong lookup values for coverage

This commit is contained in:
Matthias 2022-03-13 19:42:06 +01:00
parent bd2b279390
commit beb170c02d
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -47,7 +47,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
except json.JSONDecodeError: except json.JSONDecodeError:
return False return False
else: else:
return False return False # pragma: no cover
# If any of the following keys are in the JSON data, # If any of the following keys are in the JSON data,
# let's go ahead and assume that the code is a valid InvenTree one... # let's go ahead and assume that the code is a valid InvenTree one...
@ -70,10 +70,10 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
# Initially try casting to an integer # Initially try casting to an integer
try: try:
pk = int(data) pk = int(data)
except (TypeError, ValueError): except (TypeError, ValueError): # pragma: no cover
pk = None pk = None
if pk is None: if pk is None: # pragma: no cover
try: try:
pk = self.data[k]['id'] pk = self.data[k]['id']
except (AttributeError, KeyError): except (AttributeError, KeyError):
@ -82,7 +82,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
try: try:
item = StockItem.objects.get(pk=pk) item = StockItem.objects.get(pk=pk)
return item return item
except (ValueError, StockItem.DoesNotExist): except (ValueError, StockItem.DoesNotExist): # pragma: no cover
raise ValidationError({k, "Stock item does not exist"}) raise ValidationError({k, "Stock item does not exist"})
return None return None
@ -97,10 +97,10 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
# First try simple integer lookup # First try simple integer lookup
try: try:
pk = int(self.data[k]) pk = int(self.data[k])
except (TypeError, ValueError): except (TypeError, ValueError): # pragma: no cover
pk = None pk = None
if pk is None: if pk is None: # pragma: no cover
# Lookup by 'id' field # Lookup by 'id' field
try: try:
pk = self.data[k]['id'] pk = self.data[k]['id']
@ -110,7 +110,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
try: try:
loc = StockLocation.objects.get(pk=pk) loc = StockLocation.objects.get(pk=pk)
return loc return loc
except (ValueError, StockLocation.DoesNotExist): except (ValueError, StockLocation.DoesNotExist): # pragma: no cover
raise ValidationError({k, "Stock location does not exist"}) raise ValidationError({k, "Stock location does not exist"})
return None return None
@ -125,10 +125,10 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
# Try integer lookup first # Try integer lookup first
try: try:
pk = int(self.data[k]) pk = int(self.data[k])
except (TypeError, ValueError): except (TypeError, ValueError): # pragma: no cover
pk = None pk = None
if pk is None: if pk is None: # pragma: no cover
try: try:
pk = self.data[k]['id'] pk = self.data[k]['id']
except (AttributeError, KeyError): except (AttributeError, KeyError):
@ -137,7 +137,7 @@ class InvenTreeBarcodePlugin(BarcodePlugin):
try: try:
part = Part.objects.get(pk=pk) part = Part.objects.get(pk=pk)
return part return part
except (ValueError, Part.DoesNotExist): except (ValueError, Part.DoesNotExist): # pragma: no cover
raise ValidationError({k, 'Part does not exist'}) raise ValidationError({k, 'Part does not exist'})
return None return None