-
Notifications
You must be signed in to change notification settings - Fork 20
test: add unit tests for process_submissions helpers #1607
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
test: add unit tests for process_submissions helpers #1607
Conversation
c012639 to
826632b
Compare
gustavobtflores
left a comment
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.
Looks great overall, just some minor comments
| @patch("kernelCI_app.management.commands.helpers.process_submissions.logger") | ||
| @patch( | ||
| "kernelCI_app.management.commands.helpers.process_submissions.make_issue_instance" | ||
| ) | ||
| def test_insert_items_with_errors(self, mock_make_issue, mock_logger): | ||
| items = [{"id": "issue", "version": 1, "origin": "test"}] | ||
|
|
||
| mock_make_issue.side_effect = ValidationError.from_exception_data( | ||
| "TestModel", [] | ||
| ) | ||
| result = insert_items("issues", items) | ||
| self.assertEqual(result, 0) | ||
| self.assertEqual(mock_logger.error.call_count, 1) | ||
|
|
||
| mock_make_issue.reset_mock() | ||
| mock_logger.reset_mock() | ||
|
|
||
| mock_issue = MagicMock() | ||
| mock_issue.save = MagicMock(side_effect=IntegrityError("Duplicate key")) | ||
| mock_make_issue.return_value = mock_issue | ||
| result = insert_items("issues", items) | ||
| self.assertEqual(result, 0) | ||
| self.assertEqual(mock_logger.error.call_count, 1) |
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.
could we separate this test in two different cases?
1 - ValidationError
2 - IntegrityError
| class TestInsertItems(SimpleTestCase): | ||
| @patch("kernelCI_app.management.commands.helpers.process_submissions.logger") | ||
| @patch( | ||
| "kernelCI_app.management.commands.helpers.process_submissions.make_issue_instance" | ||
| ) |
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.
we could add a test case with an empty items list in this class, just in case
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.
Thanks, applied both comments. Can you check pls?
826632b to
9028eea
Compare
gustavobtflores
left a comment
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.
LGTM, thanks for the work!
Could you please just rebase the branch with main? I will merge it then
9028eea to
b2cc252
Compare
|
Just rebased @gustavobtflores |
Related issue:
Description
Add test coverage for the helpers functions on
process_submissions.py