mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 13:15:43 +00:00 
			
		
		
		
	Fix api_url for 'user' type (#10182)
* Fix api_url for 'user' type * Added regression test
This commit is contained in:
		| @@ -396,7 +396,7 @@ class InvenTreeMetadata(SimpleMetadata): | ||||
|  | ||||
|                 # Special case for special models | ||||
|                 if field_info['model'] == 'user': | ||||
|                     field_info['api_url'] = (reverse('api-user-list'),) | ||||
|                     field_info['api_url'] = reverse('api-user-list') | ||||
|                 elif field_info['model'] == 'group': | ||||
|                     field_info['api_url'] = reverse('api-group-list') | ||||
|                 elif field_info['model'] == 'contenttype': | ||||
|   | ||||
| @@ -42,6 +42,24 @@ class UserAPITests(InvenTreeAPITestCase): | ||||
|             fields['is_staff']['help_text'], 'Does this user have staff permissions' | ||||
|         ) | ||||
|  | ||||
|     def test_api_url(self): | ||||
|         """Test the 'api_url attribute in related API endpoints. | ||||
|  | ||||
|         Ref: https://github.com/inventree/InvenTree/pull/10182 | ||||
|         """ | ||||
|         self.user.is_superuser = True | ||||
|         self.user.save() | ||||
|  | ||||
|         url = reverse('api-build-list') | ||||
|         response = self.options(url) | ||||
|         actions = response.data['actions']['POST'] | ||||
|         issued_by = actions['issued_by'] | ||||
|  | ||||
|         self.assertEqual(issued_by['pk_field'], 'pk') | ||||
|         self.assertEqual(issued_by['model'], 'user') | ||||
|         self.assertEqual(issued_by['api_url'], reverse('api-user-list')) | ||||
|         self.assertEqual(issued_by['default'], self.user.pk) | ||||
|  | ||||
|     def test_user_api(self): | ||||
|         """Tests for User API endpoints.""" | ||||
|         url = reverse('api-user-list') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user