mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-30 20:55:42 +00:00 
			
		
		
		
	Add unit tests
This commit is contained in:
		| @@ -209,8 +209,6 @@ function enableNavbar(options) { | |||||||
|  |  | ||||||
|         var state = localStorage.getItem(stateLabel); |         var state = localStorage.getItem(stateLabel); | ||||||
|  |  | ||||||
|         console.log(stateLabel, '->', state); |  | ||||||
|  |  | ||||||
|         var width = localStorage.getItem(widthLabel) || '250px'; |         var width = localStorage.getItem(widthLabel) || '250px'; | ||||||
|          |          | ||||||
|         if (state && state == 'open') { |         if (state && state == 'open') { | ||||||
|   | |||||||
							
								
								
									
										133
									
								
								InvenTree/part/test_bom_export.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										133
									
								
								InvenTree/part/test_bom_export.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,133 @@ | |||||||
|  | """ | ||||||
|  | Unit testing for BOM export functionality | ||||||
|  | """ | ||||||
|  |  | ||||||
|  | from django.test import TestCase | ||||||
|  |  | ||||||
|  | from django.urls import reverse | ||||||
|  | from django.contrib.auth import get_user_model | ||||||
|  | from django.contrib.auth.models import Group | ||||||
|  |  | ||||||
|  | from .models import Part, BomItem | ||||||
|  |  | ||||||
|  |  | ||||||
|  | class BomExportTest(TestCase): | ||||||
|  |  | ||||||
|  |     fixtures = [ | ||||||
|  |         'category', | ||||||
|  |         'part', | ||||||
|  |         'location', | ||||||
|  |         'bom', | ||||||
|  |     ] | ||||||
|  |  | ||||||
|  |     def setUp(self): | ||||||
|  |         super().setUp() | ||||||
|  |  | ||||||
|  |         # Create a user | ||||||
|  |         user = get_user_model() | ||||||
|  |  | ||||||
|  |         self.user = user.objects.create_user( | ||||||
|  |             username='username', | ||||||
|  |             email='user@email.com', | ||||||
|  |             password='password' | ||||||
|  |         ) | ||||||
|  |  | ||||||
|  |         # Put the user into a group with the correct permissions | ||||||
|  |         group = Group.objects.create(name='mygroup') | ||||||
|  |         self.user.groups.add(group) | ||||||
|  |  | ||||||
|  |         # Give the group *all* the permissions! | ||||||
|  |         for rule in group.rule_sets.all(): | ||||||
|  |             rule.can_view = True | ||||||
|  |             rule.can_change = True | ||||||
|  |             rule.can_add = True | ||||||
|  |             rule.can_delete = True | ||||||
|  |  | ||||||
|  |             rule.save() | ||||||
|  |  | ||||||
|  |         self.client.login(username='username', password='password') | ||||||
|  |  | ||||||
|  |         self.url = reverse('bom-download', kwargs={'pk': 100}) | ||||||
|  |  | ||||||
|  |     def test_export_csv(self): | ||||||
|  |         """ | ||||||
|  |         Test BOM download in CSV format | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         print("URL", self.url) | ||||||
|  |  | ||||||
|  |         params = { | ||||||
|  |             'file_format': 'csv', | ||||||
|  |             'cascade': True, | ||||||
|  |             'parameter_data': True, | ||||||
|  |             'stock_data': True, | ||||||
|  |             'supplier_data': True, | ||||||
|  |             'manufacturer_data': True, | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.client.get(self.url, data=params) | ||||||
|  |  | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |         content = response.headers['Content-Disposition'] | ||||||
|  |         self.assertEqual(content, 'attachment; filename="BOB | Bob | A2_BOM.csv"') | ||||||
|  |  | ||||||
|  |     def test_export_xls(self): | ||||||
|  |         """ | ||||||
|  |         Test BOM download in XLS format | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         params = { | ||||||
|  |             'file_format': 'xls', | ||||||
|  |             'cascade': True, | ||||||
|  |             'parameter_data': True, | ||||||
|  |             'stock_data': True, | ||||||
|  |             'supplier_data': True, | ||||||
|  |             'manufacturer_data': True, | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.client.get(self.url, data=params) | ||||||
|  |  | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |         content = response.headers['Content-Disposition'] | ||||||
|  |         self.assertEqual(content, 'attachment; filename="BOB | Bob | A2_BOM.xls"') | ||||||
|  |  | ||||||
|  |     def test_export_xlsx(self): | ||||||
|  |         """ | ||||||
|  |         Test BOM download in XLSX format | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         params = { | ||||||
|  |             'file_format': 'xlsx', | ||||||
|  |             'cascade': True, | ||||||
|  |             'parameter_data': True, | ||||||
|  |             'stock_data': True, | ||||||
|  |             'supplier_data': True, | ||||||
|  |             'manufacturer_data': True, | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.client.get(self.url, data=params) | ||||||
|  |  | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |     def test_export_json(self): | ||||||
|  |         """ | ||||||
|  |         Test BOM download in JSON format | ||||||
|  |         """ | ||||||
|  |  | ||||||
|  |         params = { | ||||||
|  |             'file_format': 'json', | ||||||
|  |             'cascade': True, | ||||||
|  |             'parameter_data': True, | ||||||
|  |             'stock_data': True, | ||||||
|  |             'supplier_data': True, | ||||||
|  |             'manufacturer_data': True, | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         response = self.client.get(self.url, data=params) | ||||||
|  |  | ||||||
|  |         self.assertEqual(response.status_code, 200) | ||||||
|  |  | ||||||
|  |         content = response.headers['Content-Disposition'] | ||||||
|  |         self.assertEqual(content, 'attachment; filename="BOB | Bob | A2_BOM.json"') | ||||||
		Reference in New Issue
	
	Block a user