-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Refactor redshift fixture to be "first class".
Previously, redshift just directly used postgres' underlying `_postgres_container` fixture. This means that you cannot simultaneously use postgres AND redshift on different postgres database servers (version/port would be common examples of things you might want to customize). Now, a separate `_redshift_container` and `RedshiftConfig` have been added. By default they use the same values as the default postgres one; which means that by default there will be no behavior change. A redshift and postgres fixture, used together, will end up making use of the same database server. However this change **enables** these configurations to diverge for a project and use different config. Additionally, postgres has had a lot more active development of its fixture features. Redshift, using the postgres container, *can* make use of all of this development, but had a completely unique implementation, and so it did not.
- Loading branch information
Showing
14 changed files
with
217 additions
and
101 deletions.
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
# flake8: noqa | ||
from pytest_mock_resources.container.mongo import _mongo_container, MongoConfig | ||
from pytest_mock_resources.container.mysql import _mysql_container, MysqlConfig | ||
from pytest_mock_resources.container.postgres import _postgres_container, PostgresConfig | ||
from pytest_mock_resources.container.postgres import PostgresConfig | ||
from pytest_mock_resources.container.redis import _redis_container, RedisConfig | ||
from pytest_mock_resources.container.redshift import _redshift_container |
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 |
---|---|---|
@@ -1,6 +1,60 @@ | ||
import pytest | ||
import sqlalchemy | ||
|
||
from pytest_mock_resources.config import DockerContainerConfig, fallback | ||
from pytest_mock_resources.container.base import ContainerCheckFailed | ||
from pytest_mock_resources.container.postgres import get_sqlalchemy_engine | ||
|
||
@pytest.fixture(scope="session") | ||
def _redshift_container(_postgres_container): | ||
return _postgres_container | ||
|
||
class RedshiftConfig(DockerContainerConfig): | ||
"""Define the configuration object for Redshift. | ||
Args: | ||
image (str): The docker image:tag specifier to use for Redshift containers. | ||
Defaults to :code:`"postgres:9.6.10-alpine"`. | ||
host (str): The hostname under which a mounted port will be available. | ||
Defaults to :code:`"localhost"`. | ||
port (int): The port to bind the container to. | ||
Defaults to :code:`5532`. | ||
ci_port (int): The port to bind the container to when a CI environment is detected. | ||
Defaults to :code:`5432`. | ||
username (str): The username of the root Redshift user | ||
Defaults to :code:`"user"`. | ||
password (str): The password of the root Redshift password | ||
Defaults to :code:`"password"`. | ||
root_database (str): The name of the root Redshift database to create. | ||
Defaults to :code:`"dev"`. | ||
""" | ||
|
||
name = "redshift" | ||
_fields = {"image", "host", "port", "ci_port", "username", "password", "root_database"} | ||
_fields_defaults = { | ||
"image": "postgres:9.6.10-alpine", | ||
"port": 5532, | ||
"ci_port": 5432, | ||
"username": "user", | ||
"password": "password", | ||
"root_database": "dev", | ||
} | ||
|
||
@fallback | ||
def username(self): | ||
raise NotImplementedError() | ||
|
||
@fallback | ||
def password(self): | ||
raise NotImplementedError() | ||
|
||
@fallback | ||
def root_database(self): | ||
raise NotImplementedError() | ||
|
||
|
||
def check_redshift_fn(config): | ||
try: | ||
get_sqlalchemy_engine(config, config.root_database) | ||
except sqlalchemy.exc.OperationalError: | ||
raise ContainerCheckFailed( | ||
"Unable to connect to a presumed Redshift test container via given config: {}".format( | ||
config | ||
) | ||
) |
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
Oops, something went wrong.