-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2077 from openedx/ammar/set-default-lang-for-ente…
…rprise-learners fix: set default language for all learners linked with an enterprise customer
- Loading branch information
Showing
6 changed files
with
51 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
Your project description goes here. | ||
""" | ||
|
||
__version__ = "4.15.9" | ||
__version__ = "4.15.10" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -332,9 +332,9 @@ def test_catalog_contains_course_with_enterprise_customer_catalog(self, api_clie | |
wraps=update_enterprise_learners_user_preference | ||
) | ||
@mock.patch('enterprise.utils.UserPreference', return_value=mock.MagicMock()) | ||
def test_unset_language_of_all_enterprise_learners(self, user_preference_mock, mock_task): | ||
def test_set_language_of_all_enterprise_learners(self, user_preference_mock, mock_task): | ||
""" | ||
Validate that unset_language_of_all_enterprise_learners is called whenever default_language changes. | ||
Validate that set_language_of_all_enterprise_learners is called whenever default_language changes. | ||
""" | ||
user = factories.UserFactory(email='[email protected]') | ||
enterprise_customer = factories.EnterpriseCustomerFactory() | ||
|
@@ -345,22 +345,24 @@ def test_unset_language_of_all_enterprise_learners(self, user_preference_mock, m | |
enterprise_customer.default_language = 'es-419' | ||
enterprise_customer.save() | ||
mock_task.assert_called_once() | ||
user_preference_mock.objects.filter.return_value.update.assert_called_with(value='es-419') | ||
user_preference_mock.objects.filter.assert_called_once() | ||
|
||
# Make sure `unset_language_of_all_enterprise_learners` is called each time `default_language` changes. | ||
# Make sure `set_language_of_all_enterprise_learners` is called each time `default_language` changes. | ||
enterprise_customer.default_language = 'es-417' | ||
enterprise_customer.save() | ||
assert mock_task.call_count == 2 | ||
user_preference_mock.objects.filter.return_value.update.assert_called_with(value='es-417') | ||
assert user_preference_mock.objects.filter.call_count == 2 | ||
|
||
# make sure `unset_language_of_all_enterprise_learners` is not called if `default_language` is | ||
# make sure `set_language_of_all_enterprise_learners` is not called if `default_language` is | ||
# not changed. | ||
enterprise_customer.default_language = 'es-417' | ||
enterprise_customer.save() | ||
assert mock_task.call_count == 2 | ||
assert user_preference_mock.objects.filter.call_count == 2 | ||
|
||
# Make sure `unset_language_of_all_enterprise_learners` is not called if `default_language` is | ||
# Make sure `set_language_of_all_enterprise_learners` is not called if `default_language` is | ||
# set to `None`. | ||
enterprise_customer.default_language = None | ||
enterprise_customer.save() | ||
|
@@ -1006,15 +1008,20 @@ def test_soft_delete(self, method_name): | |
) | ||
|
||
@mock.patch('enterprise.utils.UserPreference', return_value=mock.MagicMock()) | ||
def test_unset_enterprise_learner_language(self, user_preference_mock): | ||
def test_set_enterprise_learner_language(self, user_preference_mock): | ||
""" | ||
Validate that unset_enterprise_learner_language is called whenever a nwe learner is linked to an enterprise | ||
Validate that set_enterprise_learner_language is called whenever a nwe learner is linked to an enterprise | ||
customer with Non-Null default language. | ||
""" | ||
enterprise_customer_user = factories.EnterpriseCustomerUserFactory() | ||
user_preference_mock.objects.update_or_create.assert_called_once() | ||
user_preference_mock.objects.update_or_create.assert_called_with( | ||
key='pref-lang', | ||
user_id=enterprise_customer_user.user_id, | ||
defaults={'value': 'en'} | ||
) | ||
|
||
# Make sure `unset_enterprise_learner_language` is not called if the enterprise customer does not have a | ||
# Make sure `set_enterprise_learner_language` is not called if the enterprise customer does not have a | ||
# default_language. | ||
enterprise_customer_user.enterprise_customer.default_language = None | ||
enterprise_customer_user.enterprise_customer.save() | ||
|