From 33227b8a723e3af83c23eebc73cd12829f97e58e Mon Sep 17 00:00:00 2001 From: Ayub khan Date: Wed, 10 Jul 2019 15:28:00 +0500 Subject: [PATCH] INCR-384 python 3 compatibility --- openedx/features/discounts/applicability.py | 2 ++ openedx/features/discounts/apps.py | 2 ++ .../discounts/tests/test_applicability.py | 13 ++++++++----- openedx/features/discounts/tests/test_views.py | 17 +++++++++++------ openedx/features/discounts/urls.py | 2 ++ openedx/features/discounts/views.py | 11 ++++++----- 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/openedx/features/discounts/applicability.py b/openedx/features/discounts/applicability.py index d72e7ec158..f64e3a0a35 100644 --- a/openedx/features/discounts/applicability.py +++ b/openedx/features/discounts/applicability.py @@ -8,6 +8,8 @@ Keep in mind that the code in this file only applies to discounts controlled in not other discounts like coupons or enterprise/program offers configured in ecommerce. """ +from __future__ import absolute_import + from datetime import datetime import crum diff --git a/openedx/features/discounts/apps.py b/openedx/features/discounts/apps.py index f9380cee0b..d5acbde250 100644 --- a/openedx/features/discounts/apps.py +++ b/openedx/features/discounts/apps.py @@ -4,6 +4,8 @@ Discounts application configuration """ # -*- coding: utf-8 -*- +from __future__ import absolute_import + from django.apps import AppConfig diff --git a/openedx/features/discounts/tests/test_applicability.py b/openedx/features/discounts/tests/test_applicability.py index faa0cadb20..fda111cb4b 100644 --- a/openedx/features/discounts/tests/test_applicability.py +++ b/openedx/features/discounts/tests/test_applicability.py @@ -1,11 +1,14 @@ """Tests of openedx.features.discounts.applicability""" # -*- coding: utf-8 -*- -from datetime import timedelta, datetime +from __future__ import absolute_import + +from datetime import datetime, timedelta + import ddt -from django.utils.timezone import now -from mock import patch, Mock import pytz +from django.utils.timezone import now +from mock import Mock, patch from course_modes.models import CourseMode from course_modes.tests.factories import CourseModeFactory @@ -13,11 +16,11 @@ from entitlements.tests.factories import CourseEntitlementFactory from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.waffle_utils.testutils import override_waffle_flag from openedx.features.discounts.models import DiscountRestrictionConfig -from student.tests.factories import UserFactory, CourseEnrollmentFactory +from student.tests.factories import CourseEnrollmentFactory, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase from xmodule.modulestore.tests.factories import CourseFactory -from ..applicability import can_receive_discount, DISCOUNT_APPLICABILITY_FLAG, _is_in_holdback +from ..applicability import DISCOUNT_APPLICABILITY_FLAG, _is_in_holdback, can_receive_discount @ddt.ddt diff --git a/openedx/features/discounts/tests/test_views.py b/openedx/features/discounts/tests/test_views.py index 402026f4f3..19a37c7938 100644 --- a/openedx/features/discounts/tests/test_views.py +++ b/openedx/features/discounts/tests/test_views.py @@ -1,13 +1,15 @@ """Tests of openedx.features.discounts.views""" # -*- coding: utf-8 -*- -import jwt +from __future__ import absolute_import +import jwt +import six from django.test.client import Client from django.urls import reverse -from xmodule.modulestore.tests.factories import CourseFactory +from student.tests.factories import TEST_PASSWORD, UserFactory from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase -from student.tests.factories import UserFactory, TEST_PASSWORD +from xmodule.modulestore.tests.factories import CourseFactory class TestCourseUserDiscount(ModuleStoreTestCase): @@ -21,13 +23,16 @@ class TestCourseUserDiscount(ModuleStoreTestCase): self.user = UserFactory.create() self.course = CourseFactory.create(run='test', display_name='test') self.client = Client() - self.url = reverse('api_discounts:course_user_discount', kwargs={'course_key_string': unicode(self.course.id)}) + self.url = reverse( + 'api_discounts:course_user_discount', + kwargs={'course_key_string': six.text_type(self.course.id)} + ) def test_url(self): """ Test that the url hasn't changed """ - assert self.url == ('/api/discounts/course/' + unicode(self.course.id)) + assert self.url == ('/api/discounts/course/' + six.text_type(self.course.id)) def test_course_user_discount(self): """ @@ -44,7 +49,7 @@ class TestCourseUserDiscount(ModuleStoreTestCase): # make sure that the response matches the expected response response_payload = jwt.decode(response.data['jwt'], verify=False) - assert all(item in response_payload.items() for item in expected_payload.items()) + assert all(item in list(response_payload.items()) for item in expected_payload.items()) def test_course_user_discount_no_user(self): """ diff --git a/openedx/features/discounts/urls.py b/openedx/features/discounts/urls.py index 239702ae4a..079454070f 100644 --- a/openedx/features/discounts/urls.py +++ b/openedx/features/discounts/urls.py @@ -1,6 +1,8 @@ """ Discount API URLs """ +from __future__ import absolute_import + from django.conf import settings from django.conf.urls import url diff --git a/openedx/features/discounts/views.py b/openedx/features/discounts/views.py index 5fb70e09bd..8626207817 100644 --- a/openedx/features/discounts/views.py +++ b/openedx/features/discounts/views.py @@ -4,10 +4,15 @@ The Discount API Views should return information about discounts that apply to t """ # -*- coding: utf-8 -*- +from __future__ import absolute_import + +from django.utils.decorators import method_decorator from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication from edx_rest_framework_extensions.auth.session.authentication import SessionAuthenticationAllowInactiveUser - from opaque_keys.edx.keys import CourseKey +from rest_framework.response import Response +from rest_framework.views import APIView + from openedx.core.djangoapps.content.course_overviews.models import CourseOverview from openedx.core.djangoapps.cors_csrf.decorators import ensure_csrf_cookie_cross_domain from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user @@ -15,10 +20,6 @@ from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiv from openedx.core.lib.api.permissions import ApiKeyHeaderPermissionIsAuthenticated from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin -from rest_framework.response import Response -from rest_framework.views import APIView -from django.utils.decorators import method_decorator - from .applicability import can_receive_discount, discount_percentage