Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unenrollment capability #60

Closed
gsidebo opened this issue Jun 26, 2019 · 1 comment · Fixed by #61
Closed

Add unenrollment capability #60

gsidebo opened this issue Jun 26, 2019 · 1 comment · Fixed by #61
Assignees
Milestone

Comments

@gsidebo
Copy link
Contributor

gsidebo commented Jun 26, 2019

We would like to use the API client to unenroll a user from a course in edX

@gsidebo
Copy link
Contributor Author

gsidebo commented Jun 26, 2019

During some local testing a while back, I ended up using the un-enrollment endpoint directly via HTTP. Here is a snippet of that code:

### Enroll via HTTP API
usernames = ['honor', 'audit', 'staff']
pw = 'edx'
course_id_str = 'course-v1:MIT+gsidebo000+2017_Summer'
enroll_url = '/change_enrollment'
#
from django.contrib.auth.models import User
from django.test.client import Client
def set_enrollment(course_id_str, usernames, pw, enroll=True):
  client = Client()
  enroll_url = '/change_enrollment'
  for username in usernames:
    login_resp = client.post(
              '/user_api/v1/account/login_session/',
              data={
                  "email": "{}@example.com".format(username),
                  "password": pw,
                  "remember": "false"
              },
              headers={
                  'Referer': '/login',
              },
    )
    enrollment_action = 'enroll' if enroll else 'unenroll'
    resp = client.post(enroll_url, data={'course_id': course_id_str, 'enrollment_action': enrollment_action})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants