Add configurable refund window

Add configuration model for enrollment refunds.

Use order info from otto in refund window calculation

Delete dupe tests. Extend tests to include window tests

Move ecom client from lib to djangoapps in openedx
This commit is contained in:
Bill DeRusha
2015-10-23 17:53:51 -04:00
parent 16ab4f4333
commit 1f77810fad
12 changed files with 513 additions and 104 deletions

View File

@@ -1,40 +1,3 @@
""" Commerce app. """
from django.conf import settings
from edx_rest_api_client.client import EdxRestApiClient
from eventtracking import tracker
def create_tracking_context(user):
""" Assembles attributes from user and request objects to be sent along
in ecommerce api calls for tracking purposes. """
context_tracker = tracker.get_tracker().resolve_context()
return {
'lms_user_id': user.id,
'lms_client_id': context_tracker.get('client_id'),
'lms_ip': context_tracker.get('ip'),
}
def is_commerce_service_configured():
"""
Return a Boolean indicating whether or not configuration is present to use
the external commerce service.
"""
return bool(settings.ECOMMERCE_API_URL and settings.ECOMMERCE_API_SIGNING_KEY)
def ecommerce_api_client(user):
""" Returns an E-Commerce API client setup with authentication for the specified user. """
return EdxRestApiClient(settings.ECOMMERCE_API_URL,
settings.ECOMMERCE_API_SIGNING_KEY,
user.username,
user.profile.name,
user.email,
tracking_context=create_tracking_context(user),
issuer=settings.JWT_ISSUER,
expires_in=settings.JWT_EXPIRATION)
# this is here to support registering the signals in signals.py
from commerce import signals # pylint: disable=unused-import

View File

@@ -9,7 +9,6 @@ from rest_framework.permissions import IsAuthenticated
from rest_framework.status import HTTP_406_NOT_ACCEPTABLE, HTTP_409_CONFLICT
from rest_framework.views import APIView
from commerce import ecommerce_api_client
from commerce.constants import Messages
from commerce.exceptions import InvalidResponseError
from commerce.http import DetailResponse, InternalRequestErrorResponse
@@ -19,6 +18,7 @@ from courseware import courses
from embargo import api as embargo_api
from enrollment.api import add_enrollment
from enrollment.views import EnrollmentCrossDomainSessionAuth
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
from openedx.core.djangoapps.user_api.preferences.api import update_email_opt_in
from openedx.core.lib.api.authentication import OAuth2AuthenticationAllowInactiveUser
from student.models import CourseEnrollment

View File

@@ -9,11 +9,11 @@ from rest_framework.generics import RetrieveUpdateAPIView, ListAPIView
from rest_framework.permissions import IsAuthenticated
from rest_framework_oauth.authentication import OAuth2Authentication
from commerce import ecommerce_api_client
from commerce.api.v1.models import Course
from commerce.api.v1.permissions import ApiKeyOrModelPermission
from commerce.api.v1.serializers import CourseSerializer
from course_modes.models import CourseMode
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
from openedx.core.lib.api.mixins import PutAsCreateMixin
from util.json_request import JsonResponse

View File

@@ -15,7 +15,7 @@ import requests
from microsite_configuration import microsite
from request_cache.middleware import RequestCache
from student.models import UNENROLL_DONE
from commerce import ecommerce_api_client, is_commerce_service_configured
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client, is_commerce_service_configured
log = logging.getLogger(__name__)

View File

@@ -12,7 +12,7 @@ import jwt
import mock
from edx_rest_api_client import auth
from commerce import ecommerce_api_client
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
from student.tests.factories import UserFactory
JSON = 'application/json'
@@ -61,7 +61,7 @@ class EdxRestApiClientTest(TestCase):
mock_tracker = mock.Mock()
mock_tracker.resolve_context = mock.Mock(return_value={'client_id': self.TEST_CLIENT_ID, 'ip': '127.0.0.1'})
with mock.patch('commerce.tracker.get_tracker', return_value=mock_tracker):
with mock.patch('openedx.core.djangoapps.commerce.utils.tracker.get_tracker', return_value=mock_tracker):
ecommerce_api_client(self.user).baskets(1).post()
# make sure the request's JWT token payload included correct tracking context values.

View File

@@ -29,7 +29,6 @@ from eventtracking import tracker
from opaque_keys import InvalidKeyError
from opaque_keys.edx.keys import CourseKey, UsageKey
from commerce import ecommerce_api_client
from commerce.utils import audit_log
from course_modes.models import CourseMode
from courseware.url_helpers import get_redirect_url
@@ -37,6 +36,7 @@ from edx_rest_api_client.exceptions import SlumberBaseException
from edxmako.shortcuts import render_to_response, render_to_string
from embargo import api as embargo_api
from microsite_configuration import microsite
from openedx.core.djangoapps.commerce.utils import ecommerce_api_client
from openedx.core.djangoapps.user_api.accounts import NAME_MIN_LENGTH
from openedx.core.djangoapps.user_api.accounts.api import update_account_settings
from openedx.core.djangoapps.user_api.errors import UserNotFound, AccountValidationError