diff --git a/django_expanded_test_cases/mixins/__init__.py b/django_expanded_test_cases/mixins/__init__.py index e5bb218fc084d2817323d55b201112f81a5e6735..4679864948b566e1eddd0b7da5eab02ebe1c7469 100644 --- a/django_expanded_test_cases/mixins/__init__.py +++ b/django_expanded_test_cases/mixins/__init__.py @@ -9,3 +9,7 @@ from .core_mixin import CoreTestCaseMixin # Expanded "Integration" TestCase utility mixins. from .response_mixin import ResponseTestCaseMixin + + +# Expanded "LiveServer" TestCase utility mixins. +from .live_server_mixin import LiveServerMixin diff --git a/django_expanded_test_cases/mixins/core_mixin.py b/django_expanded_test_cases/mixins/core_mixin.py index 9d106c7bea1556ba78443bd733929fc37af195ea..7c7ad269f97175cb1ca2bc6df66930264601c993 100644 --- a/django_expanded_test_cases/mixins/core_mixin.py +++ b/django_expanded_test_cases/mixins/core_mixin.py @@ -63,7 +63,30 @@ class DebugPrintMetaClass(type): # endregion Debug Print Wrapper Logic -class CoreTestCaseMixin: +class BaseMixin: + @classmethod + def set_up_class(cls, *args, **kwargs): + pass + + @classmethod + def set_up_test_data(cls, *args, **kwargs): + pass + + def set_up(self, *args, **kwargs): + pass + + def sub_test(self, *args, **kwargs): + pass + + @classmethod + def tear_down_class(cls, *args, **kwargs): + pass + + def tear_down(self, *args, **kwargs): + pass + + +class CoreTestCaseMixin(BaseMixin): """Core testing logic, used in all other expanded TestCase classes. For compatibility, does not inherit from @@ -87,6 +110,9 @@ class CoreTestCaseMixin: :param debug_print: Optional bool that indicates if debug output should print to console. Param overrides setting value if both param and setting are set. """ + # Call parent logic. + super().set_up_class(*args, **kwargs) + # Check user debug_print option. if debug_print is not None: cls._debug_print_bool = bool(debug_print) @@ -106,6 +132,9 @@ class CoreTestCaseMixin: :param extra_usergen_kwargs: Optional extra kwargs to pass into the get_user_model().objects.create_user() function. """ + # Call parent logic. + super().set_up_test_data(*args, **kwargs) + if ETC_AUTO_GENERATE_USERS: # Run logic to auto-generate test users. Setting is on by default. if extra_usergen_kwargs is None: @@ -119,7 +148,8 @@ class CoreTestCaseMixin: cls._auto_generate_test_users(extra_usergen_kwargs=extra_usergen_kwargs) def set_up(self, *args, **kwargs): - pass + # Call parent logic. + super().set_up(*args, **kwargs) def sub_test(self, *args, **kwargs): """ @@ -128,15 +158,20 @@ class CoreTestCaseMixin: However, since this is not inheriting from a given TestCase, calling the literal function here would override instead. """ + # Call parent logic. + super().sub_test(*args, **kwargs) + # Reset display error, in case multiple subtests run and fail in a given test. self._error_displayed = False @classmethod def tear_down_class(cls, *args, **kwargs): - pass + # Call parent logic. + super().tear_down_class(*args, **kwargs) def tear_down(self, *args, **kwargs): - pass + # Call parent logic. + super().tear_down(*args, **kwargs) @classmethod def _auto_generate_test_users(cls, extra_usergen_kwargs=None): diff --git a/django_expanded_test_cases/mixins/live_server_mixin.py b/django_expanded_test_cases/mixins/live_server_mixin.py index 47d5128f25e6e66036dcadd9b45ec63261ab4b24..8cf224f0cfc54c40671dfd73486bafea30fc238e 100644 --- a/django_expanded_test_cases/mixins/live_server_mixin.py +++ b/django_expanded_test_cases/mixins/live_server_mixin.py @@ -153,6 +153,9 @@ class LiveServerMixin(ResponseTestCaseMixin): cls.driver = cls.create_driver(cls) def set_up(self): + # Call parent logic. + super().set_up() + self._error_displayed = False def sub_test(self, *args, **kwargs): @@ -161,13 +164,13 @@ class LiveServerMixin(ResponseTestCaseMixin): @classmethod def tear_down_class(cls): + # Call parent teardown logic. + super().tear_down_class() + # Close all remaining driver instances for class. while len(cls._driver_set) > 0: cls.close_driver(cls, cls._driver_set[0]) - # Call parent teardown logic. - super().tear_down_class() - # region Utility Functions def create_driver(self, switch_window=True): @@ -181,8 +184,8 @@ class LiveServerMixin(ResponseTestCaseMixin): # Handle window positions, if set. # If not provided, then defaults to however the OS spawns windows in. - # cls._window_positions = ETC_SELENIUM_WINDOW_POSITIONS - # cls._window_position_index = 0 + self._window_positions = ETC_SELENIUM_WINDOW_POSITIONS + self._window_position_index = 0 if self._window_positions: # Window position value exists. Attempt to read in. try: diff --git a/django_expanded_test_cases/test_cases/channels_live_server_test_case.py b/django_expanded_test_cases/test_cases/channels_live_server_test_case.py index b82e2bd7a5d86249742b460c91e6e8f19df6894e..5dba37129788f82128f13257685ffea21061acaa 100644 --- a/django_expanded_test_cases/test_cases/channels_live_server_test_case.py +++ b/django_expanded_test_cases/test_cases/channels_live_server_test_case.py @@ -27,7 +27,9 @@ class ChannelsLiveServerTestCase(DjangoChannelsLiveServerTestCase, LiveServerMix @classmethod def setUpTestData(cls): - """""" + # Run parent setup logic. + super().setUpTestData() + # Initialize default data models. cls.set_up_test_data() diff --git a/django_expanded_test_cases/test_cases/live_server_test_case.py b/django_expanded_test_cases/test_cases/live_server_test_case.py index 35585302a605962baac8ec10f7b9d0cfc964a4de..020a82fc5e40a102eb038b3dec8ad5d021fc673d 100644 --- a/django_expanded_test_cases/test_cases/live_server_test_case.py +++ b/django_expanded_test_cases/test_cases/live_server_test_case.py @@ -28,7 +28,9 @@ class LiveServerTestCase(DjangoLiveServerTestCase, LiveServerMixin): @classmethod def setUpTestData(cls): - """""" + # Run parent setup logic. + super().setUpTestData() + # Initialize default data models. cls.set_up_test_data()