From 17b1ba9e368177305eadf510e4fe37cc5e33dbb1 Mon Sep 17 00:00:00 2001 From: Alan Crosswell Date: Thu, 5 Sep 2024 14:08:46 -0400 Subject: [PATCH 1/3] fix djmain changes the error message text --- tests/test_commands.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index 5204ebf77..ff21d2757 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -140,6 +140,11 @@ def test_validation_failed_message(self): stdout=output, ) - self.assertIn("user", output.getvalue()) - self.assertIn("783", output.getvalue()) - self.assertIn("does not exist", output.getvalue()) + output_str = output.getvalue() + self.assertIn("user", output_str) + self.assertIn("783", output_str) + # newer Django (>5.1) changes the error message from "does not exist" to "is not a valid choice" + self.assertTrue( + any(substring in output_str for substring in ["does not exist", "is not a valid choice"]), + f"Output did not contain 'does not exist' or 'is not a valid choice'. Actual output: {output_str}", + ) From 6bf75c0f1882ad0a1371e91f2bcdf8d676265ca9 Mon Sep 17 00:00:00 2001 From: Alan Crosswell Date: Thu, 5 Sep 2024 14:18:03 -0400 Subject: [PATCH 2/3] remove unnecceesary verbose assert message and avoid E501 --- tests/test_commands.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index ff21d2757..f9b030dd7 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -145,6 +145,5 @@ def test_validation_failed_message(self): self.assertIn("783", output_str) # newer Django (>5.1) changes the error message from "does not exist" to "is not a valid choice" self.assertTrue( - any(substring in output_str for substring in ["does not exist", "is not a valid choice"]), - f"Output did not contain 'does not exist' or 'is not a valid choice'. Actual output: {output_str}", + any(substring in output_str for substring in ["does not exist", "is not a valid choice"]) ) From c8f9f8a5090147be1411319b6449724d98a42d78 Mon Sep 17 00:00:00 2001 From: Alan Crosswell Date: Fri, 6 Sep 2024 11:44:18 -0400 Subject: [PATCH 3/3] conditionalize error message test based on Django version --- tests/test_commands.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_commands.py b/tests/test_commands.py index f9b030dd7..c4d359ce5 100644 --- a/tests/test_commands.py +++ b/tests/test_commands.py @@ -130,6 +130,8 @@ def test_application_created_with_algorithm(self): self.assertEqual(app.algorithm, "RS256") def test_validation_failed_message(self): + import django + output = StringIO() call_command( "createapplication", @@ -143,7 +145,7 @@ def test_validation_failed_message(self): output_str = output.getvalue() self.assertIn("user", output_str) self.assertIn("783", output_str) - # newer Django (>5.1) changes the error message from "does not exist" to "is not a valid choice" - self.assertTrue( - any(substring in output_str for substring in ["does not exist", "is not a valid choice"]) - ) + if django.VERSION < (5, 2): + self.assertIn("does not exist", output_str) + else: + self.assertIn("is not a valid choice", output_str)