Skip to content

Commit

Permalink
chore: Fixed patching on the CourseChatView unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rijuma committed Nov 4, 2024
1 parent 6106dc8 commit 8bc73aa
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,15 @@ def test_invalid_messages(self, mock_role, mock_waffle, mock_render):
)
self.assertEqual(response.status_code, 400)

@ddt.data(True, False) # TODO: Fix this - See below.
@ddt.data(False, True)
@patch('learning_assistant.views.render_prompt_template')
@patch('learning_assistant.views.get_chat_response')
@patch('learning_assistant.views.learning_assistant_enabled')
@patch('learning_assistant.views.get_user_role')
@patch('learning_assistant.views.CourseEnrollment.get_enrollment')
@patch('learning_assistant.views.CourseMode')
@patch('learning_assistant.api.save_chat_message')
@patch('learning_assistant.toggles.chat_history_enabled')
@patch('learning_assistant.views.save_chat_message')
@patch('learning_assistant.views.chat_history_enabled')
@override_settings(LEARNING_ASSISTANT_PROMPT_TEMPLATE='This is the default template')
def test_chat_response_default(
self,
Expand All @@ -183,14 +183,6 @@ def test_chat_response_default(
mock_render.return_value = 'Rendered template mock'
test_unit_id = 'test-unit-id'

# TODO: Fix this...
# For some reason this assignment only works the first iteration. The 2nd time onwards the return value is
# always falsy. Swap the order of the @ddt.data() above by: @ddt.data(False, True) to see it fail.
# I'm leaving it like this because we are testing the False return in the second iteration, but it's important
# to consider whenever this test needs to be updated.
# It even happens if we split the test cases into two different methods (instead of @ddt.data()), so there's
# probably some scoping issues in how the test is set up.
# Note: There's a similar test for LearningAssistantEnabledView in this file that works just fine.
mock_chat_history_enabled.return_value = enabled_flag

test_data = [
Expand Down

0 comments on commit 8bc73aa

Please sign in to comment.