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

2u/optimizer test happy path #36122

Merged
merged 7 commits into from
Jan 16, 2025

Conversation

jesperhodge
Copy link
Member

See #35887



@shared_task(base=CourseLinkCheckTask, bind=True)
def check_broken_links(self, user_id, course_key_string, language):
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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?

Copy link
Member Author

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.

@jesperhodge jesperhodge merged commit 53ef706 into 2u/course-optimizer Jan 16, 2025
39 of 50 checks passed
@jesperhodge jesperhodge deleted the 2u/optimizer-test-happy-path branch January 16, 2025 23:20
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 this pull request may close these issues.

2 participants