mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Default expiry fix (#5466)
* Handle null values for expiry date * Add unit test for new case * Unit test fix * More unit test fixes
This commit is contained in:
parent
25a1380058
commit
5851094620
@ -136,7 +136,9 @@ class LabelTest(InvenTreeAPITestCase):
|
||||
# Print via the API (Note: will default to the builtin plugin if no plugin supplied)
|
||||
url = reverse('api-part-label-print', kwargs={'pk': label.pk})
|
||||
|
||||
part_pk = Part.objects.first().pk
|
||||
prt = Part.objects.first()
|
||||
part_pk = prt.pk
|
||||
part_name = prt.name
|
||||
|
||||
response = self.get(f'{url}?parts={part_pk}', expected_code=200)
|
||||
data = json.loads(response.content)
|
||||
@ -150,7 +152,7 @@ class LabelTest(InvenTreeAPITestCase):
|
||||
content = f.read()
|
||||
|
||||
# Test that each element has been rendered correctly
|
||||
self.assertIn("part: 1 - M2x4 LPHS", content)
|
||||
self.assertIn(f"part: {part_pk} - {part_name}", content)
|
||||
self.assertIn(f'data: {{"part": {part_pk}}}', content)
|
||||
self.assertIn("http://testserver/part/1/", content)
|
||||
self.assertIn("img/blank_image.png", content)
|
||||
|
@ -648,8 +648,10 @@ class StockList(APIDownloadMixin, ListCreateDestroyAPIView):
|
||||
if location:
|
||||
data['location'] = location.pk
|
||||
|
||||
expiry_date = data.get('expiry_date', None)
|
||||
|
||||
# An expiry date was *not* specified - try to infer it!
|
||||
if 'expiry_date' not in data and part.default_expiry > 0:
|
||||
if expiry_date is None and part.default_expiry > 0:
|
||||
data['expiry_date'] = datetime.now().date() + timedelta(days=part.default_expiry)
|
||||
|
||||
# Attempt to extract serial numbers from submitted data
|
||||
|
@ -110,8 +110,8 @@ class StockLocationTest(StockAPITestCase):
|
||||
'name': 'Location',
|
||||
'description': 'Another location for stock'
|
||||
}
|
||||
response = self.client.post(self.list_url, data, format='json')
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
self.post(self.list_url, data, expected_code=201)
|
||||
|
||||
def test_stock_location_delete(self):
|
||||
"""Test stock location deletion with different parameters"""
|
||||
@ -612,43 +612,42 @@ class StockItemTest(StockAPITestCase):
|
||||
"""Test the default location functionality, if a 'location' is not specified in the creation request."""
|
||||
# The part 'R_4K7_0603' (pk=4) has a default location specified
|
||||
|
||||
response = self.client.post(
|
||||
response = self.post(
|
||||
self.list_url,
|
||||
data={
|
||||
'part': 4,
|
||||
'quantity': 10
|
||||
}
|
||||
},
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.data['location'], 2)
|
||||
|
||||
# What if we explicitly set the location to a different value?
|
||||
|
||||
response = self.client.post(
|
||||
response = self.post(
|
||||
self.list_url,
|
||||
data={
|
||||
'part': 4,
|
||||
'quantity': 20,
|
||||
'location': 1,
|
||||
}
|
||||
},
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.data['location'], 1)
|
||||
|
||||
# And finally, what if we set the location explicitly to None?
|
||||
|
||||
response = self.client.post(
|
||||
response = self.post(
|
||||
self.list_url,
|
||||
data={
|
||||
'part': 4,
|
||||
'quantity': 20,
|
||||
'location': '',
|
||||
}
|
||||
},
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
self.assertEqual(response.data['location'], None)
|
||||
|
||||
def test_stock_item_create(self):
|
||||
@ -884,18 +883,14 @@ class StockItemTest(StockAPITestCase):
|
||||
'quantity': 10,
|
||||
}
|
||||
|
||||
response = self.client.post(self.list_url, data)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
response = self.post(self.list_url, data, expected_code=201)
|
||||
|
||||
self.assertIsNone(response.data['expiry_date'])
|
||||
|
||||
# Second test - create a new StockItem with an explicit expiry date
|
||||
data['expiry_date'] = '2022-12-12'
|
||||
|
||||
response = self.client.post(self.list_url, data)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
response = self.post(self.list_url, data, expected_code=201)
|
||||
|
||||
self.assertIsNotNone(response.data['expiry_date'])
|
||||
self.assertEqual(response.data['expiry_date'], '2022-12-12')
|
||||
@ -906,14 +901,19 @@ class StockItemTest(StockAPITestCase):
|
||||
'quantity': 10
|
||||
}
|
||||
|
||||
response = self.client.post(self.list_url, data)
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
response = self.post(self.list_url, data, expected_code=201)
|
||||
|
||||
# Expected expiry date is 10 days in the future
|
||||
expiry = datetime.now().date() + timedelta(10)
|
||||
|
||||
self.assertEqual(response.data['expiry_date'], expiry.isoformat())
|
||||
|
||||
# Test result when sending a blank value
|
||||
data['expiry_date'] = None
|
||||
|
||||
response = self.post(self.list_url, data, expected_code=201)
|
||||
self.assertEqual(response.data['expiry_date'], expiry.isoformat())
|
||||
|
||||
def test_purchase_price(self):
|
||||
"""Test that we can correctly read and adjust purchase price information via the API."""
|
||||
url = reverse('api-stock-detail', kwargs={'pk': 1})
|
||||
@ -1343,30 +1343,26 @@ class StockTestResultTest(StockAPITestCase):
|
||||
|
||||
url = self.get_url()
|
||||
|
||||
response = self.client.post(
|
||||
self.post(
|
||||
url,
|
||||
data={
|
||||
'test': 'A test',
|
||||
'result': True,
|
||||
},
|
||||
format='json'
|
||||
expected_code=400
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
# This one should pass!
|
||||
response = self.client.post(
|
||||
self.post(
|
||||
url,
|
||||
data={
|
||||
'test': 'A test',
|
||||
'stock_item': 105,
|
||||
'result': True,
|
||||
},
|
||||
format='json'
|
||||
expected_code=201
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
|
||||
def test_post(self):
|
||||
"""Test creation of a new test result."""
|
||||
url = self.get_url()
|
||||
@ -1382,9 +1378,7 @@ class StockTestResultTest(StockAPITestCase):
|
||||
'notes': 'I guess there was just too much pressure?',
|
||||
}
|
||||
|
||||
response = self.client.post(url, data, format='json')
|
||||
|
||||
self.assertEqual(response.status_code, status.HTTP_201_CREATED)
|
||||
response = self.post(url, data, expected_code=201)
|
||||
|
||||
response = self.client.get(url)
|
||||
self.assertEqual(len(response.data), n + 1)
|
||||
@ -1424,7 +1418,6 @@ class StockTestResultTest(StockAPITestCase):
|
||||
}
|
||||
|
||||
response = self.client.post(self.get_url(), data)
|
||||
|
||||
self.assertEqual(response.status_code, 201)
|
||||
|
||||
# Check that an attachment has been uploaded
|
||||
|
Loading…
Reference in New Issue
Block a user