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

course_optimizer_provider tests #36033

Merged
merged 9 commits into from
Jan 17, 2025
Merged

Conversation

rayzhou-bit
Copy link
Contributor

@rayzhou-bit rayzhou-bit commented Dec 16, 2024

Unit tests for return the Data Transfer Object for course optimizer from backend to frontend.

@rayzhou-bit rayzhou-bit marked this pull request as draft December 16, 2024 18:18
@rayzhou-bit rayzhou-bit changed the title 2u/optimizer tests course_optimizer_provider tests Jan 15, 2025
@rayzhou-bit rayzhou-bit marked this pull request as ready for review January 15, 2025 19:32
Copy link
Member

@jesperhodge jesperhodge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you clarify what these tests are testing? Ideally test names should describe expected behavior and act as a kind of documentation for the code. I actually don't understand the code itself in-depth yet and having tests that describe expected behavior in their name will make that clear.

If you want you can use AI and give it the code under test and the linked naming convention file (https://github.com/openedx/frontend-lib-content-components/blob/main/docs/decisions/0006-test-names.rst) and then ask it to generate pytest names (only) for the most important cases and edge cases. That will also show you if you missed a test. (Of course AI makes mistakes but I find it still very helpful with this).

If you look at some of the test names Bernie wrote, you can see how good they are. test_number_of_scanned_blocks_equals_blocks_in_course tells you exactly what is expected.

MOCK_BLOCK.get_parent.return_value = MOCK_UNIT


def test_update_node_tree_and_dictionary(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also the convention we use for pytest is that the function docstring describes quite clearly what the unit under test is supposed to do and what we are testing.

self.assertEqual(expected_dictionary, result_dictionary)


def test_get_node_path(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See naming comment above

@rayzhou-bit rayzhou-bit merged commit 85c14da into 2u/course-optimizer Jan 17, 2025
40 of 50 checks passed
@rayzhou-bit rayzhou-bit deleted the 2u/optimizer-tests branch January 17, 2025 17:10
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