def test_enrollment_api_client(): expected_response = {"message": "test"} responses.add(responses.GET, _url("enrollment", "test"), json=expected_response) client = lms_api.EnrollmentApiClient() actual_response = client.client.test.get() assert actual_response == expected_response request = responses.calls[0][0] assert request.headers['X-Edx-Api-Key'] == settings.EDX_API_KEY
def test_get_enrollment_course_details(): course_id = "course-v1:edX+DemoX+Demo_Course" expected_response = {"course_id": course_id} responses.add(responses.GET, _url( "enrollment", "course/{}".format(course_id), ), json=expected_response) client = lms_api.EnrollmentApiClient() actual_response = client.get_course_details(course_id) assert actual_response == expected_response
def test_get_enrolled_courses(): user = "******" course_id = "course-v1:edx+DemoX+Demo_Course" expected_response = [{"course_details": {"course_id": course_id}}] responses.add( # pylint: disable=no-member responses.GET, # pylint: disable=no-member _url("enrollment", "enrollment") + '?user={}'.format(user), match_querystring=True, json=expected_response, ) client = lms_api.EnrollmentApiClient() actual_response = client.get_enrolled_courses(user) assert actual_response == expected_response
def test_get_course_enrollment_not_found(): user = "******" course_id = "course-v1:edX+DemoX+Demo_Course" responses.add( responses.GET, _url( "enrollment", "enrollment/{username},{course_id}".format(username=user, course_id=course_id), ), body='', ) client = lms_api.EnrollmentApiClient() actual_response = client.get_course_enrollment(user, course_id) assert actual_response is None
def test_get_enrollment_course_modes(): course_id = "course-v1:edX+DemoX+Demo_Course" response = {"course_modes": ['a', 'list', 'containing', 'course', 'modes']} expected_return = ['a', 'list', 'containing', 'course', 'modes'] responses.add( responses.GET, _url( "enrollment", "course/{}".format(course_id), ), json=response ) client = lms_api.EnrollmentApiClient() actual_response = client.get_course_modes(course_id) assert actual_response == expected_return
def test_get_course_enrollment(): user = "******" course_id = "course-v1:edX+DemoX+Demo_Course" course_details = {"course_id": course_id} mode = "audit" expected_response = dict(user=user, course_details=course_details, mode=mode) responses.add( responses.GET, _url( "enrollment", "enrollment/{username},{course_id}".format(username=user, course_id=course_id), ), json=expected_response ) client = lms_api.EnrollmentApiClient() actual_response = client.get_course_enrollment(user, course_id) assert actual_response == expected_response
def test_enroll_user_in_course(): user = "******" course_id = "course-v1:edX+DemoX+Demo_Course" course_details = {"course_id": course_id} mode = "audit" expected_response = dict(user=user, course_details=course_details, mode=mode) responses.add( responses.POST, _url( "enrollment", "enrollment", ), json=expected_response ) client = lms_api.EnrollmentApiClient() actual_response = client.enroll_user_in_course(user, course_id, mode) assert actual_response == expected_response request = responses.calls[0][0] assert json.loads(request.body) == expected_response