Merge pull request #21137 from edx/INCR-343
INCR-343 Python 3 compatibility
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
""" Course run serializers. """
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
import time # pylint: disable=unused-import
|
||||
|
||||
import six
|
||||
from django.contrib.auth import get_user_model
|
||||
from django.db import transaction
|
||||
@@ -82,7 +85,7 @@ class CourseRunTeamSerializerMixin(serializers.Serializer):
|
||||
|
||||
def image_is_jpeg_or_png(value):
|
||||
content_type = value.content_type
|
||||
if content_type not in IMAGE_TYPES.keys():
|
||||
if content_type not in list(IMAGE_TYPES.keys()):
|
||||
raise serializers.ValidationError(
|
||||
u'Only JPEG and PNG image types are supported. {} is not valid'.format(content_type))
|
||||
|
||||
|
||||
@@ -1,16 +1,21 @@
|
||||
"""Tests for course run serializers"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
import ddt
|
||||
import pytz
|
||||
from django.test import RequestFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from openedx.core.lib.courses import course_image_url
|
||||
from student.roles import CourseInstructorRole, CourseStaffRole
|
||||
from student.tests.factories import UserFactory
|
||||
from ..utils import serialize_datetime
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from ...serializers.course_runs import CourseRunSerializer
|
||||
from ..utils import serialize_datetime
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
"""Tests for Course run views"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
|
||||
import ddt
|
||||
import pytz
|
||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||
from django.urls import reverse
|
||||
from django.test import RequestFactory
|
||||
from django.urls import reverse
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from openedx.core.lib.courses import course_image_url
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from openedx.core.lib.courses import course_image_url
|
||||
from student.models import CourseAccessRole
|
||||
from student.tests.factories import TEST_PASSWORD, AdminFactory, UserFactory
|
||||
from xmodule.contentstore.content import StaticContent
|
||||
from xmodule.contentstore.django import contentstore
|
||||
from xmodule.exceptions import NotFoundError
|
||||
@@ -15,10 +22,8 @@ from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ToyCourseFactory
|
||||
|
||||
from student.models import CourseAccessRole
|
||||
from student.tests.factories import AdminFactory, TEST_PASSWORD, UserFactory
|
||||
from ..utils import serialize_datetime
|
||||
from ...serializers.course_runs import CourseRunSerializer
|
||||
from ..utils import serialize_datetime
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
@@ -1,21 +1,23 @@
|
||||
"""
|
||||
Tests for the maintenance app views.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
|
||||
import ddt
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.urls import reverse
|
||||
|
||||
from contentstore.management.commands.utils import get_course_versions
|
||||
from openedx.features.announcements.models import Announcement
|
||||
from student.tests.factories import AdminFactory, UserFactory
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory, ItemFactory
|
||||
|
||||
from openedx.features.announcements.models import Announcement
|
||||
|
||||
from .views import COURSE_KEY_ERROR_MESSAGES, MAINTENANCE_VIEWS
|
||||
|
||||
# This list contains URLs of all maintenance app views.
|
||||
@@ -174,7 +176,7 @@ class TestForcePublish(MaintenanceViewTestCase):
|
||||
# validate non split error message
|
||||
course = CourseFactory.create(default_store=ModuleStoreEnum.Type.mongo)
|
||||
self.verify_error_message(
|
||||
data={'course-id': unicode(course.id)},
|
||||
data={'course-id': six.text_type(course.id)},
|
||||
error_message='Force publishing course is not supported with old mongo courses.'
|
||||
)
|
||||
|
||||
@@ -186,7 +188,7 @@ class TestForcePublish(MaintenanceViewTestCase):
|
||||
# validate non split error message
|
||||
course = CourseFactory.create(org='e', number='d', run='X', default_store=ModuleStoreEnum.Type.mongo)
|
||||
self.verify_error_message(
|
||||
data={'course-id': unicode(course.id)},
|
||||
data={'course-id': six.text_type(course.id)},
|
||||
error_message='Force publishing course is not supported with old mongo courses.'
|
||||
)
|
||||
# Now search for the course key in split version.
|
||||
@@ -207,7 +209,7 @@ class TestForcePublish(MaintenanceViewTestCase):
|
||||
|
||||
# now course is published, we should get `already published course` error.
|
||||
self.verify_error_message(
|
||||
data={'course-id': unicode(course.id)},
|
||||
data={'course-id': six.text_type(course.id)},
|
||||
error_message='Course is already in published state.'
|
||||
)
|
||||
|
||||
@@ -219,7 +221,7 @@ class TestForcePublish(MaintenanceViewTestCase):
|
||||
course (object): a course object.
|
||||
"""
|
||||
# get draft and publish branch versions
|
||||
versions = get_course_versions(unicode(course.id))
|
||||
versions = get_course_versions(six.text_type(course.id))
|
||||
|
||||
# verify that draft and publish point to different versions
|
||||
self.assertNotEqual(versions['draft-branch'], versions['published-branch'])
|
||||
@@ -239,7 +241,7 @@ class TestForcePublish(MaintenanceViewTestCase):
|
||||
|
||||
# force publish course view
|
||||
data = {
|
||||
'course-id': unicode(course.id)
|
||||
'course-id': six.text_type(course.id)
|
||||
}
|
||||
response = self.client.post(self.view_url, data=data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
|
||||
response_data = json.loads(response.content)
|
||||
|
||||
@@ -1,31 +1,33 @@
|
||||
"""
|
||||
Views for the maintenance app.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import logging
|
||||
|
||||
import six
|
||||
from django.core.urlresolvers import reverse, reverse_lazy
|
||||
from django.core.validators import ValidationError
|
||||
from django.db import transaction
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.utils.translation import ugettext as _
|
||||
from django.views.generic import View
|
||||
from django.views.generic.edit import CreateView, DeleteView, UpdateView
|
||||
from django.views.generic.list import ListView
|
||||
from django.views.generic.edit import CreateView, UpdateView, DeleteView
|
||||
from opaque_keys import InvalidKeyError
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
from six import text_type
|
||||
|
||||
from contentstore.management.commands.utils import get_course_versions
|
||||
from edxmako.shortcuts import render_to_response
|
||||
from openedx.features.announcements.forms import AnnouncementForm
|
||||
from openedx.features.announcements.models import Announcement
|
||||
from util.json_request import JsonResponse
|
||||
from util.views import require_global_staff
|
||||
from xmodule.modulestore import ModuleStoreEnum
|
||||
from xmodule.modulestore.django import modulestore
|
||||
from xmodule.modulestore.exceptions import ItemNotFoundError
|
||||
|
||||
from openedx.features.announcements.models import Announcement
|
||||
from openedx.features.announcements.forms import AnnouncementForm
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
# This dict maintains all the views that will be used Maintenance app.
|
||||
@@ -155,8 +157,8 @@ class ForcePublishCourseView(MaintenanceBaseView):
|
||||
Returns a dict containing unicoded values of draft and published draft versions.
|
||||
"""
|
||||
return {
|
||||
'draft-branch': unicode(versions['draft-branch']),
|
||||
'published-branch': unicode(versions['published-branch'])
|
||||
'draft-branch': six.text_type(versions['draft-branch']),
|
||||
'published-branch': six.text_type(versions['published-branch'])
|
||||
}
|
||||
|
||||
@transaction.atomic
|
||||
|
||||
Reference in New Issue
Block a user