Merge pull request #20322 from eduNEXT/coa/incr-191

INCR-191
This commit is contained in:
Michael Youngstrom
2019-04-26 11:29:10 -04:00
committed by GitHub
10 changed files with 49 additions and 32 deletions

View File

@@ -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

View File

@@ -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):

View File

@@ -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

View File

@@ -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

View File

@@ -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):

View File

@@ -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,

View File

@@ -2,6 +2,8 @@
Django Celery tasks for service status app
"""
from __future__ import absolute_import
import time
from djcelery import celery

View File

@@ -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)

View File

@@ -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'),

View File

@@ -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