Limited grades to seven characters
ECOM-2433
This commit is contained in:
committed by
Clinton Blackburn
parent
772b0bff31
commit
8f1ff11b47
@@ -242,13 +242,20 @@ def create_credit_request(course_key, provider_id, username):
|
||||
|
||||
# Retrieve the final grade from the eligibility table
|
||||
try:
|
||||
final_grade = unicode(CreditRequirementStatus.objects.get(
|
||||
final_grade = CreditRequirementStatus.objects.get(
|
||||
username=username,
|
||||
requirement__namespace="grade",
|
||||
requirement__name="grade",
|
||||
requirement__course__course_key=course_key,
|
||||
status="satisfied"
|
||||
).reason["final_grade"])
|
||||
).reason["final_grade"]
|
||||
|
||||
# NOTE (CCB): Limiting the grade to seven characters is a hack for ASU.
|
||||
if len(unicode(final_grade)) > 7:
|
||||
final_grade = u'{:.5f}'.format(final_grade)
|
||||
else:
|
||||
final_grade = unicode(final_grade)
|
||||
|
||||
except (CreditRequirementStatus.DoesNotExist, TypeError, KeyError):
|
||||
log.exception(
|
||||
"Could not retrieve final grade from the credit eligibility table "
|
||||
|
||||
@@ -2,21 +2,21 @@
|
||||
Tests for the API functions in the credit app.
|
||||
"""
|
||||
import datetime
|
||||
import ddt
|
||||
import json
|
||||
from mock import patch
|
||||
import pytz
|
||||
import unittest
|
||||
|
||||
import ddt
|
||||
from django.conf import settings
|
||||
from django.core import mail
|
||||
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 unittest import skipUnless
|
||||
|
||||
from mock import patch
|
||||
from opaque_keys.edx.keys import CourseKey
|
||||
import pytz
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
from util.date_utils import from_timestamp
|
||||
from openedx.core.djangoapps.credit import api
|
||||
@@ -36,9 +36,6 @@ from openedx.core.djangoapps.credit.models import (
|
||||
CreditEligibility
|
||||
)
|
||||
from student.tests.factories import UserFactory
|
||||
from xmodule.modulestore.tests.django_utils import ModuleStoreTestCase
|
||||
from xmodule.modulestore.tests.factories import CourseFactory
|
||||
|
||||
|
||||
TEST_CREDIT_PROVIDER_SECRET_KEY = "931433d583c84ca7ba41784bad3232e6"
|
||||
|
||||
@@ -95,7 +92,7 @@ class CreditApiTestBase(ModuleStoreTestCase):
|
||||
return credit_course
|
||||
|
||||
|
||||
@skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS')
|
||||
@unittest.skipUnless(settings.ROOT_URLCONF == 'lms.urls', 'Test only valid in LMS')
|
||||
@ddt.ddt
|
||||
class CreditRequirementApiTests(CreditApiTestBase):
|
||||
"""
|
||||
@@ -432,7 +429,7 @@ class CreditRequirementApiTests(CreditApiTestBase):
|
||||
self.assertEqual(mail.outbox[0].subject, 'Course Credit Eligibility')
|
||||
|
||||
# Now verify them email content
|
||||
email_payload_first = mail.outbox[0].attachments[0]._payload # pylint: disable=protected-access
|
||||
email_payload_first = mail.outbox[0].attachments[0]._payload # pylint: disable=protected-access
|
||||
|
||||
# Test that email has two payloads [multipart (plain text and html
|
||||
# content), attached image]
|
||||
@@ -446,7 +443,7 @@ class CreditRequirementApiTests(CreditApiTestBase):
|
||||
# Now check that html email content has same logo image 'Content-ID'
|
||||
# as the attached logo image 'Content-ID'
|
||||
email_image = email_payload_first[1]
|
||||
html_content_first = email_payload_first[0]._payload[1]._payload # pylint: disable=protected-access
|
||||
html_content_first = email_payload_first[0]._payload[1]._payload # pylint: disable=protected-access
|
||||
|
||||
# strip enclosing angle brackets from 'logo_image' cache 'Content-ID'
|
||||
image_id = email_image.get('Content-ID', '')[1:-1]
|
||||
@@ -468,8 +465,8 @@ class CreditRequirementApiTests(CreditApiTestBase):
|
||||
self.assertEqual(len(mail.outbox), 2)
|
||||
# Now check that on sending eligibility notification again cached
|
||||
# logo image is used
|
||||
email_payload_second = mail.outbox[1].attachments[0]._payload # pylint: disable=protected-access
|
||||
html_content_second = email_payload_second[0]._payload[1]._payload # pylint: disable=protected-access
|
||||
email_payload_second = mail.outbox[1].attachments[0]._payload # pylint: disable=protected-access
|
||||
html_content_second = email_payload_second[0]._payload[1]._payload # pylint: disable=protected-access
|
||||
self.assertIn(image_id, html_content_second)
|
||||
|
||||
# The user should remain eligible even if the requirement status is later changed
|
||||
@@ -644,6 +641,21 @@ class CreditProviderIntegrationApiTests(CreditApiTestBase):
|
||||
self.assertIn(param_key, parameters)
|
||||
self.assertEqual(parameters[param_key], self.USER_INFO[key])
|
||||
|
||||
def test_create_credit_request_grade_length(self):
|
||||
""" Verify the length of the final grade is limited to seven (7) characters total.
|
||||
|
||||
This is a hack for ASU.
|
||||
"""
|
||||
# Update the user's grade
|
||||
status = CreditRequirementStatus.objects.get(username=self.USER_INFO["username"])
|
||||
status.status = "satisfied"
|
||||
status.reason = {"final_grade": 1.0 / 3.0}
|
||||
status.save()
|
||||
|
||||
# Initiate a credit request
|
||||
request = api.create_credit_request(self.course_key, self.PROVIDER_ID, self.USER_INFO['username'])
|
||||
self.assertEqual(request['parameters']['final_grade'], u'0.33333')
|
||||
|
||||
def test_credit_request_disable_integration(self):
|
||||
CreditProvider.objects.all().update(enable_integration=False)
|
||||
|
||||
@@ -842,6 +854,7 @@ 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}):
|
||||
|
||||
Reference in New Issue
Block a user