-
Notifications
You must be signed in to change notification settings - Fork 4
feat(config): add is_patroni_postgresql flag to database configurations #44
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
Merged
Merged
Changes from all commits
Commits
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 hidden or 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 |
|---|---|---|
| @@ -1 +1 @@ | ||
| 6.0.0 | ||
| 6.1.0 |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
116 changes: 116 additions & 0 deletions
116
src/chartreuse/tests/unit_tests/test_patroni_postgresql.py
This file contains hidden or 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,116 @@ | ||
| from pytest_mock import MockerFixture | ||
|
|
||
| from chartreuse.utils.alembic_migration_helper import AlembicMigrationHelper | ||
|
|
||
|
|
||
| class TestPatroniPostgreSQLFeature: | ||
| """Test cases for the is_patroni_postgresql feature.""" | ||
|
|
||
| def test_patroni_postgresql_flag_false_by_default(self, mocker: MockerFixture) -> None: | ||
| """Test that is_patroni_postgresql defaults to False.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| helper = AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| skip_db_checks=True, # Skip database checks for testing | ||
| ) | ||
|
|
||
| assert helper.is_patroni_postgresql is False | ||
|
|
||
| def test_patroni_postgresql_flag_set_to_true(self, mocker: MockerFixture) -> None: | ||
| """Test that is_patroni_postgresql can be set to True.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| helper = AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=True, | ||
| skip_db_checks=True, # Skip database checks for testing | ||
| ) | ||
|
|
||
| assert helper.is_patroni_postgresql is True | ||
|
|
||
| def test_patroni_postgresql_adds_parameter(self, mocker: MockerFixture) -> None: | ||
| """Test that when is_patroni_postgresql=True, it adds the correct parameter.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._wait_postgres_is_configured") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| helper = AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=True, | ||
| additional_parameters="--verbose", | ||
| ) | ||
|
|
||
| # Should have added the patroni_postgresql parameter | ||
| assert " -x patroni_postgresql=yes" in helper.additional_parameters | ||
| assert "--verbose" in helper.additional_parameters | ||
|
|
||
| def test_patroni_postgresql_does_not_add_parameter_when_false(self, mocker: MockerFixture) -> None: | ||
| """Test that when is_patroni_postgresql=False, it doesn't add the parameter.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| helper = AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=False, | ||
| additional_parameters="--verbose", | ||
| ) | ||
|
|
||
| # Should not have added the patroni_postgresql parameter | ||
| assert "patroni_postgresql=yes" not in helper.additional_parameters | ||
| assert "--verbose" in helper.additional_parameters | ||
|
|
||
| def test_patroni_postgresql_calls_wait_postgres_configured(self, mocker: MockerFixture) -> None: | ||
| """Test that when is_patroni_postgresql=True, it calls _wait_postgres_is_configured.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mock_wait = mocker.patch("chartreuse.utils.AlembicMigrationHelper._wait_postgres_is_configured") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=True, | ||
| ) | ||
|
|
||
| mock_wait.assert_called_once() | ||
|
|
||
| def test_patroni_postgresql_does_not_call_wait_postgres_configured_when_false(self, mocker: MockerFixture) -> None: | ||
| """Test that when is_patroni_postgresql=False, it doesn't call _wait_postgres_is_configured.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mock_wait = mocker.patch("chartreuse.utils.AlembicMigrationHelper._wait_postgres_is_configured") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=False, | ||
| ) | ||
|
|
||
| mock_wait.assert_not_called() | ||
|
|
||
| def test_patroni_postgresql_skips_wait_when_skip_db_checks_true(self, mocker: MockerFixture) -> None: | ||
| """Test that when skip_db_checks=True, it doesn't call _wait_postgres_is_configured.""" | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._configure") | ||
| mock_wait = mocker.patch("chartreuse.utils.AlembicMigrationHelper._wait_postgres_is_configured") | ||
| mocker.patch("chartreuse.utils.AlembicMigrationHelper._check_migration_needed", return_value=False) | ||
|
|
||
| AlembicMigrationHelper( | ||
| database_url="postgresql://user:pass@localhost:5432/db", | ||
| alembic_section_name="test", | ||
| is_patroni_postgresql=True, | ||
| skip_db_checks=True, | ||
| ) | ||
|
|
||
| mock_wait.assert_not_called() | ||
|
|
||
| def test_wait_postgres_is_configured_method_exists(self) -> None: | ||
| """Test that the _wait_postgres_is_configured method exists and is callable.""" | ||
| # This is a basic sanity check that the method exists | ||
| assert hasattr(AlembicMigrationHelper, "_wait_postgres_is_configured") | ||
| assert callable(AlembicMigrationHelper._wait_postgres_is_configured) |
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.