Merge pull request #11483 from edx/renzo/programs-task-fixes
Fixes for program certificate generation
This commit is contained in:
@@ -8,3 +8,6 @@ if and only if the service is deployed in the Open edX installation.
|
||||
To ensure maximum separation of concerns, and a minimum of interdependencies,
|
||||
this package should be kept small, thin, and stateless.
|
||||
"""
|
||||
|
||||
# Register signal handlers
|
||||
from . import signals
|
||||
|
||||
@@ -49,7 +49,7 @@ def get_completed_courses(student):
|
||||
"""
|
||||
all_certs = get_certificates_for_user(student.username)
|
||||
return [
|
||||
{'course_id': cert['course_key'], 'mode': cert['type']}
|
||||
{'course_id': unicode(cert['course_key']), 'mode': cert['type']}
|
||||
for cert in all_certs
|
||||
if is_passing_status(cert['status'])
|
||||
]
|
||||
@@ -108,7 +108,11 @@ def award_program_certificate(client, username, program_id):
|
||||
None
|
||||
|
||||
"""
|
||||
client.user_credentials.post({'program_id': program_id, 'username': username})
|
||||
client.user_credentials.post({
|
||||
'username': username,
|
||||
'credential': {'program_id': program_id},
|
||||
'attributes': []
|
||||
})
|
||||
|
||||
|
||||
@task(bind=True, ignore_result=True)
|
||||
|
||||
@@ -109,7 +109,7 @@ class GetCompletedProgramsTestCase(TestCase):
|
||||
{'course_id': 'test-course-2', 'mode': 'prof-ed'},
|
||||
]
|
||||
result = tasks.get_completed_programs(test_client, payload)
|
||||
self.assertEqual(httpretty.last_request().body, json.dumps({'completed_courses': payload}))
|
||||
self.assertEqual(json.loads(httpretty.last_request().body), {'completed_courses': payload})
|
||||
self.assertEqual(result, [1, 2, 3])
|
||||
|
||||
|
||||
@@ -165,12 +165,20 @@ class AwardProgramCertificateTestCase(TestCase):
|
||||
"""
|
||||
test_username = 'test-username'
|
||||
test_client = EdxRestApiClient('http://test-server', jwt='test-token')
|
||||
|
||||
httpretty.register_uri(
|
||||
httpretty.POST,
|
||||
'http://test-server/user_credentials/',
|
||||
)
|
||||
|
||||
tasks.award_program_certificate(test_client, test_username, 123)
|
||||
self.assertEqual(httpretty.last_request().body, json.dumps({'program_id': 123, 'username': test_username}))
|
||||
|
||||
expected_body = {
|
||||
'username': test_username,
|
||||
'credential': {'program_id': 123},
|
||||
'attributes': []
|
||||
}
|
||||
self.assertEqual(json.loads(httpretty.last_request().body), expected_body)
|
||||
|
||||
|
||||
@ddt.ddt
|
||||
|
||||
Reference in New Issue
Block a user