INCR-376 python3 compatibility
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
Admin site bindings for ccxcon
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.contrib import admin
|
||||
|
||||
from .models import CCXCon
|
||||
|
||||
@@ -2,9 +2,12 @@
|
||||
Module containing API functions for the CCXCon
|
||||
"""
|
||||
|
||||
import logging
|
||||
import urlparse
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
import six.moves.urllib.parse # pylint: disable=import-error
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.validators import URLValidator
|
||||
from django.http import Http404
|
||||
@@ -90,18 +93,18 @@ def course_info_to_ccxcon(course_key):
|
||||
try:
|
||||
course = get_course_by_id(course_key)
|
||||
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
|
||||
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
|
||||
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
|
||||
if not is_valid_url(course.ccx_connector):
|
||||
log.error(
|
||||
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
|
||||
# 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
|
||||
|
||||
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_secret=ccxcon.oauth_client_secret
|
||||
)
|
||||
@@ -127,7 +130,7 @@ def course_info_to_ccxcon(course_key):
|
||||
course_details = CourseDetails.fetch(course_key)
|
||||
|
||||
payload = {
|
||||
'course_id': unicode(course_key),
|
||||
'course_id': six.text_type(course_key),
|
||||
'title': course.display_name,
|
||||
'author_name': None,
|
||||
'overview': course_details.overview,
|
||||
@@ -138,7 +141,7 @@ def course_info_to_ccxcon(course_key):
|
||||
headers = {'content-type': 'application/json'}
|
||||
|
||||
# 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(
|
||||
url=add_course_url,
|
||||
json=payload,
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Configuration for CCX connector
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,9 @@
|
||||
Models for the ccxcon
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import six
|
||||
from django.db import models
|
||||
|
||||
|
||||
@@ -29,4 +32,4 @@ class CCXCon(models.Model):
|
||||
return self.title
|
||||
|
||||
def __unicode__(self):
|
||||
return unicode(self.__str__())
|
||||
return six.text_type(self.__str__())
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
This file contains celery tasks for ccxcon
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from celery.task import task
|
||||
from celery.utils.log import get_task_logger
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
"""
|
||||
Dummy factories for tests
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from factory.django import DjangoModelFactory
|
||||
|
||||
from openedx.core.djangoapps.ccxcon.models import CCXCon
|
||||
|
||||
|
||||
|
||||
@@ -2,24 +2,22 @@
|
||||
Unit tests for the API module
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
import mock
|
||||
import pytz
|
||||
import urlparse
|
||||
|
||||
import six.moves.urllib.parse # pylint: disable=import-error
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from student.tests.factories import AdminFactory
|
||||
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 six.moves import range
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -58,18 +56,18 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
||||
)
|
||||
|
||||
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([
|
||||
[
|
||||
ItemFactory.create(parent=chapter) for _ in xrange(2)
|
||||
ItemFactory.create(parent=chapter) for _ in range(2)
|
||||
] for chapter in cls.chapters
|
||||
])
|
||||
cls.verticals = flatten([
|
||||
[
|
||||
ItemFactory.create(
|
||||
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
|
||||
])
|
||||
|
||||
@@ -78,7 +76,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
||||
with cls.store.bulk_operations(course.id, emit_signals=False):
|
||||
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
|
||||
])
|
||||
|
||||
@@ -167,7 +165,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
||||
self.assertEqual(k_args, tuple())
|
||||
self.assertEqual(
|
||||
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
|
||||
@@ -182,7 +180,7 @@ class APIsTestCase(SharedModuleStoreTestCase):
|
||||
self.assertEqual(k_args, tuple())
|
||||
self.assertEqual(
|
||||
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)
|
||||
|
||||
@@ -2,11 +2,12 @@
|
||||
Tests for the CCXCon celery tasks
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import mock
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
from openedx.core.djangoapps.ccxcon import api, tasks
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user