From caf04210825d3f1922d38fbc236ad0eccfb2d48a Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Thu, 26 Dec 2024 03:31:41 +0100 Subject: [PATCH] fix test asserts --- src/backend/InvenTree/InvenTree/tests.py | 10 +++++++--- .../plugin/samples/event/test_event_sample.py | 2 +- .../plugin/samples/event/test_filtered_event_sample.py | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/backend/InvenTree/InvenTree/tests.py b/src/backend/InvenTree/InvenTree/tests.py index 91be4f865a2a..355a8d812202 100644 --- a/src/backend/InvenTree/InvenTree/tests.py +++ b/src/backend/InvenTree/InvenTree/tests.py @@ -1357,14 +1357,17 @@ def test_daily_holdoff(self): # First call should run without issue result = InvenTree.tasks.check_daily_holdoff('dummy_task') self.assertTrue(result) - self.assertIn("Logging task attempt for 'dummy_task'", str(cm.output)) + self.assertIn( + 'Logging task attempt for dummy_task', str(cm.output).replace("\\'", '') + ) with self.assertLogs(logger='inventree', level='INFO') as cm: # An attempt has been logged, but it is too recent result = InvenTree.tasks.check_daily_holdoff('dummy_task') self.assertFalse(result) self.assertIn( - "Last attempt for 'dummy_task' was too recent", str(cm.output) + 'Last attempt for dummy_task was too recent', + str(cm.output).replace("\\'", ''), ) # Mark last attempt a few days ago - should now return True @@ -1385,7 +1388,8 @@ def test_daily_holdoff(self): result = InvenTree.tasks.check_daily_holdoff('dummy_task') self.assertFalse(result) self.assertIn( - "Last attempt for 'dummy_task' was too recent", str(cm.output) + 'Last attempt for dummy_task was too recent', + str(cm.output).replace("\\'", ''), ) # Configure so a task was successful too recently diff --git a/src/backend/InvenTree/plugin/samples/event/test_event_sample.py b/src/backend/InvenTree/plugin/samples/event/test_event_sample.py index 0e5eb9b86d34..adb4414de090 100644 --- a/src/backend/InvenTree/plugin/samples/event/test_event_sample.py +++ b/src/backend/InvenTree/plugin/samples/event/test_event_sample.py @@ -27,7 +27,7 @@ def test_run_event(self): # Enable event testing settings.PLUGIN_TESTING_EVENTS = True # Check that an event is issued - with self.assertLogs(logger=logger, level='DEBUG') as cm: + with self.assertLogs(logger=logger.name, level='DEBUG') as cm: trigger_event('test.event') self.assertIn( 'DEBUG:inventree:Event `test.event` triggered in sample plugin', cm[1] diff --git a/src/backend/InvenTree/plugin/samples/event/test_filtered_event_sample.py b/src/backend/InvenTree/plugin/samples/event/test_filtered_event_sample.py index 1da5a3b499ed..0f75a8f3f0f8 100644 --- a/src/backend/InvenTree/plugin/samples/event/test_filtered_event_sample.py +++ b/src/backend/InvenTree/plugin/samples/event/test_filtered_event_sample.py @@ -25,7 +25,7 @@ def test_run_event(self): # Enable event testing settings.PLUGIN_TESTING_EVENTS = True # Check that an event is issued - with self.assertLogs(logger=logger, level='DEBUG') as cm: + with self.assertLogs(logger=logger.name, level='DEBUG') as cm: trigger_event('test.event') self.assertIn( 'DEBUG:inventree:Event `test.event` triggered in sample plugin', cm[1] @@ -46,7 +46,7 @@ def test_ignore_event(self): # Enable event testing settings.PLUGIN_TESTING_EVENTS = True # Check that an event is issued - with self.assertLogs(logger=logger, level='DEBUG') as cm: + with self.assertLogs(logger=logger.name, level='DEBUG') as cm: trigger_event('test.some.other.event') self.assertNotIn( 'DEBUG:inventree:Event `test.some.other.event` triggered in sample plugin',