def test_enroll_user_in_course(): user = "******" course_id = "course-v1:edX+DemoX+Demo_Course" course_details = {"course_id": course_id} mode = "audit" cohort = "masters" expected_response = dict(user=user, course_details=course_details, mode=mode, cohort=cohort, is_active=True) responses.add(responses.POST, _url( "enrollment", "enrollment", ), json=expected_response) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.enroll_user_in_course(user, course_id, mode, cohort=cohort) assert actual_response == expected_response request = responses.calls[0][0] assert json.loads(request.body) == expected_response
def test_enrollment_api_client(): expected_response = {"message": "test"} responses.add(responses.GET, _url("enrollment", "test"), json=expected_response) client = lms_api.EnrollmentApiClient('some-user') client.connect() actual_response = client.client.test.get() assert actual_response == expected_response
def test_unenroll_already_unenrolled(): user = "******" course_id = "course-v1:edx+DemoX+Demo_Course" mode = 'audit' expected_response = dict(user=user, course_details={'course_id': course_id}, mode=mode, is_active=False) responses.add(responses.GET, _url( "enrollment", "enrollment/{username},{course_id}".format( username=user, course_id=course_id), ), json=expected_response) expected_response = dict(user=user, is_active=False) responses.add(responses.POST, _url( "enrollment", "enrollment", ), json=expected_response) client = lms_api.EnrollmentApiClient('some-user') unenrolled = client.unenroll_user_from_course(user, course_id) assert not unenrolled
def test_doesnt_have_course_modes(): course_id = "course-v1:edX+DemoX+Demo_Course" response = { "course_modes": [ { 'slug': 'course' }, { 'slug': 'a' }, { 'slug': 'containing' }, { 'slug': 'list' }, { 'slug': 'modes' }, ] } responses.add(responses.GET, _url( "enrollment", "course/{}".format(course_id), ), json=response) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.has_course_mode(course_id, 'course') assert actual_response is False
def test_get_enrollment_course_modes(): course_id = "course-v1:edX+DemoX+Demo_Course" response = { "course_modes": [ {'slug': 'course'}, {'slug': 'a'}, {'slug': 'containing'}, {'slug': 'list'}, {'slug': 'modes'}, ] } expected_return = [ {'slug': 'a'}, {'slug': 'list'}, {'slug': 'containing'}, {'slug': 'modes'}, ] responses.add( responses.GET, _url( "enrollment", "course/{}".format(course_id), ), json=response ) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.get_course_modes(course_id) assert actual_response == expected_return
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_with_exception(): course_id = "course-v1:edX+DemoX+Demo_Course" responses.add(responses.GET, _url( "enrollment", "course/{}".format(course_id), ), status=400) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.get_course_details(course_id) assert actual_response == {}
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('some-user') 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( responses.GET, _url("enrollment", "enrollment") + '?user={}'.format(user), match_querystring=True, json=expected_response, ) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.get_enrolled_courses(user) assert actual_response == expected_response
def test_is_enrolled_false(): 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), ), status=404, ) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.is_enrolled(user, course_id) assert actual_response is False
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('some-user') actual_response = client.get_course_enrollment(user, course_id) assert actual_response is None
def test_get_course_enrollment_invalid(): 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), ), status=404, ) client = lms_api.EnrollmentApiClient() actual_response = client.get_course_enrollment(user, course_id) assert actual_response is None
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('some-user') actual_response = client.get_course_enrollment(user, course_id) assert actual_response == expected_response
def test_is_enrolled_but_not_active(): user = "******" course_id = "course-v1:edX+DemoX+Demo_Course" course_details = {"course_id": course_id} mode = "audit" is_active = False expected_response = dict(user=user, course_details=course_details, mode=mode, is_active=is_active) responses.add( responses.GET, _url( "enrollment", "enrollment/{username},{course_id}".format(username=user, course_id=course_id), ), json=expected_response ) client = lms_api.EnrollmentApiClient('some-user') actual_response = client.is_enrolled(user, course_id) assert actual_response is False