INCR-253 Run python-modernize on lms/djangoapps/shoppingcart/management lms/djangoapps/shoppingcart/tests (#20554)
* run python modernize * run isort * Fix quality
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
Script for retiring order that went through cybersource but weren't
|
||||
marked as "purchased" in the db
|
||||
"""
|
||||
from __future__ import print_function
|
||||
from __future__ import absolute_import, print_function
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
from six import text_type
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
"""Tests for the retire_order command"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
from django.core.management import call_command
|
||||
|
||||
@@ -13,6 +13,8 @@ request to the view with param "success"
|
||||
set to "success" or "failure". The view defaults to payment success.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.http import HttpResponse, HttpResponseBadRequest
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.generic.base import View
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
"""
|
||||
Dashboard with Shopping Cart History tests with configuration overrides.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.urls import reverse
|
||||
from mock import patch
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Unit tests for shoppingcart context_processor
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from mock import Mock, patch
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
"""
|
||||
Tests for the Shopping Cart Models
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import json
|
||||
@@ -10,16 +12,18 @@ from decimal import Decimal
|
||||
|
||||
import ddt
|
||||
import pytz
|
||||
import six
|
||||
from six.moves import range
|
||||
from boto.exception import BotoServerError # this is a super-class of SESError and catches connection errors
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.models import AnonymousUser
|
||||
from django.core import mail
|
||||
from django.core.mail.message import EmailMessage
|
||||
from django.urls import reverse
|
||||
from django.db import DatabaseError
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from mock import Mock, MagicMock, patch
|
||||
from django.urls import reverse
|
||||
from mock import MagicMock, Mock, patch
|
||||
from opaque_keys.edx.locator import CourseLocator
|
||||
|
||||
from course_modes.models import CourseMode
|
||||
@@ -69,7 +73,7 @@ class OrderTest(ModuleStoreTestCase):
|
||||
course = CourseFactory.create()
|
||||
self.course_key = course.id
|
||||
self.other_course_keys = []
|
||||
for __ in xrange(1, 5):
|
||||
for __ in range(1, 5):
|
||||
course_key = CourseFactory.create().id
|
||||
CourseMode.objects.create(
|
||||
course_id=course_key,
|
||||
@@ -265,7 +269,7 @@ class OrderTest(ModuleStoreTestCase):
|
||||
self.assertEquals(len(mail.outbox), 1)
|
||||
self.assertEquals('Order Payment Confirmation', mail.outbox[0].subject)
|
||||
self.assertIn(settings.PAYMENT_SUPPORT_EMAIL, mail.outbox[0].body)
|
||||
self.assertIn(unicode(cart.total_cost), mail.outbox[0].body)
|
||||
self.assertIn(six.text_type(cart.total_cost), mail.outbox[0].body)
|
||||
self.assertIn(item.additional_instruction_text(), mail.outbox[0].body)
|
||||
|
||||
# Verify Google Analytics event fired for purchase
|
||||
@@ -280,8 +284,8 @@ class OrderTest(ModuleStoreTestCase):
|
||||
'products': [
|
||||
{
|
||||
'sku': u'CertificateItem.honor',
|
||||
'name': unicode(self.course_key),
|
||||
'category': unicode(self.course_key.org),
|
||||
'name': six.text_type(self.course_key),
|
||||
'category': six.text_type(self.course_key.org),
|
||||
'price': '40.00',
|
||||
'id': 1,
|
||||
'quantity': 1
|
||||
@@ -879,8 +883,8 @@ class CertificateItemTest(ModuleStoreTestCase):
|
||||
'products': [
|
||||
{
|
||||
'sku': u'CertificateItem.verified',
|
||||
'name': unicode(self.course_key),
|
||||
'category': unicode(self.course_key.org),
|
||||
'name': six.text_type(self.course_key),
|
||||
'category': six.text_type(self.course_key.org),
|
||||
'price': '40.00',
|
||||
'id': 1,
|
||||
'quantity': 1
|
||||
@@ -1277,7 +1281,7 @@ class InvoiceHistoryTest(TestCase):
|
||||
'qty': 1,
|
||||
'unit_price': '123.45',
|
||||
'currency': 'usd',
|
||||
'course_id': unicode(self.course_key)
|
||||
'course_id': six.text_type(self.course_key)
|
||||
}])
|
||||
|
||||
# Create a second invoice item
|
||||
@@ -1292,13 +1296,13 @@ class InvoiceHistoryTest(TestCase):
|
||||
'qty': 1,
|
||||
'unit_price': '123.45',
|
||||
'currency': 'usd',
|
||||
'course_id': unicode(self.course_key)
|
||||
'course_id': six.text_type(self.course_key)
|
||||
},
|
||||
{
|
||||
'qty': 2,
|
||||
'unit_price': '456.78',
|
||||
'currency': 'usd',
|
||||
'course_id': unicode(self.course_key)
|
||||
'course_id': six.text_type(self.course_key)
|
||||
}
|
||||
])
|
||||
|
||||
@@ -1366,7 +1370,7 @@ class InvoiceHistoryTest(TestCase):
|
||||
def _assert_history_contact_info(self, **kwargs):
|
||||
"""Check contact info in the latest history record. """
|
||||
contact_info = self._latest_history()['contact_info']
|
||||
for key, value in kwargs.iteritems():
|
||||
for key, value in six.iteritems(kwargs):
|
||||
self.assertEqual(contact_info[key], value)
|
||||
|
||||
def _assert_history_items(self, expected_items):
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
Tests for the fake payment page used in acceptance tests.
|
||||
"""
|
||||
|
||||
from __future__ import absolute_import
|
||||
|
||||
from collections import OrderedDict
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
"""
|
||||
Tests for Pdf file
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import unittest
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
|
||||
from django.conf import settings
|
||||
from django.test.utils import override_settings
|
||||
from six.moves import range
|
||||
|
||||
from shoppingcart.pdf import PDFInvoice
|
||||
from shoppingcart.utils import parse_pages
|
||||
|
||||
@@ -2,6 +2,8 @@
|
||||
"""
|
||||
Tests for the Shopping Cart Models
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import datetime
|
||||
import StringIO
|
||||
from textwrap import dedent
|
||||
|
||||
@@ -1,28 +1,32 @@
|
||||
"""
|
||||
Tests for Shopping Cart views
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from collections import OrderedDict
|
||||
from datetime import datetime, timedelta
|
||||
from decimal import Decimal
|
||||
from urlparse import urlparse
|
||||
|
||||
import ddt
|
||||
import pytz
|
||||
import six
|
||||
from django.conf import settings
|
||||
from django.contrib.admin.sites import AdminSite
|
||||
from django.contrib.auth.models import Group, User
|
||||
from django.contrib.messages.storage.fallback import FallbackStorage
|
||||
from django.core import mail
|
||||
from django.core.cache import cache
|
||||
from django.urls import reverse
|
||||
from django.http import HttpRequest
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.urls import reverse
|
||||
from freezegun import freeze_time
|
||||
from mock import Mock, patch
|
||||
from pytz import UTC
|
||||
from six import text_type
|
||||
from six.moves import range
|
||||
from six.moves.urllib.parse import urlparse # pylint: disable=import-error
|
||||
|
||||
from common.test.utils import XssTestMixin
|
||||
from course_modes.models import CourseMode
|
||||
@@ -936,7 +940,7 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
|
||||
'quantity': 1,
|
||||
'line_cost': 40,
|
||||
'line_desc': u'{} for course Test Course'.format(self.verified_course_mode.mode_display_name),
|
||||
'course_key': unicode(self.verified_course_key)
|
||||
'course_key': six.text_type(self.verified_course_key)
|
||||
})
|
||||
|
||||
def test_show_receipt_xss(self):
|
||||
@@ -997,14 +1001,14 @@ class ShoppingCartViewsTests(SharedModuleStoreTestCase, XssTestMixin):
|
||||
'quantity': 1,
|
||||
'line_cost': 40,
|
||||
'line_desc': 'Registration for Course: Robot Super Course',
|
||||
'course_key': unicode(self.course_key)
|
||||
'course_key': six.text_type(self.course_key)
|
||||
})
|
||||
self.assertEqual(items[1], {
|
||||
'unit_cost': 40,
|
||||
'quantity': 1,
|
||||
'line_cost': 40,
|
||||
'line_desc': u'{} for course Test Course'.format(self.verified_course_mode.mode_display_name),
|
||||
'course_key': unicode(self.verified_course_key)
|
||||
'course_key': six.text_type(self.verified_course_key)
|
||||
})
|
||||
|
||||
def test_receipt_json_refunded(self):
|
||||
@@ -1547,7 +1551,7 @@ class ReceiptRedirectTest(SharedModuleStoreTestCase):
|
||||
# page in the verify_student app
|
||||
redirect_url = reverse(
|
||||
'verify_student_payment_confirmation',
|
||||
kwargs={'course_id': unicode(self.course_key)}
|
||||
kwargs={'course_id': six.text_type(self.course_key)}
|
||||
)
|
||||
redirect_url += '?payment-order-num={order_num}'.format(
|
||||
order_num=self.cart.id
|
||||
@@ -1760,7 +1764,7 @@ class RegistrationCodeRedemptionCourseEnrollment(SharedModuleStoreTestCase):
|
||||
cache.clear()
|
||||
url = reverse('register_code_redemption', args=['asdasd'])
|
||||
self.login_user()
|
||||
for i in xrange(30): # pylint: disable=unused-variable
|
||||
for i in range(30): # pylint: disable=unused-variable
|
||||
response = self.client.post(url)
|
||||
self.assertEquals(response.status_code, 404)
|
||||
|
||||
@@ -1784,7 +1788,7 @@ class RegistrationCodeRedemptionCourseEnrollment(SharedModuleStoreTestCase):
|
||||
cache.clear()
|
||||
url = reverse('register_code_redemption', args=['asdasd'])
|
||||
self.login_user()
|
||||
for i in xrange(30): # pylint: disable=unused-variable
|
||||
for i in range(30): # pylint: disable=unused-variable
|
||||
response = self.client.get(url)
|
||||
self.assertEquals(response.status_code, 404)
|
||||
|
||||
@@ -2033,7 +2037,7 @@ class DonationViewTest(SharedModuleStoreTestCase):
|
||||
if course_id is not None:
|
||||
self.assertEqual(
|
||||
payment_info["payment_params"]["merchant_defined_data1"],
|
||||
unicode(course_id)
|
||||
six.text_type(course_id)
|
||||
)
|
||||
self.assertEqual(
|
||||
payment_info["payment_params"]["merchant_defined_data2"],
|
||||
|
||||
Reference in New Issue
Block a user