-
Notifications
You must be signed in to change notification settings - Fork 78
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
HJ-131 Delete monitors before deleting integration #5478
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
db0a8eb
Delete monitors before deleting integration
erosselli c3defd1
Fix typing and add test
erosselli a50cd8d
Static checks and changelog entry
erosselli a7befa0
Remove back_populates attribute so monitor creation doesn't break
erosselli c4246ef
Fix fixtures
erosselli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
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
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,62 @@ | ||
from typing import Generator | ||
|
||
import pytest | ||
from sqlalchemy.orm import Session | ||
from sqlalchemy.orm.exc import ObjectDeletedError | ||
|
||
from fides.api.models.connectionconfig import ConnectionConfig | ||
from fides.api.models.detection_discovery import MonitorConfig | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def monitor_config( | ||
db: Session, connection_config: ConnectionConfig | ||
) -> Generator[MonitorConfig, None, None]: | ||
mc = MonitorConfig.create( | ||
db=db, | ||
data={ | ||
"name": "test monitor config 1", | ||
"key": "test_monitor_config_1", | ||
"connection_config_id": connection_config.id, | ||
"classify_params": { | ||
"num_samples": 25, | ||
"num_threads": 2, | ||
}, | ||
"databases": ["db1", "db2"], | ||
"execution_frequency": None, | ||
"execution_start_date": None, | ||
}, | ||
) | ||
yield mc | ||
try: | ||
db.delete(mc) | ||
except ObjectDeletedError: | ||
# Object was already deleted, do nothing | ||
return | ||
|
||
|
||
@pytest.fixture(scope="function") | ||
def monitor_config_2( | ||
db: Session, connection_config: ConnectionConfig | ||
) -> Generator[MonitorConfig, None, None]: | ||
mc = MonitorConfig.create( | ||
db=db, | ||
data={ | ||
"name": "test monitor config 2", | ||
"key": "test_monitor_config_2", | ||
"connection_config_id": connection_config.id, | ||
"classify_params": { | ||
"num_samples": 20, | ||
"num_threads": 2, | ||
}, | ||
"databases": ["db1", "db3"], | ||
"execution_frequency": None, | ||
"execution_start_date": None, | ||
}, | ||
) | ||
yield mc | ||
try: | ||
db.delete(mc) | ||
except ObjectDeletedError: | ||
# Object was already deleted, do nothing | ||
return |
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 |
---|---|---|
|
@@ -190,34 +190,14 @@ def test_staged_resource_helpers(self, db: Session, create_staged_resource): | |
|
||
|
||
class TestMonitorConfigModel: | ||
@pytest.fixture | ||
def create_monitor_config(self, db: Session, connection_config: ConnectionConfig): | ||
Comment on lines
-193
to
-194
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. moved this fixture to the new |
||
mc = MonitorConfig.create( | ||
db=db, | ||
data={ | ||
"name": "test monitor config 1", | ||
"key": "test_monitor_config_1", | ||
"connection_config_id": connection_config.id, | ||
"classify_params": { | ||
"num_samples": 25, | ||
"num_threads": 2, | ||
}, | ||
"databases": ["db1", "db2"], | ||
"execution_frequency": None, | ||
"execution_start_date": None, | ||
}, | ||
) | ||
yield mc | ||
db.delete(mc) | ||
|
||
def test_create_monitor_config( | ||
self, db: Session, create_monitor_config, connection_config: ConnectionConfig | ||
self, db: Session, monitor_config, connection_config: ConnectionConfig | ||
) -> None: | ||
""" | ||
Creation fixture creates the config, this tests that it was created successfully | ||
and that we can access its attributes as expected. | ||
""" | ||
mc: MonitorConfig = MonitorConfig.get(db=db, object_id=create_monitor_config.id) | ||
mc: MonitorConfig = MonitorConfig.get(db=db, object_id=monitor_config.id) | ||
assert mc.name == "test monitor config 1" | ||
assert mc.key == "test_monitor_config_1" | ||
assert mc.classify_params == { | ||
|
@@ -237,11 +217,11 @@ def test_create_monitor_config( | |
assert mc.excluded_databases == [] | ||
|
||
def test_update_monitor_config_fails_with_conflicting_dbs( | ||
self, db: Session, create_monitor_config, connection_config: ConnectionConfig | ||
self, db: Session, monitor_config, connection_config: ConnectionConfig | ||
) -> None: | ||
""" """ | ||
with pytest.raises(ValueError): | ||
create_monitor_config.update( | ||
monitor_config.update( | ||
db=db, | ||
data={ | ||
"name": "updated test monitor config 1", | ||
|
@@ -388,12 +368,12 @@ def test_update_monitor_config_execution_trigger_logic( | |
self, | ||
db: Session, | ||
connection_config: ConnectionConfig, | ||
create_monitor_config: MonitorConfig, | ||
monitor_config: MonitorConfig, | ||
monitor_frequency, | ||
expected_dict, | ||
): | ||
"""Tests that execution_trigger logic works as expected during within `update`""" | ||
create_monitor_config.update( | ||
monitor_config.update( | ||
db=db, | ||
data={ | ||
"name": "updated test monitor config 1", | ||
|
@@ -407,7 +387,7 @@ def test_update_monitor_config_execution_trigger_logic( | |
"execution_frequency": monitor_frequency, | ||
}, | ||
) | ||
mc: MonitorConfig = MonitorConfig.get(db=db, object_id=create_monitor_config.id) | ||
mc: MonitorConfig = MonitorConfig.get(db=db, object_id=monitor_config.id) | ||
|
||
# first ensure update works as expected on a "normal" field | ||
assert mc.name == "updated test monitor config 1" | ||
|
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.
this is so mypy doesn't complain about not recognizing the
MonitorConfig
model. Theif TYPE_CHECKING
is needed to avoid a circular import