mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Fix unit test (#6084)
* Add debug print statements * Add more debug prints * Upate unit test - Use global variables to ensure correct error is raised - collect() does not always collect in the same "order"
This commit is contained in:
parent
64671dce20
commit
2c45d88d15
@ -832,6 +832,7 @@ def inheritors(cls):
|
||||
"""Return all classes that are subclasses from the supplied cls."""
|
||||
subcls = set()
|
||||
work = [cls]
|
||||
|
||||
while work:
|
||||
parent = work.pop()
|
||||
for child in parent.__subclasses__():
|
||||
|
@ -4,6 +4,13 @@ from InvenTree.unit_test import InvenTreeTestCase
|
||||
|
||||
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):
|
||||
"""Error for testing purposes."""
|
||||
@ -16,6 +23,7 @@ def dflt(*args, **kwargs):
|
||||
|
||||
def _clean_storage(refs):
|
||||
"""Clean the storage."""
|
||||
|
||||
for ref in refs:
|
||||
del ref
|
||||
storage.collect()
|
||||
@ -38,9 +46,20 @@ 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):
|
||||
raise MyPrivateError('RaisingImplementation')
|
||||
"""Custom transition method."""
|
||||
|
||||
global raise_storage
|
||||
|
||||
if raise_storage:
|
||||
raise MyPrivateError('RaisingImplementation')
|
||||
|
||||
# Ensure registering works
|
||||
storage.collect()
|
||||
@ -58,6 +77,12 @@ 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):
|
||||
def transition(self, *args, **kwargs):
|
||||
|
@ -71,6 +71,7 @@ class StateTransitionMixin:
|
||||
instance: Object instance
|
||||
default_action: Default action to be taken if none of the transitions returns a boolean true value
|
||||
"""
|
||||
|
||||
# Check if there is a custom override function for this transition
|
||||
for override in storage.list:
|
||||
rslt = override.transition(current_state, target_state, instance, default_action, **kwargs)
|
||||
|
Loading…
Reference in New Issue
Block a user