Merge pull request #21030 from edx/INCR-376
INCR-376 python3 compatibility
This commit is contained in:
@@ -2,6 +2,8 @@
|
|||||||
Admin site bindings for ccxcon
|
Admin site bindings for ccxcon
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from .models import CCXCon
|
from .models import CCXCon
|
||||||
|
|||||||
@@ -2,9 +2,12 @@
|
|||||||
Module containing API functions for the CCXCon
|
Module containing API functions for the CCXCon
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import logging
|
from __future__ import absolute_import
|
||||||
import urlparse
|
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import six
|
||||||
|
import six.moves.urllib.parse # pylint: disable=import-error
|
||||||
from django.core.exceptions import ValidationError
|
from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import URLValidator
|
from django.core.validators import URLValidator
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
@@ -90,18 +93,18 @@ def course_info_to_ccxcon(course_key):
|
|||||||
try:
|
try:
|
||||||
course = get_course_by_id(course_key)
|
course = get_course_by_id(course_key)
|
||||||
except Http404:
|
except Http404:
|
||||||
log.error(u'Master Course with key "%s" not found', unicode(course_key))
|
log.error(u'Master Course with key "%s" not found', six.text_type(course_key))
|
||||||
return
|
return
|
||||||
if not course.enable_ccx:
|
if not course.enable_ccx:
|
||||||
log.debug(u'ccx not enabled for course key "%s"', unicode(course_key))
|
log.debug(u'ccx not enabled for course key "%s"', six.text_type(course_key))
|
||||||
return
|
return
|
||||||
if not course.ccx_connector:
|
if not course.ccx_connector:
|
||||||
log.debug(u'ccx connector not defined for course key "%s"', unicode(course_key))
|
log.debug(u'ccx connector not defined for course key "%s"', six.text_type(course_key))
|
||||||
return
|
return
|
||||||
if not is_valid_url(course.ccx_connector):
|
if not is_valid_url(course.ccx_connector):
|
||||||
log.error(
|
log.error(
|
||||||
u'ccx connector URL "%s" for course key "%s" is not a valid URL.',
|
u'ccx connector URL "%s" for course key "%s" is not a valid URL.',
|
||||||
course.ccx_connector, unicode(course_key)
|
course.ccx_connector, six.text_type(course_key)
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
# get the oauth credential for this URL
|
# get the oauth credential for this URL
|
||||||
@@ -114,7 +117,7 @@ def course_info_to_ccxcon(course_key):
|
|||||||
# get an oauth client with a valid token
|
# get an oauth client with a valid token
|
||||||
|
|
||||||
oauth_ccxcon = get_oauth_client(
|
oauth_ccxcon = get_oauth_client(
|
||||||
server_token_url=urlparse.urljoin(course.ccx_connector, CCXCON_TOKEN_URL),
|
server_token_url=six.moves.urllib.parse.urljoin(course.ccx_connector, CCXCON_TOKEN_URL),
|
||||||
client_id=ccxcon.oauth_client_id,
|
client_id=ccxcon.oauth_client_id,
|
||||||
client_secret=ccxcon.oauth_client_secret
|
client_secret=ccxcon.oauth_client_secret
|
||||||
)
|
)
|
||||||
@@ -127,7 +130,7 @@ def course_info_to_ccxcon(course_key):
|
|||||||
course_details = CourseDetails.fetch(course_key)
|
course_details = CourseDetails.fetch(course_key)
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'course_id': unicode(course_key),
|
'course_id': six.text_type(course_key),
|
||||||
'title': course.display_name,
|
'title': course.display_name,
|
||||||
'author_name': None,
|
'author_name': None,
|
||||||
'overview': course_details.overview,
|
'overview': course_details.overview,
|
||||||
@@ -138,7 +141,7 @@ def course_info_to_ccxcon(course_key):
|
|||||||
headers = {'content-type': 'application/json'}
|
headers = {'content-type': 'application/json'}
|
||||||
|
|
||||||
# make the POST request
|
# make the POST request
|
||||||
add_course_url = urlparse.urljoin(course.ccx_connector, CCXCON_COURSEXS_URL)
|
add_course_url = six.moves.urllib.parse.urljoin(course.ccx_connector, CCXCON_COURSEXS_URL)
|
||||||
resp = oauth_ccxcon.post(
|
resp = oauth_ccxcon.post(
|
||||||
url=add_course_url,
|
url=add_course_url,
|
||||||
json=payload,
|
json=payload,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
Configuration for CCX connector
|
Configuration for CCX connector
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from django.apps import AppConfig
|
from django.apps import AppConfig
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,9 @@
|
|||||||
Models for the ccxcon
|
Models for the ccxcon
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import six
|
||||||
from django.db import models
|
from django.db import models
|
||||||
|
|
||||||
|
|
||||||
@@ -29,4 +32,4 @@ class CCXCon(models.Model):
|
|||||||
return self.title
|
return self.title
|
||||||
|
|
||||||
def __unicode__(self):
|
def __unicode__(self):
|
||||||
return unicode(self.__str__())
|
return six.text_type(self.__str__())
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
This file contains celery tasks for ccxcon
|
This file contains celery tasks for ccxcon
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from celery.task import task
|
from celery.task import task
|
||||||
from celery.utils.log import get_task_logger
|
from celery.utils.log import get_task_logger
|
||||||
from opaque_keys.edx.keys import CourseKey
|
from opaque_keys.edx.keys import CourseKey
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
"""
|
"""
|
||||||
Dummy factories for tests
|
Dummy factories for tests
|
||||||
"""
|
"""
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
from factory.django import DjangoModelFactory
|
from factory.django import DjangoModelFactory
|
||||||
|
|
||||||
from openedx.core.djangoapps.ccxcon.models import CCXCon
|
from openedx.core.djangoapps.ccxcon.models import CCXCon
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,24 +2,22 @@
|
|||||||
Unit tests for the API module
|
Unit tests for the API module
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
import pytz
|
import pytz
|
||||||
import urlparse
|
import six.moves.urllib.parse # pylint: disable=import-error
|
||||||
|
|
||||||
from opaque_keys.edx.keys import CourseKey
|
from opaque_keys.edx.keys import CourseKey
|
||||||
from student.tests.factories import AdminFactory
|
from six.moves import range
|
||||||
from xmodule.modulestore.django import modulestore
|
|
||||||
from xmodule.modulestore.tests.django_utils import (
|
|
||||||
SharedModuleStoreTestCase,
|
|
||||||
TEST_DATA_SPLIT_MODULESTORE
|
|
||||||
)
|
|
||||||
from xmodule.modulestore.tests.factories import (
|
|
||||||
CourseFactory,
|
|
||||||
ItemFactory,
|
|
||||||
)
|
|
||||||
|
|
||||||
from openedx.core.djangoapps.ccxcon import api as ccxconapi
|
from openedx.core.djangoapps.ccxcon import api as ccxconapi
|
||||||
|
from student.tests.factories import AdminFactory
|
||||||
|
from xmodule.modulestore.django import modulestore
|
||||||
|
from xmodule.modulestore.tests.django_utils import TEST_DATA_SPLIT_MODULESTORE, SharedModuleStoreTestCase
|
||||||
|
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||||
|
|
||||||
from .factories import CcxConFactory
|
from .factories import CcxConFactory
|
||||||
|
|
||||||
|
|
||||||
@@ -58,18 +56,18 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
|||||||
)
|
)
|
||||||
|
|
||||||
cls.chapters = [
|
cls.chapters = [
|
||||||
ItemFactory.create(start=start, parent=course) for _ in xrange(2)
|
ItemFactory.create(start=start, parent=course) for _ in range(2)
|
||||||
]
|
]
|
||||||
cls.sequentials = flatten([
|
cls.sequentials = flatten([
|
||||||
[
|
[
|
||||||
ItemFactory.create(parent=chapter) for _ in xrange(2)
|
ItemFactory.create(parent=chapter) for _ in range(2)
|
||||||
] for chapter in cls.chapters
|
] for chapter in cls.chapters
|
||||||
])
|
])
|
||||||
cls.verticals = flatten([
|
cls.verticals = flatten([
|
||||||
[
|
[
|
||||||
ItemFactory.create(
|
ItemFactory.create(
|
||||||
start=start, due=due, parent=sequential, graded=True, format='Homework', category=u'vertical'
|
start=start, due=due, parent=sequential, graded=True, format='Homework', category=u'vertical'
|
||||||
) for _ in xrange(2)
|
) for _ in range(2)
|
||||||
] for sequential in cls.sequentials
|
] for sequential in cls.sequentials
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -78,7 +76,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
|||||||
with cls.store.bulk_operations(course.id, emit_signals=False):
|
with cls.store.bulk_operations(course.id, emit_signals=False):
|
||||||
blocks = flatten([ # pylint: disable=unused-variable
|
blocks = flatten([ # pylint: disable=unused-variable
|
||||||
[
|
[
|
||||||
ItemFactory.create(parent=vertical) for _ in xrange(2)
|
ItemFactory.create(parent=vertical) for _ in range(2)
|
||||||
] for vertical in cls.verticals
|
] for vertical in cls.verticals
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -167,7 +165,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
|||||||
self.assertEqual(k_args, tuple())
|
self.assertEqual(k_args, tuple())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
k_kwargs.get('url'),
|
k_kwargs.get('url'),
|
||||||
urlparse.urljoin(self.course.ccx_connector, ccxconapi.CCXCON_COURSEXS_URL)
|
six.moves.urllib.parse.urljoin(self.course.ccx_connector, ccxconapi.CCXCON_COURSEXS_URL)
|
||||||
)
|
)
|
||||||
|
|
||||||
# second call with different status code
|
# second call with different status code
|
||||||
@@ -182,7 +180,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
|||||||
self.assertEqual(k_args, tuple())
|
self.assertEqual(k_args, tuple())
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
k_kwargs.get('url'),
|
k_kwargs.get('url'),
|
||||||
urlparse.urljoin(self.course.ccx_connector, ccxconapi.CCXCON_COURSEXS_URL)
|
six.moves.urllib.parse.urljoin(self.course.ccx_connector, ccxconapi.CCXCON_COURSEXS_URL)
|
||||||
)
|
)
|
||||||
|
|
||||||
@mock.patch('requests_oauthlib.oauth2_session.OAuth2Session.fetch_token', fetch_token_mock)
|
@mock.patch('requests_oauthlib.oauth2_session.OAuth2Session.fetch_token', fetch_token_mock)
|
||||||
|
|||||||
@@ -2,11 +2,12 @@
|
|||||||
Tests for the CCXCon celery tasks
|
Tests for the CCXCon celery tasks
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
|
|
||||||
from opaque_keys.edx.keys import CourseKey
|
from opaque_keys.edx.keys import CourseKey
|
||||||
|
|
||||||
from openedx.core.djangoapps.ccxcon import api, tasks
|
from openedx.core.djangoapps.ccxcon import api, tasks
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user