Ejemplo n.º 1
0
    def test_language_in_session(self):
        # language set in both the user preferences and session,
        # session should get precedence
        self.request.session['django_language'] = 'en'
        UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
        self.middleware.process_request(self.request)

        self.assertEquals(self.request.session['django_language'], 'en')
Ejemplo n.º 2
0
    def test_language_in_session(self):
        # language set in both the user preferences and session,
        # session should get precedence
        self.request.session['django_language'] = 'en'
        UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
        self.middleware.process_request(self.request)

        self.assertEquals(self.request.session['django_language'], 'en')
Ejemplo n.º 3
0
    def test_user_with_locale_claim(self):
        language = "en"
        UserPreference.set_preference(self.user, LANGUAGE_KEY, language)
        scopes, claims = self.get_id_token_values("openid profile")

        self.assertIn("profile", scopes)

        locale = claims["locale"]
        self.assertEqual(language, locale)
Ejemplo n.º 4
0
    def test_user_with_locale_claim(self):
        language = 'en'
        UserPreference.set_preference(self.user, LANGUAGE_KEY, language)
        scopes, claims = self.get_id_token_values('openid profile')

        self.assertIn('profile', scopes)

        locale = claims['locale']
        self.assertEqual(language, locale)
Ejemplo n.º 5
0
    def test_user_with_locale_claim(self):
        language = 'en'
        UserPreference.set_preference(self.user, LANGUAGE_KEY, language)
        scopes, claims = self.get_id_token_values('openid profile')

        self.assertIn('profile', scopes)

        locale = claims['locale']
        self.assertEqual(language, locale)
    def setUp(self):
        # Platform language is English, instructor's language is Chinese,
        # student's language is French, so the emails should all be sent in
        # French.
        self.course = CourseFactory.create()
        self.instructor = InstructorFactory(course_key=self.course.id)
        UserPreference.set_preference(self.instructor, LANGUAGE_KEY, 'zh-cn')
        self.client.login(username=self.instructor.username, password='******')

        self.student = UserFactory.create()
        UserPreference.set_preference(self.student, LANGUAGE_KEY, 'fr')
Ejemplo n.º 7
0
    def setUp(self):
        # Platform language is English, instructor's language is Chinese,
        # student's language is French, so the emails should all be sent in
        # French.
        self.course = CourseFactory.create()
        self.instructor = InstructorFactory(course_key=self.course.id)
        UserPreference.set_preference(self.instructor, LANGUAGE_KEY, 'zh-cn')
        self.client.login(username=self.instructor.username, password='******')

        self.student = UserFactory.create()
        UserPreference.set_preference(self.student, LANGUAGE_KEY, 'fr')
Ejemplo n.º 8
0
def set_language(request):
    """
    This view is called when the user would like to set a language preference
    """
    user = request.user
    lang_pref = request.POST.get('language', None)

    if lang_pref:
        UserPreference.set_preference(user, LANGUAGE_KEY, lang_pref)
        return HttpResponse('{"success": true}')

    return HttpResponseBadRequest('no language provided')
Ejemplo n.º 9
0
    def test_get_private_profile(self, api_client, requesting_username):
        """
        Test that private profile information is only available to the test user themselves.
        """
        client = self.login_client(api_client, requesting_username)

        # Verify that a user with a private profile only returns the public fields
        UserPreference.set_preference(self.user, PROFILE_VISIBILITY_PREF_KEY,
                                      PRIVATE_VISIBILITY)
        self.create_mock_profile(self.user)
        response = self.send_get(client)
        self._verify_private_profile_response(response)

        # Verify that only the public fields are returned if 'include_all' parameter is specified as false
        response = self.send_get(client, query_parameters='include_all=false')
        self._verify_private_profile_response(response)

        # Verify that all fields are returned for the user themselves if
        # the 'include_all' parameter is specified as true.
        response = self.send_get(client, query_parameters='include_all=true')
        if requesting_username == "user":
            self._verify_full_profile_response(response)
        else:
            self._verify_private_profile_response(response)
Ejemplo n.º 10
0
 def test_language_in_user_prefs(self):
     # language set in the user preferences and not the session
     UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
     self.middleware.process_request(self.request)
     self.assertEquals(self.request.session['django_language'], 'eo')
Ejemplo n.º 11
0
 def test_language_in_user_prefs(self):
     # language set in the user preferences and not the session
     UserPreference.set_preference(self.user, LANGUAGE_KEY, 'eo')
     self.middleware.process_request(self.request)
     self.assertEquals(self.request.session['django_language'], 'eo')