'Create a test user for a course.'

def create_user_for_course(self, course, user_type=CourseUserType.ENROLLED):

    if (user_type is CourseUserType.ANONYMOUS):
        return AnonymousUser()
    is_enrolled = (user_type is CourseUserType.ENROLLED)
    is_unenrolled_staff = (user_type is CourseUserType.UNENROLLED_STAFF)
    if is_unenrolled_staff:
        user = StaffFactory(course_key=course.id, password=self.TEST_PASSWORD)
    else:
        user = UserFactory(password=self.TEST_PASSWORD)
    self.client.login(username=user.username, password=self.TEST_PASSWORD)
    if is_enrolled:
        CourseEnrollment.enroll(user, course.id)
    return user
