-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
2u/optimizer test happy path #36122
2u/optimizer test happy path #36122
Conversation
|
||
|
||
@shared_task(base=CourseLinkCheckTask, bind=True) | ||
def check_broken_links(self, user_id, course_key_string, language): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this function?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of the decorator, I was not getting anywhere with mocking. It is difficult to test an actual celery task directly.
Then I realized that the decorated function is just there to kick off the task. Often it is cleaner anyway to separate the actual business logic that happens inside the task from it.
Introducing a function that handles the logic (_check_broken_links
) allows me to call that underscored function instead, and makes it easy to test it. I don't need to test the actual task, just what it does.
mock_save_broken_links_file, | ||
mock_scan_course_for_links, | ||
_mock_user_task_status, | ||
mock_user_task_artifact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't these inputs match the mock.patch function names as closely as possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, that's probably cleaner. I think they all match except for mock_write_links
so fixing that now.
See #35887