-
-
Notifications
You must be signed in to change notification settings - Fork 214
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
Catch exception in case of missing ds table #34595
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
ef45dc4
Catch exception in case of missing ds table
Charl1996 6296975
Check for table during error handling
Charl1996 7974e0b
Remove redundant else
Charl1996 495c64c
Add some tests for bulk_delete
Charl1996 b0b0ffb
Try to not use drop_table in tests
Charl1996 e6884b2
update test type to allow DB queries
mkangia File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
from django.test import TestCase | ||
from unittest.mock import patch | ||
|
||
from corehq.apps.userreports.sql.adapter import IndicatorSqlAdapter | ||
from corehq.apps.userreports.models import DataSourceConfiguration | ||
from corehq.apps.userreports.app_manager.helpers import clean_table_name | ||
|
||
|
||
class TestIndicatorSqlAdapter(TestCase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mkangia Oh my goodness! Thank you! |
||
|
||
@staticmethod | ||
def _create_data_source_config(domain): | ||
indicator = { | ||
"type": "expression", | ||
"expression": { | ||
"type": "property_name", | ||
"property_name": 'name' | ||
}, | ||
"column_id": 'name', | ||
"display_name": 'name', | ||
"datatype": "string" | ||
} | ||
return DataSourceConfiguration( | ||
domain=domain, | ||
display_name='foo', | ||
referenced_doc_type='CommCareCase', | ||
table_id=clean_table_name('domain', 'test-table'), | ||
configured_indicators=[indicator], | ||
) | ||
|
||
@patch("corehq.apps.userreports.sql.adapter.register_data_source_row_change") | ||
def test_bulk_delete_table_dont_exist(self, register_data_source_row_change_mock): | ||
config = self._create_data_source_config("test-domain") | ||
adapter = IndicatorSqlAdapter(config) | ||
|
||
docs = [{'_id': '1'}] | ||
self.assertFalse(adapter.table_exists) | ||
|
||
adapter.bulk_delete(docs) | ||
register_data_source_row_change_mock.assert_not_called() | ||
|
||
@patch("corehq.apps.userreports.sql.adapter.register_data_source_row_change") | ||
def test_bulk_delete_table_exists(self, register_data_source_row_change_mock): | ||
config = self._create_data_source_config("test-domain2") | ||
adapter = IndicatorSqlAdapter(config) | ||
|
||
docs = [{'_id': '1'}] | ||
adapter.build_table() | ||
self.assertTrue(adapter.table_exists) | ||
|
||
adapter.bulk_delete(docs) | ||
register_data_source_row_change_mock.assert_called() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not really worth the hassle of changing, but maybe just interesting to know about: You can use
raise
to raise the last exception, and so you don't need a variable for it in this situation.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.
Good point. I forgot about that 👍