BOM-2442
pyupgrade in course-search and discount.
This commit is contained in:
@@ -33,10 +33,10 @@ class CourseSearchView(CourseTabView):
|
||||
"""
|
||||
Displays the home page for the specified course.
|
||||
"""
|
||||
return super(CourseSearchView, self).get(request, course_id, 'courseware', **kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||
return super().get(request, course_id, 'courseware', **kwargs)
|
||||
|
||||
def render_to_fragment(self, request, course=None, tab=None, **kwargs): # lint-amnesty, pylint: disable=arguments-differ, unused-argument
|
||||
course_id = six.text_type(course.id)
|
||||
course_id = str(course.id)
|
||||
home_fragment_view = CourseSearchFragmentView()
|
||||
return home_fragment_view.render_to_fragment(request, course_id=course_id, **kwargs)
|
||||
|
||||
@@ -53,7 +53,7 @@ class CourseSearchFragmentView(EdxFragmentView):
|
||||
course_key = CourseKey.from_string(course_id)
|
||||
course = get_course_overview_with_access(request.user, 'load', course_key, check_if_enrolled=True)
|
||||
course_url_name = default_course_url_name(course.id)
|
||||
course_url = reverse(course_url_name, kwargs={'course_id': six.text_type(course.id)})
|
||||
course_url = reverse(course_url_name, kwargs={'course_id': str(course.id)})
|
||||
|
||||
# Render the course home fragment
|
||||
context = {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Django Admin pages for DiscountRestrictionConfig.
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Contains code related to computing discount percentage
|
||||
and discount applicability.
|
||||
@@ -36,8 +35,8 @@ from common.djangoapps.track import segment
|
||||
# .. toggle_tickets: REVEM-282
|
||||
# .. toggle_warnings: This temporary feature toggle does not have a target removal date.
|
||||
DISCOUNT_APPLICABILITY_FLAG = LegacyWaffleFlag(
|
||||
waffle_namespace=LegacyWaffleFlagNamespace(name=u'discounts'),
|
||||
flag_name=u'enable_discounting',
|
||||
waffle_namespace=LegacyWaffleFlagNamespace(name='discounts'),
|
||||
flag_name='enable_discounting',
|
||||
module_name=__name__,
|
||||
)
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
|
||||
"""
|
||||
Discounts application configuration
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.20 on 2019-05-31 20:08
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.11.25 on 2019-10-22 17:20
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""Tests of openedx.features.discounts.applicability"""
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
from datetime import datetime, timedelta
|
||||
@@ -11,7 +10,7 @@ from django.contrib.sites.models import Site
|
||||
from django.utils.timezone import now
|
||||
from edx_toggles.toggles.testutils import override_waffle_flag
|
||||
from enterprise.models import EnterpriseCustomer, EnterpriseCustomerUser
|
||||
from mock import Mock, patch
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from common.djangoapps.course_modes.models import CourseMode
|
||||
from common.djangoapps.course_modes.tests.factories import CourseModeFactory
|
||||
@@ -35,12 +34,12 @@ class TestApplicability(ModuleStoreTestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestApplicability, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
self.site, _ = Site.objects.get_or_create(domain='example.com')
|
||||
self.user = UserFactory.create()
|
||||
self.course = CourseFactory.create(run='test', display_name='test')
|
||||
CourseModeFactory.create(course_id=self.course.id, mode_slug='verified')
|
||||
now_time = datetime.now(tz=pytz.UTC).strftime(u"%Y-%m-%d %H:%M:%S%z")
|
||||
now_time = datetime.now(tz=pytz.UTC).strftime("%Y-%m-%d %H:%M:%S%z")
|
||||
ExperimentData.objects.create(
|
||||
user=self.user, experiment_id=REV1008_EXPERIMENT_ID, key=str(self.course.id), value=now_time
|
||||
)
|
||||
|
||||
@@ -24,7 +24,7 @@ class TestDiscountRestrictionConfig(CacheIsolationTestCase):
|
||||
def setUp(self):
|
||||
self.course_overview = CourseOverviewFactory.create()
|
||||
self.user = UserFactory.create()
|
||||
super(TestDiscountRestrictionConfig, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
|
||||
@ddt.data(True, False)
|
||||
def test_disabled_for_course_stacked_config(
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"""
|
||||
Tests of the openedx.features.discounts.utils module.
|
||||
"""
|
||||
from mock import patch, Mock
|
||||
from unittest.mock import patch, Mock
|
||||
|
||||
import ddt
|
||||
import six
|
||||
@@ -33,7 +33,7 @@ class TestStrikeoutPrice(TestCase):
|
||||
):
|
||||
content, has_discount = utils.format_strikeout_price(Mock(name='user'), Mock(name='course'))
|
||||
|
||||
assert six.text_type(content) == u"<span class='price'>$100</span>"
|
||||
assert str(content) == "<span class='price'>$100</span>"
|
||||
assert not has_discount
|
||||
|
||||
@ddt.data((15, 100, "$100", "$85",), (50, 50, "$50", "$25"), (10, 99, "$99", "$89.10"))
|
||||
@@ -47,12 +47,12 @@ class TestStrikeoutPrice(TestCase):
|
||||
):
|
||||
content, has_discount = utils.format_strikeout_price(Mock(name='user'), Mock(name='course'))
|
||||
|
||||
assert six.text_type(content) == (
|
||||
u"<span class='sr-only'>"
|
||||
u"Original price: <span class='price original'>{original_price}</span>, discount price: "
|
||||
u"</span>"
|
||||
u"<span class='price discount'>{discount_price}</span> "
|
||||
u"<del aria-hidden='true'><span class='price original'>{original_price}</span></del>"
|
||||
assert str(content) == (
|
||||
"<span class='sr-only'>"
|
||||
"Original price: <span class='price original'>{original_price}</span>, discount price: "
|
||||
"</span>"
|
||||
"<span class='price discount'>{discount_price}</span> "
|
||||
"<del aria-hidden='true'><span class='price original'>{original_price}</span></del>"
|
||||
).format(original_price=formatted_base_price, discount_price=final_price)
|
||||
assert has_discount
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
"""Tests of openedx.features.discounts.views"""
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
|
||||
import jwt
|
||||
@@ -19,20 +18,20 @@ class TestCourseUserDiscount(ModuleStoreTestCase):
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
super(TestCourseUserDiscount, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||
super().setUp()
|
||||
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': six.text_type(self.course.id)}
|
||||
kwargs={'course_key_string': str(self.course.id)}
|
||||
)
|
||||
|
||||
def test_url(self):
|
||||
"""
|
||||
Test that the url hasn't changed
|
||||
"""
|
||||
assert self.url == ('/api/discounts/course/' + six.text_type(self.course.id))
|
||||
assert self.url == ('/api/discounts/course/' + str(self.course.id))
|
||||
|
||||
def test_course_user_discount(self):
|
||||
"""
|
||||
|
||||
@@ -9,8 +9,8 @@ from django.conf.urls import url
|
||||
from .views import CourseUserDiscount, CourseUserDiscountWithUserParam
|
||||
|
||||
urlpatterns = [
|
||||
url(r'^course/{}'.format(settings.COURSE_KEY_PATTERN), CourseUserDiscount.as_view(), name='course_user_discount'),
|
||||
url(r'^user/(?P<user_id>[^/]*)/course/{}'.format(settings.COURSE_KEY_PATTERN),
|
||||
url(fr'^course/{settings.COURSE_KEY_PATTERN}', CourseUserDiscount.as_view(), name='course_user_discount'),
|
||||
url(fr'^user/(?P<user_id>[^/]*)/course/{settings.COURSE_KEY_PATTERN}',
|
||||
CourseUserDiscountWithUserParam.as_view(),
|
||||
name='course_user_discount_with_param'),
|
||||
]
|
||||
|
||||
@@ -43,7 +43,7 @@ def offer_banner_wrapper(user, block, view, frag, context): # pylint: disable=W
|
||||
# Course content must be escaped to render correctly due to the way the
|
||||
# way the XBlock rendering works. Transforming the safe markup to unicode
|
||||
# escapes correctly.
|
||||
offer_banner_fragment.content = six.text_type(offer_banner_fragment.content)
|
||||
offer_banner_fragment.content = str(offer_banner_fragment.content)
|
||||
|
||||
offer_banner_fragment.add_content(frag.content)
|
||||
offer_banner_fragment.add_fragment_resources(frag)
|
||||
@@ -69,9 +69,9 @@ def _get_discount_prices(user, course, assume_discount=False):
|
||||
discounted_price = base_price * ((100.0 - percentage) / 100)
|
||||
if discounted_price: # leave 0 prices alone, as format_course_price below will adjust to 'Free'
|
||||
if discounted_price == int(discounted_price):
|
||||
discounted_price = '{:0.0f}'.format(discounted_price)
|
||||
discounted_price = f'{discounted_price:0.0f}'
|
||||
else:
|
||||
discounted_price = '{:0.2f}'.format(discounted_price)
|
||||
discounted_price = f'{discounted_price:0.2f}'
|
||||
|
||||
return format_course_price(base_price), format_course_price(discounted_price), percentage
|
||||
else:
|
||||
@@ -215,7 +215,7 @@ def get_first_purchase_offer_banner_fragment_from_key(user, course_key):
|
||||
shouldn't show a first purchase offer message for this user.
|
||||
"""
|
||||
request_cache = RequestCache('get_first_purchase_offer_banner_fragment_from_key')
|
||||
cache_key = 'html:{},{}'.format(user.id, course_key)
|
||||
cache_key = f'html:{user.id},{course_key}'
|
||||
cache_response = request_cache.get_cached_response(cache_key)
|
||||
if cache_response.is_found:
|
||||
cached_html = cache_response.value
|
||||
|
||||
Reference in New Issue
Block a user