Added location owner change test case to verify stock item owner in that location is also updated

This commit is contained in:
eeintech 2021-01-12 17:11:46 -05:00
parent 3054c637dd
commit 0a0a47a5e4
2 changed files with 16 additions and 2 deletions

View File

@ -384,7 +384,6 @@ class StockOwnershipTest(StockViewTestCase):
# Try to create new item with no owner # Try to create new item with no owner
response = self.client.post(reverse('stock-item-create'), response = self.client.post(reverse('stock-item-create'),
new_item, HTTP_X_REQUESTED_WITH='XMLHttpRequest') new_item, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
# print(response.content)
self.assertContains(response, '"form_valid": false', status_code=200) self.assertContains(response, '"form_valid": false', status_code=200)
# Try to create new item with invalid owner # Try to create new item with invalid owner
@ -398,3 +397,19 @@ class StockOwnershipTest(StockViewTestCase):
response = self.client.post(reverse('stock-item-create'), response = self.client.post(reverse('stock-item-create'),
new_item, HTTP_X_REQUESTED_WITH='XMLHttpRequest') new_item, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertContains(response, '"form_valid": true', status_code=200) self.assertContains(response, '"form_valid": true', status_code=200)
# Logout
self.client.logout()
# Login with admin
self.client.login(username='username', password='password')
# Switch owner of location
response = self.client.post(reverse('stock-location-edit', args=(location_created.pk,)),
{'name': new_location['name'], 'owner': user_group_owner.pk},
HTTP_X_REQUESTED_WITH='XMLHttpRequest')
self.assertContains(response, '"form_valid": true', status_code=200)
# Check that owner was updated for item in this location
stock_item = StockItem.objects.all().last()
self.assertEqual(stock_item.owner, user_group_owner)

View File

@ -1800,7 +1800,6 @@ class StockItemCreate(AjaxCreateView):
if not stock_ownership_control: if not stock_ownership_control:
form.fields['owner'].widget = HiddenInput() form.fields['owner'].widget = HiddenInput()
else: else:
print('> Stock ownership is enabled')
try: try:
location_owner = location.owner location_owner = location.owner
except AttributeError: except AttributeError: