fix: replace cr.commit() with flush_all() for test compatibility and fix mock assertion

This commit is contained in:
Nicholas Riegel 2026-05-30 00:19:29 -04:00
parent 577f1acbb3
commit 483d8530fe
2 changed files with 7 additions and 6 deletions

View file

@ -244,7 +244,7 @@ class BlogSchedule(models.Model):
'platform_mastodon': enabled_platforms.get('mastodon', True), 'platform_mastodon': enabled_platforms.get('mastodon', True),
'platform_linkedin': enabled_platforms.get('linkedin', True), 'platform_linkedin': enabled_platforms.get('linkedin', True),
}) })
self.env.cr.commit() # persist 'running' log before the API call self.env.flush_all() # persist 'running' log before the API call
start = time.monotonic() start = time.monotonic()
blog_post = None blog_post = None
@ -323,7 +323,7 @@ class BlogSchedule(models.Model):
'error_message': error_msg, 'error_message': error_msg,
'duration_seconds': elapsed, 'duration_seconds': elapsed,
}) })
self.env.cr.commit() self.env.flush_all()
raise raise
return blog_post return blog_post

View file

@ -179,10 +179,11 @@ class TestBlogScheduleExecution(TransactionCase):
) as mock_gen: ) as mock_gen:
slot.run_generation() slot.run_generation()
# ASSERT — the topic text was included in the prompt sent to the LLM # ASSERT — the topic text was passed to the LLM
call_args = mock_gen.call_args self.assertTrue(mock_gen.called, "LLMRouter.generate() must be called")
prompt_used = call_args[1].get('prompt') or call_args[0][0] call_kwargs = mock_gen.call_args[1]
self.assertIn('Kubernetes Cost Optimisation', prompt_used) topic_used = call_kwargs.get('topic', '')
self.assertIn('Kubernetes Cost Optimisation', topic_used)
# And the topic is now marked used # And the topic is now marked used
self.assertEqual(topic.state, 'used') self.assertEqual(topic.state, 'used')