pytest-minio-mock


Namepytest-minio-mock JSON
Version 0.4.13 PyPI version JSON
download
home_pagehttps://github.com/oussjarrousse/pytest-minio-mock
SummaryA pytest plugin for mocking Minio S3 interactions
upload_time2024-04-27 12:13:40
maintainerNone
docs_urlNone
authorOussama Jarrousse
requires_python>=3.8
licenseMIT
keywords pytest minio mock
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pytest-minio-mock

### Pip Stats
[![PyPI version](https://badge.fury.io/py/pytest-minio-mock.svg)](https://badge.fury.io/py/pytest-minio-mock)
[![Downloads](https://static.pepy.tech/badge/pytest-minio-mock)](https://pepy.tech/project/pytest-minio-mock)
[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint)

## Overview
`pytest-minio-mock` is a pytest plugin designed to simplify testing of applications that interact with Minio the code  S3 compatible object storage system. It is not designed to test the correnction to the minio server. It provides a fixture that mocks the `minio.Minio` class, allowing for easy testing of Minio interactions without the need for a real Minio server.

The plugin supports python version 3.8 or above.

## Features
- Mock implementation of the `minio.Minio` client.
- Easy to use pytest fixture.
- Supports common Minio operations such as bucket creation, file upload/download, etc.

## Installation

To install `pytest-minio-mock`, run:

```bash
pip install pytest-minio-mock
```

## Usage
To use the minio_mock fixture in your pytest tests, simply include it as a parameter in your test functions. Then use minio.Minio() as usual Here's an example:

```python
def foo():
    try:
        minio_client = minio.Minio(
            endpoint=S3_URI,
            access_key=S3_ACCESS_KEY,
            secret_key=S3_SECRET_KEY,
            region=S3_REGION
        )
        return minio_client.make_bucket("buckets")
    except Exception as e:
        logging.error(e)


def test_file_upload(minio_mock):
    # Calling function foo that involves using minio.Minio()
    assert foo()
    minio_client = minio.Minio(
            endpoint=S3_URI,
            access_key=S3_ACCESS_KEY,
            secret_key=S3_SECRET_KEY,
            region=S3_REGION
        )
    buckets = minio.list_buckets()
    assert len(buckets)==1

```

The `minio_mock` fixture will patch newly created minio.Minio() thus providing you with a way to test your code around the Minio client easily.

At the moment, instances of minio.Minio() created before loading the minio_mock fixture code will not be patched. This might be an issue if one or more of the fixtures you are using in your tests that preceeds `minio_mock` in the parameters list of the test function, initiates instances of minio.Minio() that you want to test. As a workaround make sure that minio_mock is the first fixture in the list of arguments of function where minio_mock is needed. Example:

```python
@pytest.fixture()
def system_under_test(minio_mock: MockMinioClient, storage_provider_stub: StorageProvider):
    # your code here
    pass
```

## API

### MockMinioClient

A brief description of the mocked methods and their behavior, like:

- `make_bucket(bucket_name, ...)` # Mocks bucket creation.
- `fput_object(bucket_name, object_name, file_path, ...)` # Mocks file upload.
- ...

## Contributing
Contributions to pytest-minio-mock are welcome!

Follow the usual path:
 - fork the repository
 - create a feature branch
 - push the branch to your forked repository
 - from the forked repository, create a "pull request" to this project.

When creating a pull request make sure to use the following template:

```
Change Summary
 - item one
 - item two
Related issue number
 - issue a
 - issue b
Checklist
  [ ] code is ready
  [ ] add tests
  [ ] all tests passing
  [ ] test coverage did not drop
  [ ] PR is ready for review
```

After a pull request has been submitted:
- A reviewer must review the pull-request
- the pull requests must pass all tests for all supported python versions 3.8, 3.9, 3.10, 3.11 and 3.12.
- A maintainer will eventually merges the pull request
- A release manager will upload it to pypi.

## License
pytest-minio-mock is licensed under the MIT License - see the LICENSE file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/oussjarrousse/pytest-minio-mock",
    "name": "pytest-minio-mock",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "pytest minio mock",
    "author": "Oussama Jarrousse",
    "author_email": "oussama@jarrousse.org",
    "download_url": "https://files.pythonhosted.org/packages/91/4f/493e76710987632f20c12eb1c9115175946c5bc826117a51a9a5ebd519ca/pytest_minio_mock-0.4.13.tar.gz",
    "platform": "any",
    "description": "# pytest-minio-mock\n\n### Pip Stats\n[![PyPI version](https://badge.fury.io/py/pytest-minio-mock.svg)](https://badge.fury.io/py/pytest-minio-mock)\n[![Downloads](https://static.pepy.tech/badge/pytest-minio-mock)](https://pepy.tech/project/pytest-minio-mock)\n[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/pylint-dev/pylint)\n\n## Overview\n`pytest-minio-mock` is a pytest plugin designed to simplify testing of applications that interact with Minio the code  S3 compatible object storage system. It is not designed to test the correnction to the minio server. It provides a fixture that mocks the `minio.Minio` class, allowing for easy testing of Minio interactions without the need for a real Minio server.\n\nThe plugin supports python version 3.8 or above.\n\n## Features\n- Mock implementation of the `minio.Minio` client.\n- Easy to use pytest fixture.\n- Supports common Minio operations such as bucket creation, file upload/download, etc.\n\n## Installation\n\nTo install `pytest-minio-mock`, run:\n\n```bash\npip install pytest-minio-mock\n```\n\n## Usage\nTo use the minio_mock fixture in your pytest tests, simply include it as a parameter in your test functions. Then use minio.Minio() as usual Here's an example:\n\n```python\ndef foo():\n    try:\n        minio_client = minio.Minio(\n            endpoint=S3_URI,\n            access_key=S3_ACCESS_KEY,\n            secret_key=S3_SECRET_KEY,\n            region=S3_REGION\n        )\n        return minio_client.make_bucket(\"buckets\")\n    except Exception as e:\n        logging.error(e)\n\n\ndef test_file_upload(minio_mock):\n    # Calling function foo that involves using minio.Minio()\n    assert foo()\n    minio_client = minio.Minio(\n            endpoint=S3_URI,\n            access_key=S3_ACCESS_KEY,\n            secret_key=S3_SECRET_KEY,\n            region=S3_REGION\n        )\n    buckets = minio.list_buckets()\n    assert len(buckets)==1\n\n```\n\nThe `minio_mock` fixture will patch newly created minio.Minio() thus providing you with a way to test your code around the Minio client easily.\n\nAt the moment, instances of minio.Minio() created before loading the minio_mock fixture code will not be patched. This might be an issue if one or more of the fixtures you are using in your tests that preceeds `minio_mock` in the parameters list of the test function, initiates instances of minio.Minio() that you want to test. As a workaround make sure that minio_mock is the first fixture in the list of arguments of function where minio_mock is needed. Example:\n\n```python\n@pytest.fixture()\ndef system_under_test(minio_mock: MockMinioClient, storage_provider_stub: StorageProvider):\n    # your code here\n    pass\n```\n\n## API\n\n### MockMinioClient\n\nA brief description of the mocked methods and their behavior, like:\n\n- `make_bucket(bucket_name, ...)` # Mocks bucket creation.\n- `fput_object(bucket_name, object_name, file_path, ...)` # Mocks file upload.\n- ...\n\n## Contributing\nContributions to pytest-minio-mock are welcome!\n\nFollow the usual path:\n - fork the repository\n - create a feature branch\n - push the branch to your forked repository\n - from the forked repository, create a \"pull request\" to this project.\n\nWhen creating a pull request make sure to use the following template:\n\n```\nChange Summary\n - item one\n - item two\nRelated issue number\n - issue a\n - issue b\nChecklist\n  [ ] code is ready\n  [ ] add tests\n  [ ] all tests passing\n  [ ] test coverage did not drop\n  [ ] PR is ready for review\n```\n\nAfter a pull request has been submitted:\n- A reviewer must review the pull-request\n- the pull requests must pass all tests for all supported python versions 3.8, 3.9, 3.10, 3.11 and 3.12.\n- A maintainer will eventually merges the pull request\n- A release manager will upload it to pypi.\n\n## License\npytest-minio-mock is licensed under the MIT License - see the LICENSE file for details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A pytest plugin for mocking Minio S3 interactions",
    "version": "0.4.13",
    "project_urls": {
        "Homepage": "https://github.com/oussjarrousse/pytest-minio-mock",
        "Source": "https://github.com/oussjarrousse/pytest-minio-mock/",
        "Tracker": "https://github.com/oussjarrousse/pytest-minio-mock/issues"
    },
    "split_keywords": [
        "pytest",
        "minio",
        "mock"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c4b261cf997a18fa5c09ceb389e16118759842b9106b4d484e03bd819240deeb",
                "md5": "bc1b5830a9444a58f87949cd494aa9b8",
                "sha256": "fa8777a376310efee4403a8cb34bb58936276693f9dc221c4fc1173b6f55344d"
            },
            "downloads": -1,
            "filename": "pytest_minio_mock-0.4.13-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "bc1b5830a9444a58f87949cd494aa9b8",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 13639,
            "upload_time": "2024-04-27T12:13:37",
            "upload_time_iso_8601": "2024-04-27T12:13:37.305862Z",
            "url": "https://files.pythonhosted.org/packages/c4/b2/61cf997a18fa5c09ceb389e16118759842b9106b4d484e03bd819240deeb/pytest_minio_mock-0.4.13-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "914f493e76710987632f20c12eb1c9115175946c5bc826117a51a9a5ebd519ca",
                "md5": "d5c83ea145874e3030462e70d4ed0ffe",
                "sha256": "852634355c6ef59c5e00951bc6c09c73af98ac86ffabe3d7e311b55ebc5690d9"
            },
            "downloads": -1,
            "filename": "pytest_minio_mock-0.4.13.tar.gz",
            "has_sig": false,
            "md5_digest": "d5c83ea145874e3030462e70d4ed0ffe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 17256,
            "upload_time": "2024-04-27T12:13:40",
            "upload_time_iso_8601": "2024-04-27T12:13:40.917702Z",
            "url": "https://files.pythonhosted.org/packages/91/4f/493e76710987632f20c12eb1c9115175946c5bc826117a51a9a5ebd519ca/pytest_minio_mock-0.4.13.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-27 12:13:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "oussjarrousse",
    "github_project": "pytest-minio-mock",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "tox": true,
    "lcname": "pytest-minio-mock"
}
        
Elapsed time: 0.25885s