Applied pylint-amnesty to commerce
This commit is contained in:
@@ -69,7 +69,7 @@ class BasketsViewTests(EnrollmentEventTestMixin, UserMixin, ModuleStoreTestCase)
|
|||||||
self.assertEqual(actual, expected_msg)
|
self.assertEqual(actual, expected_msg)
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BasketsViewTests, self).setUp()
|
super(BasketsViewTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.url = reverse('commerce_api:v0:baskets:create')
|
self.url = reverse('commerce_api:v0:baskets:create')
|
||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
@@ -290,7 +290,7 @@ class BasketOrderViewTests(UserMixin, TestCase):
|
|||||||
path = reverse_lazy(view_name, kwargs={'basket_id': 1})
|
path = reverse_lazy(view_name, kwargs={'basket_id': 1})
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(BasketOrderViewTests, self).setUp()
|
super(BasketOrderViewTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
def test_order_found(self):
|
def test_order_found(self):
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ class BasketsView(APIView):
|
|||||||
u'Failed to handle marketing opt-in flag: user="%s", course="%s"', user.username, course_key
|
u'Failed to handle marketing opt-in flag: user="%s", course="%s"', user.username, course_key
|
||||||
)
|
)
|
||||||
|
|
||||||
def post(self, request, *args, **kwargs):
|
def post(self, request, *args, **kwargs): # lint-amnesty, pylint: disable=unused-argument
|
||||||
"""
|
"""
|
||||||
Attempt to enroll the user.
|
Attempt to enroll the user.
|
||||||
"""
|
"""
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class Course(object):
|
|||||||
course_id = CourseKey.from_string(six.text_type(course_id))
|
course_id = CourseKey.from_string(six.text_type(course_id))
|
||||||
except InvalidKeyError:
|
except InvalidKeyError:
|
||||||
log.debug(u'[%s] is not a valid course key.', course_id)
|
log.debug(u'[%s] is not a valid course key.', course_id)
|
||||||
raise ValueError
|
raise ValueError # lint-amnesty, pylint: disable=raise-missing-from
|
||||||
|
|
||||||
course_modes = CourseMode.objects.filter(course_id=course_id)
|
course_modes = CourseMode.objects.filter(course_id=course_id)
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
""" Custom API permissions. """
|
""" Custom API permissions. """
|
||||||
|
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||||
from rest_framework.permissions import BasePermission, DjangoModelPermissions
|
from rest_framework.permissions import BasePermission, DjangoModelPermissions
|
||||||
|
|
||||||
from openedx.core.lib.api.permissions import ApiKeyHeaderPermission
|
from openedx.core.lib.api.permissions import ApiKeyHeaderPermission
|
||||||
@@ -22,7 +22,7 @@ class IsAuthenticatedOrActivationOverridden(BasePermission):
|
|||||||
def has_permission(self, request, view):
|
def has_permission(self, request, view):
|
||||||
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
|
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
|
||||||
try:
|
try:
|
||||||
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id'])
|
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id']) # lint-amnesty, pylint: disable=protected-access
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
pass
|
pass
|
||||||
return request.user.is_authenticated
|
return request.user.is_authenticated
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ def validate_course_id(course_id):
|
|||||||
try:
|
try:
|
||||||
course_key = CourseKey.from_string(six.text_type(course_id))
|
course_key = CourseKey.from_string(six.text_type(course_id))
|
||||||
except InvalidKeyError:
|
except InvalidKeyError:
|
||||||
raise serializers.ValidationError(
|
raise serializers.ValidationError( # lint-amnesty, pylint: disable=raise-missing-from
|
||||||
_(u"{course_id} is not a valid course key.").format(
|
_(u"{course_id} is not a valid course key.").format(
|
||||||
course_id=course_id
|
course_id=course_id
|
||||||
)
|
)
|
||||||
@@ -69,7 +69,7 @@ class PossiblyUndefinedDateTimeField(serializers.DateTimeField):
|
|||||||
def to_representation(self, value):
|
def to_representation(self, value):
|
||||||
if value is UNDEFINED:
|
if value is UNDEFINED:
|
||||||
return None
|
return None
|
||||||
return super(PossiblyUndefinedDateTimeField, self).to_representation(value)
|
return super(PossiblyUndefinedDateTimeField, self).to_representation(value) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
|
|
||||||
|
|
||||||
class CourseSerializer(serializers.Serializer):
|
class CourseSerializer(serializers.Serializer):
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ class CourseTests(TestCase):
|
|||||||
""" Tests for Course model. """
|
""" Tests for Course model. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CourseTests, self).setUp()
|
super(CourseTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.course = Course('a/b/c', [])
|
self.course = Course('a/b/c', [])
|
||||||
|
|
||||||
@ddt.unpack
|
@ddt.unpack
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class CourseApiViewTestMixin(object):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CourseApiViewTestMixin, self).setUp()
|
super(CourseApiViewTestMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.course = CourseFactory.create()
|
self.course = CourseFactory.create()
|
||||||
self.course_mode = CourseMode.objects.create(
|
self.course_mode = CourseMode.objects.create(
|
||||||
course_id=self.course.id,
|
course_id=self.course.id,
|
||||||
@@ -114,7 +114,7 @@ class CourseRetrieveUpdateViewTests(CourseApiViewTestMixin, ModuleStoreTestCase)
|
|||||||
}
|
}
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(CourseRetrieveUpdateViewTests, self).setUp()
|
super(CourseRetrieveUpdateViewTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.path = reverse('commerce_api:v1:courses:retrieve_update', args=[six.text_type(self.course.id)])
|
self.path = reverse('commerce_api:v1:courses:retrieve_update', args=[six.text_type(self.course.id)])
|
||||||
self.user = UserFactory.create()
|
self.user = UserFactory.create()
|
||||||
self.client.login(username=self.user.username, password=PASSWORD)
|
self.client.login(username=self.user.username, password=PASSWORD)
|
||||||
@@ -450,7 +450,7 @@ class OrderViewTests(UserMixin, TestCase):
|
|||||||
path = reverse_lazy(view_name, kwargs={'number': ORDER_NUMBER})
|
path = reverse_lazy(view_name, kwargs={'number': ORDER_NUMBER})
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(OrderViewTests, self).setUp()
|
super(OrderViewTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self._login()
|
self._login()
|
||||||
|
|
||||||
def test_order_found(self):
|
def test_order_found(self):
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ Commerce views
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from django.contrib.auth.models import User
|
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from edx_rest_api_client import exceptions
|
from edx_rest_api_client import exceptions
|
||||||
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
|
from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication
|
||||||
@@ -53,7 +53,7 @@ class CourseRetrieveUpdateView(PutAsCreateMixin, RetrieveUpdateAPIView):
|
|||||||
# rather than a CourseMode, so this isn't really used.
|
# rather than a CourseMode, so this isn't really used.
|
||||||
queryset = CourseMode.objects.all()
|
queryset = CourseMode.objects.all()
|
||||||
|
|
||||||
def get_object(self, queryset=None):
|
def get_object(self, queryset=None): # lint-amnesty, pylint: disable=arguments-differ, unused-argument
|
||||||
course_id = self.kwargs.get(self.lookup_url_kwarg)
|
course_id = self.kwargs.get(self.lookup_url_kwarg)
|
||||||
course = Course.get(course_id)
|
course = Course.get(course_id)
|
||||||
|
|
||||||
@@ -80,7 +80,7 @@ class OrderView(APIView):
|
|||||||
# anonymous user object attached to the request with the actual user object (if it exists)
|
# anonymous user object attached to the request with the actual user object (if it exists)
|
||||||
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
|
if not request.user.is_authenticated and is_account_activation_requirement_disabled():
|
||||||
try:
|
try:
|
||||||
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id'])
|
request.user = User.objects.get(id=request.session._session_cache['_auth_user_id']) # lint-amnesty, pylint: disable=protected-access
|
||||||
except User.DoesNotExist:
|
except User.DoesNotExist:
|
||||||
return JsonResponse(status=403)
|
return JsonResponse(status=403)
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
class InvalidResponseError(Exception):
|
class InvalidResponseError(Exception):
|
||||||
""" Exception raised when an API response is invalid. """
|
""" Exception raised when an API response is invalid. """
|
||||||
pass
|
pass # lint-amnesty, pylint: disable=unnecessary-pass
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class DetailResponse(JsonResponse):
|
|||||||
|
|
||||||
def __init__(self, message, status=HTTP_200_OK):
|
def __init__(self, message, status=HTTP_200_OK):
|
||||||
data = {'detail': message}
|
data = {'detail': message}
|
||||||
super(DetailResponse, self).__init__(resp_obj=data, status=status)
|
super(DetailResponse, self).__init__(resp_obj=data, status=status) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
|
|
||||||
|
|
||||||
class InternalRequestErrorResponse(DetailResponse):
|
class InternalRequestErrorResponse(DetailResponse):
|
||||||
@@ -22,4 +22,4 @@ class InternalRequestErrorResponse(DetailResponse):
|
|||||||
u'Call to E-Commerce API failed. Internal Service Message: [{internal_message}]'
|
u'Call to E-Commerce API failed. Internal Service Message: [{internal_message}]'
|
||||||
.format(internal_message=internal_message)
|
.format(internal_message=internal_message)
|
||||||
)
|
)
|
||||||
super(InternalRequestErrorResponse, self).__init__(message=message, status=HTTP_500_INTERNAL_SERVER_ERROR)
|
super(InternalRequestErrorResponse, self).__init__(message=message, status=HTTP_500_INTERNAL_SERVER_ERROR) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
|
|||||||
@@ -289,4 +289,4 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
raise CommandError(u'Command failed with traceback %s' % str(ex))
|
raise CommandError(u'Command failed with traceback %s' % str(ex)) # lint-amnesty, pylint: disable=raise-missing-from
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ class EdxRestApiClientTest(TestCase):
|
|||||||
]
|
]
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(EdxRestApiClientTest, self).setUp()
|
super(EdxRestApiClientTest, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.user = UserFactory()
|
self.user = UserFactory()
|
||||||
|
|
||||||
@httpretty.activate
|
@httpretty.activate
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class mock_basket_order(mock_ecommerce_api_endpoint):
|
|||||||
method = httpretty.GET
|
method = httpretty.GET
|
||||||
|
|
||||||
def __init__(self, basket_id, **kwargs):
|
def __init__(self, basket_id, **kwargs):
|
||||||
super(mock_basket_order, self).__init__(**kwargs)
|
super(mock_basket_order, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.basket_id = basket_id
|
self.basket_id = basket_id
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
@@ -131,7 +131,7 @@ class mock_process_refund(mock_ecommerce_api_endpoint):
|
|||||||
method = httpretty.PUT
|
method = httpretty.PUT
|
||||||
|
|
||||||
def __init__(self, refund_id, **kwargs):
|
def __init__(self, refund_id, **kwargs):
|
||||||
super(mock_process_refund, self).__init__(**kwargs)
|
super(mock_process_refund, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.refund_id = refund_id
|
self.refund_id = refund_id
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
@@ -145,7 +145,7 @@ class mock_order_endpoint(mock_ecommerce_api_endpoint):
|
|||||||
method = httpretty.GET
|
method = httpretty.GET
|
||||||
|
|
||||||
def __init__(self, order_number, **kwargs):
|
def __init__(self, order_number, **kwargs):
|
||||||
super(mock_order_endpoint, self).__init__(**kwargs)
|
super(mock_order_endpoint, self).__init__(**kwargs) # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.order_number = order_number
|
self.order_number = order_number
|
||||||
|
|
||||||
def get_path(self):
|
def get_path(self):
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ class TestRefundSignal(TestCase):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestRefundSignal, self).setUp()
|
super(TestRefundSignal, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
|
|
||||||
# Ensure the E-Commerce service user exists
|
# Ensure the E-Commerce service user exists
|
||||||
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
|
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class EcommerceServiceTests(TestCase):
|
|||||||
self.user = UserFactory.create()
|
self.user = UserFactory.create()
|
||||||
self.request = self.request_factory.get("foo")
|
self.request = self.request_factory.get("foo")
|
||||||
update_commerce_config(enabled=True)
|
update_commerce_config(enabled=True)
|
||||||
super(EcommerceServiceTests, self).setUp()
|
super(EcommerceServiceTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
|
|
||||||
def test_is_enabled(self):
|
def test_is_enabled(self):
|
||||||
"""Verify that is_enabled() returns True when ecomm checkout is enabled. """
|
"""Verify that is_enabled() returns True when ecomm checkout is enabled. """
|
||||||
@@ -187,7 +187,7 @@ class RefundUtilMethodTests(ModuleStoreTestCase):
|
|||||||
"""Tests for Refund Utilities"""
|
"""Tests for Refund Utilities"""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(RefundUtilMethodTests, self).setUp()
|
super(RefundUtilMethodTests, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.user = UserFactory()
|
self.user = UserFactory()
|
||||||
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
|
UserFactory(username=settings.ECOMMERCE_SERVICE_WORKER_USERNAME, is_staff=True)
|
||||||
|
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class UserMixin(object):
|
|||||||
""" Mixin for tests involving users. """
|
""" Mixin for tests involving users. """
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(UserMixin, self).setUp()
|
super(UserMixin, self).setUp() # lint-amnesty, pylint: disable=super-with-arguments
|
||||||
self.user = UserFactory()
|
self.user = UserFactory()
|
||||||
|
|
||||||
def _login(self):
|
def _login(self):
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from common.djangoapps.course_modes.models import CourseMode
|
|||||||
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client, is_commerce_service_configured
|
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client, is_commerce_service_configured
|
||||||
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
from openedx.core.djangoapps.site_configuration import helpers as configuration_helpers
|
||||||
from openedx.core.djangoapps.theming import helpers as theming_helpers
|
from openedx.core.djangoapps.theming import helpers as theming_helpers
|
||||||
from common.djangoapps.student.models import CourseEnrollment
|
from common.djangoapps.student.models import CourseEnrollment # lint-amnesty, pylint: disable=unused-import
|
||||||
|
|
||||||
from .models import CommerceConfiguration
|
from .models import CommerceConfiguration
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user