It's actually not terribly difficult to set up a course with an enrolled user using UserFactory, CourseFactory, and CourseEnrollmentFactory. That would avoid the need to mock this function and allow you to test for appropriate 404 errors.