Skip to content

test: add tests for ol_openedx_auto_select_language#759

Open
Copilot wants to merge 10 commits intomainfrom
copilot/write-tests-for-plugin-middleware
Open

test: add tests for ol_openedx_auto_select_language#759
Copilot wants to merge 10 commits intomainfrom
copilot/write-tests-for-plugin-middleware

Conversation

Copy link
Contributor

Copilot AI commented Mar 12, 2026

Ticket

None

Description

Add tests for ol_openedx_auto_select_language


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 12, 2026 09:28
… view

Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests for ol_openedx_auto_language_select plugin Add tests for ol_openedx_auto_select_language plugin Mar 12, 2026
Copilot AI and others added 2 commits March 12, 2026 11:12
…_language tests

Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Copilot AI changed the title Add tests for ol_openedx_auto_select_language plugin Reduce test duplication via parametrization and shared fixtures Mar 12, 2026
@asadali145 asadali145 changed the title Reduce test duplication via parametrization and shared fixtures test: add tests for ol_openedx_auto_select_language Mar 12, 2026
@asadali145 asadali145 marked this pull request as ready for review March 13, 2026 11:48
@arslanashraf7 arslanashraf7 self-assigned this Mar 16, 2026
Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few small comments



@pytest.fixture
def rf():
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should rename it to request_factory

Comment on lines +19 to +22
@pytest.fixture
def mock_anonymous_user(mocker):
"""Provide a mock anonymous user."""
return mocker.Mock(is_authenticated=False)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused

Comment on lines +31 to +33
"zh_HANS",
{"zh-Hans": "chinese.srt", "en": "english.srt"},
"zh-Hans",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should add es-419 as well, which will cover the case for code-number based language codes.

)

if expected_lang is not None:
video_child_key = next(c for c in block.children if c.block_type == "video")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe?

Suggested change
video_child_key = next(c for c in block.children if c.block_type == "video")
video_child = next(child for child in block.children if child.block_type == "video")

Comment on lines +161 to +162
def test_defaults_to_english_fallback(mocker, course_setup, transcripts):
"""Test defaults to English for various fallback cases."""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rename ? what defaults to English fallback? dest_language?

)


def test_no_redirect_when_cookie_matches(rf, settings, mock_user, mocker):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This and test_no_redirect_when_already_english can be combined into one parametrized test i think.

Comment on lines +325 to +343
def test_resets_non_english_cookie_to_english(rf, settings, mock_user, mocker):
"""Test non-English cookie reset to English."""
settings.ENABLE_AUTO_LANGUAGE_SELECTION = True

mock_helpers = mocker.patch(f"{MODULE}.lang_pref_helpers")
mocker.patch(f"{MODULE}.set_user_preference")
mock_helpers.get_language_cookie.return_value = "fr"

middleware = CourseLanguageCookieResetMiddleware(mocker.Mock())
request = rf.get("/some-cms-page/")
request.user = mock_user
response = HttpResponse()

result = middleware.process_response(request, response)

assert result is response
mock_helpers.set_language_cookie.assert_called_once_with(
request, response, ENGLISH_LANGUAGE_CODE
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this test for? Is this in any way intended except for the authoring MFE's case? If so, we already have a test for that above.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for CourseLanguageCookieResetMiddleware, the other one is CourseLanguageCookieMiddleware when requests with Authoring MFE hit LMS.

Copy link
Contributor

@arslanashraf7 arslanashraf7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants