-
-
Notifications
You must be signed in to change notification settings - Fork 7
feat: add support for minio
#69
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
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ readme = "README.md" | |
| requires-python = ">=3.9" | ||
| version = "0.11.1" | ||
| # | ||
| authors = [{ name = "Cody Fincher", email = "cody[email protected]" }] | ||
| authors = [{ name = "Cody Fincher", email = "cody@litestar.dev" }] | ||
| keywords = [ | ||
| "database", | ||
| "migration", | ||
|
|
@@ -61,27 +61,28 @@ elasticsearch7 = ["elasticsearch7"] | |
| elasticsearch8 = ["elasticsearch8"] | ||
| keydb = ["redis"] | ||
| mariadb = ["mariadb"] | ||
| mssql = ["pymssql<=2.3.1"] | ||
| minio = ["minio"] | ||
| mssql = ["pymssql"] | ||
| mysql = ["mysql-connector-python"] | ||
| oracle = ["oracledb"] | ||
| postgres = ["psycopg>=3"] | ||
| redis = ["redis"] | ||
| spanner = ["google-cloud-spanner"] | ||
|
|
||
|
|
||
| [dependency-groups] | ||
| dev = [ | ||
| # tests | ||
| "bump-my-version", | ||
| "pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,mariadb,oracle,postgres,redis,spanner]", | ||
| "coverage[toml]>=6.2", | ||
| "pytest-databases[azure-storage,bigquery,cockroachdb,dragonfly,elasticsearch7,elasticsearch8,keydb,mssql,mysql,mariadb,oracle,postgres,redis,spanner,minio]", | ||
| "coverage[toml]>=6.2", | ||
| "pytest", | ||
| "pytest-cov", | ||
| "pytest-cdist>=0.2", | ||
| "pytest-mock", | ||
| "pytest-vcr", | ||
| "pytest-click", | ||
| "pytest-xdist", | ||
| "pytest-sugar", | ||
| "slotscheck", | ||
| # lint | ||
| "mypy", | ||
| "ruff", | ||
|
|
@@ -104,7 +105,7 @@ dev = [ | |
| "sphinx-design>=0.5.0", | ||
| "sphinxcontrib-mermaid>=0.9.2", | ||
| "auto-pytabs[sphinx]>=0.4.0", | ||
| "pytest-cdist>=0.2", | ||
|
|
||
| ] | ||
|
|
||
|
|
||
|
|
@@ -116,7 +117,7 @@ dev = [ | |
| allow_dirty = true | ||
| commit = true | ||
| commit_args = "--no-verify" | ||
| current_version = "0.11.0" | ||
| current_version = "0.11.1" | ||
| ignore_missing_files = false | ||
| ignore_missing_version = false | ||
| message = "chore(release): bump to v{new_version}" | ||
|
|
@@ -295,7 +296,7 @@ lint.select = ["ALL"] | |
| lint.dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$" | ||
| preview = true # preview features & checks, use with caution | ||
| src = ["src", "tests/", "docs/"] | ||
| target-version = "py38" | ||
| target-version = "py39" | ||
|
|
||
| [tool.ruff.lint.pydocstyle] | ||
| convention = "google" | ||
|
|
||
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
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,109 @@ | ||
| import os | ||
| from dataclasses import dataclass | ||
| from typing import TYPE_CHECKING | ||
| from urllib.error import URLError | ||
| from urllib.request import Request, urlopen | ||
|
|
||
| import pytest | ||
| from minio.api import Minio | ||
|
|
||
| from pytest_databases.docker import TRUE_VALUES | ||
| from pytest_databases.helpers import get_xdist_worker_num | ||
| from pytest_databases.types import ServiceContainer, XdistIsolationLevel | ||
|
|
||
| if TYPE_CHECKING: | ||
| from collections.abc import Generator | ||
|
|
||
| from pytest_databases._service import DockerService | ||
|
|
||
|
|
||
| DEFAULT_MINIO_ACCESS_KEY = os.getenv("MINIO_ACCESS_KEY", "minio") | ||
| DEFAULT_MINIO_SECRET_KEY = os.getenv("MINIO_SECRET_KEY", "minio123") | ||
| DEFAULT_MINIO_SECURE = os.getenv("MINIO_SECURE", "false").lower() in TRUE_VALUES | ||
|
|
||
|
|
||
| @dataclass | ||
| class MinioService(ServiceContainer): | ||
| endpoint: str | ||
| access_key: str = DEFAULT_MINIO_ACCESS_KEY | ||
| secret_key: str = DEFAULT_MINIO_SECRET_KEY | ||
| secure: bool = DEFAULT_MINIO_SECURE | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def xdist_minio_isolation_level() -> XdistIsolationLevel: | ||
| return "database" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def minio_default_bucket_name(xdist_minio_isolation_level: XdistIsolationLevel) -> str: | ||
| worker_num = get_xdist_worker_num() | ||
| if worker_num is not None and xdist_minio_isolation_level == "server": | ||
| return f"pytest-databases-{worker_num}" | ||
| return "pytest-databases" | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def minio_service( | ||
| docker_service: "DockerService", | ||
| xdist_minio_isolation_level: "XdistIsolationLevel", | ||
| ) -> "Generator[MinioService, None, None]": | ||
| def check(_service: ServiceContainer) -> bool: | ||
| scheme = "https" if DEFAULT_MINIO_SECURE else "http" | ||
| url = f"{scheme}://{_service.host}:{_service.port}/minio/health/ready" | ||
| if not url.startswith(("http:", "https:")): | ||
| msg = "URL must start with 'http:' or 'https:'" | ||
| raise ValueError(msg) | ||
| try: | ||
| with urlopen(url=Request(url, method="GET"), timeout=10) as response: # noqa: S310 | ||
| return response.status == 200 | ||
| except (URLError, ConnectionError): | ||
| return False | ||
|
|
||
| command = "server /data" | ||
| name = "minio" | ||
| access_key = DEFAULT_MINIO_ACCESS_KEY | ||
| secret_key = DEFAULT_MINIO_SECRET_KEY | ||
| env = { | ||
| "MINIO_ROOT_USER": access_key, | ||
| "MINIO_ROOT_PASSWORD": secret_key, | ||
| } | ||
|
|
||
| with docker_service.run( | ||
| image="quay.io/minio/minio", | ||
| name=name, | ||
| command=command, | ||
| container_port=9000, | ||
| timeout=20, | ||
| pause=0.5, | ||
| env=env, | ||
| check=check, | ||
| ) as service: | ||
| yield MinioService( | ||
| host=service.host, | ||
| port=service.port, | ||
| endpoint=f"{service.host}:{service.port}", | ||
| access_key=access_key, | ||
| secret_key=secret_key, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture(scope="session") | ||
| def minio_client( | ||
| minio_service: "MinioService", | ||
| minio_default_bucket_name: str, | ||
| ) -> "Generator[Minio, None, None]": | ||
| client = Minio( | ||
| endpoint=minio_service.endpoint, | ||
| access_key=minio_service.access_key, | ||
| secret_key=minio_service.secret_key, | ||
| secure=False, | ||
| ) | ||
| try: | ||
| if not client.bucket_exists(minio_default_bucket_name): | ||
| client.make_bucket(minio_default_bucket_name) | ||
| except Exception as e: | ||
| msg = f"Failed to create bucket {minio_default_bucket_name}" | ||
| raise RuntimeError(msg) from e | ||
| else: | ||
| yield client | ||
Oops, something went wrong.
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.