test: add tests for ol_openedx_auto_select_language#759
test: add tests for ol_openedx_auto_select_language#759
Conversation
… view Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
Co-authored-by: asadali145 <52656433+asadali145@users.noreply.github.com>
…_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>
arslanashraf7
left a comment
There was a problem hiding this comment.
a few small comments
|
|
||
|
|
||
| @pytest.fixture | ||
| def rf(): |
There was a problem hiding this comment.
Should rename it to request_factory
| @pytest.fixture | ||
| def mock_anonymous_user(mocker): | ||
| """Provide a mock anonymous user.""" | ||
| return mocker.Mock(is_authenticated=False) |
| "zh_HANS", | ||
| {"zh-Hans": "chinese.srt", "en": "english.srt"}, | ||
| "zh-Hans", |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
Maybe?
| 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") |
| def test_defaults_to_english_fallback(mocker, course_setup, transcripts): | ||
| """Test defaults to English for various fallback cases.""" |
There was a problem hiding this comment.
rename ? what defaults to English fallback? dest_language?
| ) | ||
|
|
||
|
|
||
| def test_no_redirect_when_cookie_matches(rf, settings, mock_user, mocker): |
There was a problem hiding this comment.
This and test_no_redirect_when_already_english can be combined into one parametrized test i think.
| 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 | ||
| ) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
This is for CourseLanguageCookieResetMiddleware, the other one is CourseLanguageCookieMiddleware when requests with Authoring MFE hit LMS.
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.