'Utility method to possibly create and possibly enroll a user.
Creates a state matching the SettableEnrollmentState properties.
Returns a tuple of (
email,
User, (optionally None)
CourseEnrollment, (optionally None)
CourseEnrollmentAllowed, (optionally None)'

def create_user(self, course_id=None):

    email = 'robot_no_user_exists_with_this_email@edx.org'
    if self.user:
        user = UserFactory()
        email = user.email
        if self.enrollment:
            cenr = CourseEnrollment.enroll(user, course_id)
            return EnrollmentObjects(email, user, cenr, None)
        else:
            return EnrollmentObjects(email, user, None, None)
    elif self.allowed:
        cea = CourseEnrollmentAllowed.objects.create(email=email, course_id=course_id, auto_enroll=self.auto_enroll)
        return EnrollmentObjects(email, None, None, cea)
    else:
        return EnrollmentObjects(email, None, None, None)
