mirror of
				https://github.com/inventree/InvenTree.git
				synced 2025-10-31 05:05:42 +00:00 
			
		
		
		
	Tests: remove dead paths in test files (#6965)
* remove dead paths
* disable cov on fix for flaky tests
* remove dead path
* remove coverage from faliover path
* style fixes
* remove unused path
* cleanup
* ignore failure state for coverage
* reduce function complexity
* style fix
* more style fixes
* Revert "remove dead paths"
This reverts commit e6618d1925.
* improve error message
			
			
This commit is contained in:
		| @@ -1148,12 +1148,8 @@ class TestSettings(InvenTreeTestCase): | ||||
|  | ||||
|     superuser = True | ||||
|  | ||||
|     def in_env_context(self, envs=None): | ||||
|     def in_env_context(self, envs): | ||||
|         """Patch the env to include the given dict.""" | ||||
|         # Set default - see B006 | ||||
|         if envs is None: | ||||
|             envs = {} | ||||
|  | ||||
|         return mock.patch.dict(os.environ, envs) | ||||
|  | ||||
|     def run_reload(self, envs=None): | ||||
| @@ -1588,15 +1584,15 @@ class ClassValidationMixinTest(TestCase): | ||||
|  | ||||
|         def test(self): | ||||
|             """Test function.""" | ||||
|             pass | ||||
|             ... | ||||
|  | ||||
|         def test1(self): | ||||
|             """Test function.""" | ||||
|             pass | ||||
|             ... | ||||
|  | ||||
|         def test2(self): | ||||
|             """Test function.""" | ||||
|             pass | ||||
|             ... | ||||
|  | ||||
|         required_attributes = ['NAME'] | ||||
|         required_overrides = [test, [test1, test2]] | ||||
| @@ -1616,11 +1612,11 @@ class ClassValidationMixinTest(TestCase): | ||||
|  | ||||
|             def test(self): | ||||
|                 """Test function.""" | ||||
|                 pass | ||||
|                 ... | ||||
|  | ||||
|             def test2(self): | ||||
|                 """Test function.""" | ||||
|                 pass | ||||
|                 ... | ||||
|  | ||||
|         TestClass.validate() | ||||
|  | ||||
| @@ -1643,7 +1639,7 @@ class ClassValidationMixinTest(TestCase): | ||||
|  | ||||
|             def test2(self): | ||||
|                 """Test function.""" | ||||
|                 pass | ||||
|                 ... | ||||
|  | ||||
|         with self.assertRaisesRegex( | ||||
|             NotImplementedError, | ||||
|   | ||||
| @@ -157,12 +157,14 @@ class UserMixin: | ||||
|  | ||||
|         if type(assign_all) is not bool: | ||||
|             # Raise exception if common mistake is made! | ||||
|             raise TypeError('assignRole: assign_all must be a boolean value') | ||||
|             raise TypeError( | ||||
|                 'assignRole: assign_all must be a boolean value' | ||||
|             )  # pragma: no cover | ||||
|  | ||||
|         if not role and not assign_all: | ||||
|             raise ValueError( | ||||
|                 'assignRole: either role must be provided, or assign_all must be set' | ||||
|             ) | ||||
|             )  # pragma: no cover | ||||
|  | ||||
|         if not assign_all and role: | ||||
|             rule, perm = role.split('.') | ||||
| @@ -241,14 +243,18 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase): | ||||
|             yield  # your test will be run here | ||||
|  | ||||
|         if verbose: | ||||
|             msg = '\r\n%s' % json.dumps(context.captured_queries, indent=4) | ||||
|             msg = '\r\n%s' % json.dumps( | ||||
|                 context.captured_queries, indent=4 | ||||
|             )  # pragma: no cover | ||||
|         else: | ||||
|             msg = None | ||||
|  | ||||
|         n = len(context.captured_queries) | ||||
|  | ||||
|         if debug: | ||||
|             print(f'Expected less than {value} queries, got {n} queries') | ||||
|             print( | ||||
|                 f'Expected less than {value} queries, got {n} queries' | ||||
|             )  # pragma: no cover | ||||
|  | ||||
|         self.assertLess(n, value, msg=msg) | ||||
|  | ||||
| @@ -258,7 +264,7 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase): | ||||
|         if expected_code is None: | ||||
|             return | ||||
|  | ||||
|         if expected_code != response.status_code: | ||||
|         if expected_code != response.status_code:  # pragma: no cover | ||||
|             print( | ||||
|                 f"Unexpected {method} response at '{url}': status_code = {response.status_code}" | ||||
|             ) | ||||
| @@ -280,11 +286,7 @@ class InvenTreeAPITestCase(ExchangeRateMixin, UserMixin, APITestCase): | ||||
|         response = self.client.options(url) | ||||
|         self.assertEqual(response.status_code, 200) | ||||
|  | ||||
|         actions = response.data.get('actions', None) | ||||
|  | ||||
|         if not actions: | ||||
|             actions = {} | ||||
|  | ||||
|         actions = response.data.get('actions', {}) | ||||
|         return actions | ||||
|  | ||||
|     def get(self, url, data=None, expected_code=200, format='json', **kwargs): | ||||
|   | ||||
| @@ -46,7 +46,7 @@ class NewsFeedTests(TestCase): | ||||
|         """Tests that news feed is updated when accessing a valid URL.""" | ||||
|         try: | ||||
|             common_tasks.update_news_feed() | ||||
|         except Exception as ex: | ||||
|         except Exception as ex:  # pragma: no cover | ||||
|             self.fail(f'News feed raised exceptions: {ex}') | ||||
|  | ||||
|         self.assertNotEqual(NewsFeedEntry.objects.all().count(), 0) | ||||
|   | ||||
| @@ -1048,18 +1048,18 @@ class ColorThemeTest(TestCase): | ||||
|         """Test that default choices are returned.""" | ||||
|         result = ColorTheme.get_color_themes_choices() | ||||
|  | ||||
|         # skip | ||||
|         # skip due to directories not being set up | ||||
|         if not result: | ||||
|             return | ||||
|             return  # pragma: no cover | ||||
|         self.assertIn(('default', 'Default'), result) | ||||
|  | ||||
|     def test_valid_choice(self): | ||||
|         """Check that is_valid_choice works correctly.""" | ||||
|         result = ColorTheme.get_color_themes_choices() | ||||
|  | ||||
|         # skip | ||||
|         # skip due to directories not being set up | ||||
|         if not result: | ||||
|             return | ||||
|             return  # pragma: no cover | ||||
|  | ||||
|         # check wrong reference | ||||
|         self.assertFalse(ColorTheme.is_valid_choice('abcdd')) | ||||
| @@ -1099,10 +1099,12 @@ class CurrencyAPITests(InvenTreeAPITestCase): | ||||
|                 # Exit early | ||||
|                 return | ||||
|  | ||||
|             # Delay and try again | ||||
|             time.sleep(10) | ||||
|             # Delay and try again - might have problems with exchange rate endpoint | ||||
|             time.sleep(10)  # pragma: no cover | ||||
|  | ||||
|         raise TimeoutError('Could not refresh currency exchange data after 5 attempts') | ||||
|         raise TimeoutError( | ||||
|             'Could not refresh currency exchange data after 5 attempts' | ||||
|         )  # pragma: no cover | ||||
|  | ||||
|  | ||||
| class NotesImageTest(InvenTreeAPITestCase): | ||||
|   | ||||
| @@ -6,10 +6,8 @@ from .transition import StateTransitionMixin, TransitionMethod, storage | ||||
|  | ||||
| # Global variables to determine which transition classes raises an exception | ||||
| global raise_storage | ||||
| global raise_function | ||||
|  | ||||
| raise_storage = False | ||||
| raise_function = False | ||||
|  | ||||
|  | ||||
| class MyPrivateError(NotImplementedError): | ||||
| @@ -44,10 +42,8 @@ class TransitionTests(InvenTreeTestCase): | ||||
|     def test_storage(self): | ||||
|         """Ensure that the storage collection mechanism works.""" | ||||
|         global raise_storage | ||||
|         global raise_function | ||||
|  | ||||
|         raise_storage = True | ||||
|         raise_function = False | ||||
|  | ||||
|         class RaisingImplementation(TransitionMethod): | ||||
|             def transition(self, *args, **kwargs): | ||||
| @@ -73,10 +69,8 @@ class TransitionTests(InvenTreeTestCase): | ||||
|     def test_function(self): | ||||
|         """Ensure that a TransitionMethod's function is called.""" | ||||
|         global raise_storage | ||||
|         global raise_function | ||||
|  | ||||
|         raise_storage = False | ||||
|         raise_function = True | ||||
|  | ||||
|         # Setup | ||||
|         class ValidImplementationNoEffect(TransitionMethod): | ||||
| @@ -85,12 +79,7 @@ class TransitionTests(InvenTreeTestCase): | ||||
|  | ||||
|         class ValidImplementation(TransitionMethod): | ||||
|             def transition(self, *args, **kwargs): | ||||
|                 global raise_function | ||||
|  | ||||
|                 if raise_function: | ||||
|                     return 1234 | ||||
|                 else: | ||||
|                     return False | ||||
|                 return 1234 | ||||
|  | ||||
|         storage.collect() | ||||
|         self.assertIn(ValidImplementationNoEffect, storage.list) | ||||
|   | ||||
| @@ -23,7 +23,7 @@ class GeneralStatus(StatusCode): | ||||
|  | ||||
|     def GHI(self):  # This should be ignored | ||||
|         """A invalid function.""" | ||||
|         pass | ||||
|         ... | ||||
|  | ||||
|  | ||||
| class GeneralStateTest(InvenTreeTestCase): | ||||
|   | ||||
| @@ -64,11 +64,6 @@ class LabelTest(InvenTreeAPITestCase): | ||||
|         response = self.get(url, {'enabled': False}) | ||||
|         self.assertEqual(len(response.data), 0) | ||||
|  | ||||
|         # Disable each report | ||||
|         for label in labels: | ||||
|             label.enabled = False | ||||
|             label.save() | ||||
|  | ||||
|         # Filter by "enabled" status | ||||
|         response = self.get(url, {'enabled': True}) | ||||
|         self.assertEqual(len(response.data), 0) | ||||
|   | ||||
| @@ -143,7 +143,7 @@ class MachineAPITest(TestMachineRegistryMixin, InvenTreeAPITestCase): | ||||
|             for error in errors_msgs: | ||||
|                 if re.match(pattern, error): | ||||
|                     break | ||||
|             else: | ||||
|             else:  # pragma: no cover | ||||
|                 errors_str = '\n'.join([f'- {e}' for e in errors_msgs]) | ||||
|                 self.fail( | ||||
|                     f"""Error message matching pattern '{pattern}' not found in machine registry errors:\n{errors_str}""" | ||||
|   | ||||
| @@ -554,9 +554,6 @@ class StockItemListTest(StockAPITestCase): | ||||
|         ) | ||||
|         self.assertTrue(len(response.data) < StockItem.objects.count()) | ||||
|  | ||||
|         for result in response.data: | ||||
|             self.assertIsNone(result['location']) | ||||
|  | ||||
|         # Filter with "cascade=True" | ||||
|         response = self.get( | ||||
|             self.list_url, {'location': 'null', 'cascade': True}, expected_code=200 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user