@@ -1,11 +1,12 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Python API for language and translation management. """
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.site_configuration.helpers import get_value
|
||||
|
||||
|
||||
@@ -2,16 +2,14 @@
|
||||
Middleware for Language Preferences
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||
from django.utils.translation.trans_real import parse_accept_lang_header
|
||||
|
||||
from openedx.core.djangoapps.lang_pref import COOKIE_DURATION, LANGUAGE_HEADER, LANGUAGE_KEY
|
||||
from openedx.core.djangoapps.user_api.errors import UserAPIInternalError, UserAPIRequestError
|
||||
from openedx.core.djangoapps.user_api.preferences.api import (
|
||||
get_user_preference,
|
||||
set_user_preference
|
||||
)
|
||||
from openedx.core.djangoapps.user_api.preferences.api import get_user_preference, set_user_preference
|
||||
|
||||
|
||||
class LanguagePreferenceMiddleware(object):
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Tests for the language API. """
|
||||
|
||||
from mock import patch
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ddt
|
||||
from django.contrib.auth.models import User
|
||||
from django.test.utils import override_settings
|
||||
from django.utils import translation
|
||||
from django.contrib.auth.models import User
|
||||
import ddt
|
||||
|
||||
from mock import patch
|
||||
from openedx.core.djangoapps.dark_lang.models import DarkLangConfig
|
||||
from openedx.core.djangoapps.lang_pref import api as language_api
|
||||
from openedx.core.djangoapps.site_configuration.tests.test_util import with_site_configuration_context
|
||||
|
||||
@@ -2,24 +2,28 @@
|
||||
Tests for lang_pref middleware.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import itertools
|
||||
import mock
|
||||
|
||||
import ddt
|
||||
import mock
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
from django.test.client import RequestFactory
|
||||
from django.http import HttpResponse
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.http import HttpResponse
|
||||
from django.test.client import RequestFactory
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||
from django.utils.translation.trans_real import parse_accept_lang_header
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
|
||||
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY, COOKIE_DURATION
|
||||
from openedx.core.djangoapps.lang_pref import COOKIE_DURATION, LANGUAGE_KEY
|
||||
from openedx.core.djangoapps.lang_pref.middleware import LanguagePreferenceMiddleware
|
||||
from openedx.core.djangoapps.user_api.preferences.api import set_user_preference, get_user_preference, delete_user_preference
|
||||
from student.tests.factories import UserFactory
|
||||
from student.tests.factories import AnonymousUserFactory
|
||||
from openedx.core.djangoapps.user_api.preferences.api import (
|
||||
delete_user_preference,
|
||||
get_user_preference,
|
||||
set_user_preference
|
||||
)
|
||||
from openedx.core.djangolib.testing.utils import CacheIsolationTestCase
|
||||
from student.tests.factories import AnonymousUserFactory, UserFactory
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
"""
|
||||
Tests: lang pref views
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.urls import reverse
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY, get_language
|
||||
from student.tests.factories import UserFactory
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
from django.utils.translation import get_language
|
||||
|
||||
|
||||
class TestLangPrefView(TestCase):
|
||||
|
||||
@@ -2,13 +2,16 @@
|
||||
Language Preference Views
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
import six
|
||||
|
||||
from django.conf import settings
|
||||
from django.http import HttpResponse
|
||||
from django.utils.translation import LANGUAGE_SESSION_KEY
|
||||
from django.views.decorators.csrf import ensure_csrf_cookie
|
||||
|
||||
from openedx.core.djangoapps.lang_pref import COOKIE_DURATION, LANGUAGE_KEY
|
||||
|
||||
|
||||
@@ -22,7 +25,7 @@ def update_session_language(request):
|
||||
data = json.loads(request.body)
|
||||
language = data.get(LANGUAGE_KEY, settings.LANGUAGE_CODE)
|
||||
if request.session.get(LANGUAGE_SESSION_KEY, None) != language:
|
||||
request.session[LANGUAGE_SESSION_KEY] = unicode(language)
|
||||
request.session[LANGUAGE_SESSION_KEY] = six.text_type(language)
|
||||
response.set_cookie(
|
||||
settings.LANGUAGE_COOKIE,
|
||||
language,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Django Celery tasks for service status app
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import time
|
||||
|
||||
from djcelery import celery
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
"""Test for async task service status"""
|
||||
|
||||
import json
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.urls import reverse
|
||||
from django.test.client import Client
|
||||
import json
|
||||
import unittest
|
||||
|
||||
import six
|
||||
|
||||
from django.test.client import Client
|
||||
from django.urls import reverse
|
||||
|
||||
|
||||
class CeleryConfigTest(unittest.TestCase):
|
||||
"""
|
||||
@@ -44,6 +48,6 @@ class CeleryConfigTest(unittest.TestCase):
|
||||
|
||||
# We don't know the other dict values exactly,
|
||||
# but we can assert that they take the right form
|
||||
self.assertIsInstance(result_dict['task_id'], unicode)
|
||||
self.assertIsInstance(result_dict['task_id'], six.text_type)
|
||||
self.assertIsInstance(result_dict['time'], float)
|
||||
self.assertGreater(result_dict['time'], 0.0)
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
Django URLs for service status app
|
||||
"""
|
||||
|
||||
from django.conf.urls import url
|
||||
from __future__ import absolute_import
|
||||
|
||||
from openedx.core.djangoapps.service_status.views import index, celery_status, celery_ping
|
||||
from django.conf.urls import url
|
||||
from openedx.core.djangoapps.service_status.views import celery_ping, celery_status, index
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^$', index, name='status.service.index'),
|
||||
|
||||
@@ -2,13 +2,14 @@
|
||||
Django Views for service status app
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from celery.exceptions import TimeoutError
|
||||
from django.http import HttpResponse
|
||||
from djcelery import celery
|
||||
|
||||
from openedx.core.djangoapps.service_status.tasks import delayed_ping
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user