From 843edfcca4ef2519e9b5e7d53928d032a266d97d Mon Sep 17 00:00:00 2001
From: Brandon Rodriguez <brodriguez8774@gmail.com>
Date: Thu, 23 Nov 2023 05:25:18 -0500
Subject: [PATCH] Correct contextual output msg occuring in instance with only
 one item

---
 .../test_cases/integration_test_case.py       | 62 ++++++++++---------
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/django_expanded_test_cases/test_cases/integration_test_case.py b/django_expanded_test_cases/test_cases/integration_test_case.py
index 76b7e75..815518a 100644
--- a/django_expanded_test_cases/test_cases/integration_test_case.py
+++ b/django_expanded_test_cases/test_cases/integration_test_case.py
@@ -715,34 +715,37 @@ class IntegrationTestCase(BaseTestCase, ResponseTestCaseMixin):
             for index in range(len(expected_content)):
                 expected = expected_content[index]
 
-                # Update str in event of error.
-                updated_checked_content_str_addon = checked_content_str_addon.format(
-                    '{1}    * {0}{2}\n'.format(
-                        expected_content[index - 2],
-                        ETC_OUTPUT_EXPECTED_MATCH_COLOR,
-                        ETC_OUTPUT_RESET_COLOR,
-                    ) if index >= 2 else '',
-                    '{1}    * {0}{2}\n'.format(
-                        expected_content[index - 1],
-                        ETC_OUTPUT_EXPECTED_MATCH_COLOR,
-                        ETC_OUTPUT_RESET_COLOR,
-                    ) if index >= 1 else '',
-                    '{1}  > * {0}{2}\n'.format(
-                        expected_content[index],
-                        ETC_OUTPUT_ERROR_COLOR,
-                        ETC_OUTPUT_RESET_COLOR,
-                    ),
-                    '{1}    * {0}{2}\n'.format(
-                        expected_content[index + 1],
-                        ETC_OUTPUT_ACTUALS_MATCH_COLOR,
-                        ETC_OUTPUT_RESET_COLOR,
-                    ) if (len(expected_content) - index) > 1 else '',
-                    '{1}    * {0}{2}\n'.format(
-                        expected_content[index + 2],
-                        ETC_OUTPUT_ACTUALS_MATCH_COLOR,
-                        ETC_OUTPUT_RESET_COLOR,
-                    ) if (len(expected_content) - index) > 2 else '',
-                )
+                if len(expected_content) > 1:
+                    # Update str in event of error.
+                    updated_checked_content_str_addon = checked_content_str_addon.format(
+                        '{1}    * {0}{2}\n'.format(
+                            expected_content[index - 2],
+                            ETC_OUTPUT_EXPECTED_MATCH_COLOR,
+                            ETC_OUTPUT_RESET_COLOR,
+                        ) if index >= 2 else '',
+                        '{1}    * {0}{2}\n'.format(
+                            expected_content[index - 1],
+                            ETC_OUTPUT_EXPECTED_MATCH_COLOR,
+                            ETC_OUTPUT_RESET_COLOR,
+                        ) if index >= 1 else '',
+                        '{1}  > * {0}{2}\n'.format(
+                            expected_content[index],
+                            ETC_OUTPUT_ERROR_COLOR,
+                            ETC_OUTPUT_RESET_COLOR,
+                        ),
+                        '{1}    * {0}{2}\n'.format(
+                            expected_content[index + 1],
+                            ETC_OUTPUT_ACTUALS_MATCH_COLOR,
+                            ETC_OUTPUT_RESET_COLOR,
+                        ) if (len(expected_content) - index) > 1 else '',
+                        '{1}    * {0}{2}\n'.format(
+                            expected_content[index + 2],
+                            ETC_OUTPUT_ACTUALS_MATCH_COLOR,
+                            ETC_OUTPUT_RESET_COLOR,
+                        ) if (len(expected_content) - index) > 2 else '',
+                    )
+                else:
+                    updated_checked_content_str_addon = ''
 
                 stripped_expected = self.get_minimized_response_content(expected, strip_newlines=True)
                 if ignore_ordering:
@@ -860,7 +863,6 @@ class IntegrationTestCase(BaseTestCase, ResponseTestCaseMixin):
                         content_starts_after,
                         content_ends_before,
                         main_err_msg,
-                        '',
                     )
 
         # Return page content in case user wants to run additional logic on it.
@@ -870,7 +872,7 @@ class IntegrationTestCase(BaseTestCase, ResponseTestCaseMixin):
         self,
         actual_content, minimized_expected, display_expected,
         strip_actual_start, strip_actual_end,
-        err_msg, checked_content_str_addon
+        err_msg, checked_content_str_addon,
     ):
         """Internal sub-assertion for assertPageContent() function."""
         strip_err_msg = 'Expected content value was found, but occurred in "{0}" section. Expected was:\n{1}'
-- 
GitLab