From 3f5e6629042ff12e7f57479f1b5ae33eccf8bf4a Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Sun, 5 Nov 2023 01:06:27 -0500
Subject: [PATCH] Slightly reorganize selenium call chain hierarchy

---
 django_expanded_test_cases/mixins/__init__.py |  4 ++
 .../mixins/core_mixin.py                      | 43 +++++++++++++++++--
 .../mixins/live_server_mixin.py               | 13 +++---
 .../channels_live_server_test_case.py         |  4 +-
 .../test_cases/live_server_test_case.py       |  4 +-
 5 files changed, 57 insertions(+), 11 deletions(-)

diff --git a/django_expanded_test_cases/mixins/__init__.py b/django_expanded_test_cases/mixins/__init__.py
index e5bb218..4679864 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 9d106c7..7c7ad26 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 47d5128..8cf224f 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 b82e2bd..5dba371 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 3558530..020a82f 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()
 
-- 
GitLab