ECOM-1816: added the provider detail on the receipt page.
This commit is contained in:
@@ -8,6 +8,7 @@ import pytz
|
||||
import uuid
|
||||
|
||||
from django.db import transaction
|
||||
from lms.djangoapps.django_comment_client.utils import JsonResponse
|
||||
|
||||
from openedx.core.djangoapps.credit.exceptions import (
|
||||
UserIsNotEligible,
|
||||
@@ -39,7 +40,6 @@ def get_credit_providers(providers_list=None):
|
||||
|
||||
Returns:
|
||||
list of credit providers represented as dictionaries
|
||||
|
||||
Response Values:
|
||||
>>> get_credit_providers(['hogwarts'])
|
||||
[
|
||||
@@ -60,10 +60,52 @@ def get_credit_providers(providers_list=None):
|
||||
...
|
||||
]
|
||||
"""
|
||||
|
||||
return CreditProvider.get_credit_providers(providers_list=providers_list)
|
||||
|
||||
|
||||
def get_credit_provider_info(request, provider_id): # pylint: disable=unused-argument
|
||||
"""Retrieve the 'CreditProvider' model data against provided
|
||||
credit provider.
|
||||
|
||||
Args:
|
||||
provider_id (str): The identifier for the credit provider
|
||||
|
||||
Returns: 'CreditProvider' data dictionary
|
||||
|
||||
Example Usage:
|
||||
>>> get_credit_provider_info("hogwarts")
|
||||
{
|
||||
"provider_id": "hogwarts",
|
||||
"display_name": "Hogwarts School of Witchcraft and Wizardry",
|
||||
"provider_url": "https://credit.example.com/",
|
||||
"provider_status_url": "https://credit.example.com/status/",
|
||||
"provider_description: "A new model for the Witchcraft and Wizardry School System.",
|
||||
"enable_integration": False,
|
||||
"fulfillment_instructions": "
|
||||
<p>In order to fulfill credit, Hogwarts School of Witchcraft and Wizardry requires learners to:</p>
|
||||
<ul>
|
||||
<li>Sample instruction abc</li>
|
||||
<li>Sample instruction xyz</li>
|
||||
</ul>",
|
||||
}
|
||||
|
||||
"""
|
||||
credit_provider = CreditProvider.get_credit_provider(provider_id=provider_id)
|
||||
credit_provider_data = {}
|
||||
if credit_provider:
|
||||
credit_provider_data = {
|
||||
"provider_id": credit_provider.provider_id,
|
||||
"display_name": credit_provider.display_name,
|
||||
"provider_url": credit_provider.provider_url,
|
||||
"provider_status_url": credit_provider.provider_status_url,
|
||||
"provider_description": credit_provider.provider_description,
|
||||
"enable_integration": credit_provider.enable_integration,
|
||||
"fulfillment_instructions": credit_provider.fulfillment_instructions
|
||||
}
|
||||
|
||||
return JsonResponse(credit_provider_data)
|
||||
|
||||
|
||||
@transaction.commit_on_success
|
||||
def create_credit_request(course_key, provider_id, username):
|
||||
"""
|
||||
|
||||
@@ -3,11 +3,16 @@ Tests for the API functions in the credit app.
|
||||
"""
|
||||
import datetime
|
||||
import ddt
|
||||
import json
|
||||
from mock import patch
|
||||
import pytz
|
||||
import unittest
|
||||
|
||||
from django.conf import settings
|
||||
from django.test import TestCase
|
||||
from django.test.utils import override_settings
|
||||
from django.db import connection, transaction
|
||||
from django.core.urlresolvers import reverse, NoReverseMatch
|
||||
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
|
||||
@@ -33,6 +38,8 @@ from student.tests.factories import UserFactory
|
||||
|
||||
TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6"
|
||||
|
||||
from util.testing import UrlResetMixin
|
||||
|
||||
|
||||
@override_settings(CREDIT_PROVIDER_SECRET_KEYS={
|
||||
"hogwarts": TEST_CREDIT_PROVIDER_SECRET_KEY,
|
||||
@@ -691,3 +698,117 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase):
|
||||
"""Check the user's credit status. """
|
||||
statuses = api.get_credit_requests_for_user(self.USER_INFO["username"])
|
||||
self.assertEqual(statuses[0]["status"], expected_status)
|
||||
|
||||
|
||||
class CreditApiFeatureFlagTest(UrlResetMixin, TestCase):
|
||||
"""
|
||||
Base class to test the credit api urls.
|
||||
"""
|
||||
def setUp(self, **kwargs):
|
||||
enable_credit_api = kwargs.get('enable_credit_api', False)
|
||||
with patch.dict('django.conf.settings.FEATURES', {'ENABLE_CREDIT_API': enable_credit_api}):
|
||||
super(CreditApiFeatureFlagTest, self).setUp('lms.urls')
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
class CreditApiFeatureFlagDisabledTests(CreditApiFeatureFlagTest):
|
||||
"""
|
||||
Test Python API for credit provider api with feature flag
|
||||
'ENABLE_CREDIT_API' disabled.
|
||||
"""
|
||||
PROVIDER_ID = "hogwarts"
|
||||
|
||||
def setUp(self):
|
||||
super(CreditApiFeatureFlagDisabledTests, self).setUp(enable_credit_api=False)
|
||||
|
||||
def test_get_credit_provider_details(self):
|
||||
"""
|
||||
Test that 'get_provider_info' api url not found.
|
||||
"""
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
reverse('credit:get_provider_info', args=[self.PROVIDER_ID])
|
||||
|
||||
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in lms')
|
||||
class CreditApiFeatureFlagEnabledTests(CreditApiFeatureFlagTest, CreditApiTestBase):
|
||||
"""
|
||||
Test Python API for credit provider api with feature flag
|
||||
'ENABLE_CREDIT_API' enabled.
|
||||
"""
|
||||
USER_INFO = {
|
||||
"username": "bob",
|
||||
"email": "bob@example.com",
|
||||
"full_name": "Bob",
|
||||
"mailing_address": "123 Fake Street, Cambridge MA",
|
||||
"country": "US",
|
||||
}
|
||||
|
||||
FINAL_GRADE = 0.95
|
||||
|
||||
def setUp(self):
|
||||
super(CreditApiFeatureFlagEnabledTests, self).setUp(enable_credit_api=True)
|
||||
self.user = UserFactory(
|
||||
username=self.USER_INFO['username'],
|
||||
email=self.USER_INFO['email'],
|
||||
)
|
||||
|
||||
self.user.profile.name = self.USER_INFO['full_name']
|
||||
self.user.profile.mailing_address = self.USER_INFO['mailing_address']
|
||||
self.user.profile.country = self.USER_INFO['country']
|
||||
self.user.profile.save()
|
||||
|
||||
# By default, configure the database so that there is a single
|
||||
# credit requirement that the user has satisfied (minimum grade)
|
||||
self._configure_credit()
|
||||
|
||||
def test_get_credit_provider_details(self):
|
||||
"""Test that credit api method 'test_get_credit_provider_details'
|
||||
returns dictionary data related to provided credit provider.
|
||||
"""
|
||||
expected_result = {
|
||||
"provider_id": self.PROVIDER_ID,
|
||||
"display_name": self.PROVIDER_NAME,
|
||||
"provider_url": self.PROVIDER_URL,
|
||||
"provider_status_url": self.PROVIDER_STATUS_URL,
|
||||
"provider_description": self.PROVIDER_DESCRIPTION,
|
||||
"enable_integration": self.ENABLE_INTEGRATION,
|
||||
"fulfillment_instructions": self.FULFILLMENT_INSTRUCTIONS,
|
||||
}
|
||||
path = reverse('credit:get_provider_info', kwargs={'provider_id': self.PROVIDER_ID})
|
||||
result = self.client.get(path)
|
||||
result = json.loads(result.content)
|
||||
self.assertEqual(result, expected_result)
|
||||
|
||||
# now test that user gets empty dict for non existent credit provider
|
||||
path = reverse('credit:get_provider_info', kwargs={'provider_id': 'fake_provider_id'})
|
||||
result = self.client.get(path)
|
||||
result = json.loads(result.content)
|
||||
self.assertEqual(result, {})
|
||||
|
||||
def _configure_credit(self):
|
||||
"""
|
||||
Configure a credit course and its requirements.
|
||||
|
||||
By default, add a single requirement (minimum grade)
|
||||
that the user has satisfied.
|
||||
|
||||
"""
|
||||
credit_course = self.add_credit_course()
|
||||
requirement = CreditRequirement.objects.create(
|
||||
course=credit_course,
|
||||
namespace="grade",
|
||||
name="grade",
|
||||
active=True
|
||||
)
|
||||
status = CreditRequirementStatus.objects.create(
|
||||
username=self.USER_INFO["username"],
|
||||
requirement=requirement,
|
||||
)
|
||||
status.status = "satisfied"
|
||||
status.reason = {"final_grade": self.FINAL_GRADE}
|
||||
status.save()
|
||||
|
||||
CreditEligibility.objects.create(
|
||||
username=self.USER_INFO['username'],
|
||||
course=CreditCourse.objects.get(course_key=self.course_key)
|
||||
)
|
||||
|
||||
@@ -3,6 +3,7 @@ URLs for the credit app.
|
||||
"""
|
||||
from django.conf.urls import patterns, url
|
||||
|
||||
from .api.provider import get_credit_provider_info
|
||||
from .views import create_credit_request, credit_provider_callback, get_providers_detail, get_eligibility_for_user
|
||||
|
||||
PROVIDER_ID_PATTERN = r'(?P<provider_id>[^/]+)'
|
||||
@@ -10,6 +11,11 @@ PROVIDER_ID_PATTERN = r'(?P<provider_id>[^/]+)'
|
||||
urlpatterns = patterns(
|
||||
'',
|
||||
|
||||
url(
|
||||
r"^v1/providers/(?P<provider_id>[^/]+)/$",
|
||||
get_credit_provider_info,
|
||||
name="get_provider_info"
|
||||
),
|
||||
url(
|
||||
r"^v1/providers/$",
|
||||
get_providers_detail,
|
||||
|
||||
Reference in New Issue
Block a user