Metadata-Version: 2.1
Name: pytest-minio-mock
Version: 0.1.8
Summary: A pytest plugin for mocking Minio S3 interactions
Home-page: https://github.com/oussjarrousse/pytest-minio-mock
Author: Oussama Jarrousse
Author-email: oussama@jarrousse.org
License: MIT
Project-URL: Source, https://github.com/oussjarrousse/pytest-minio-mock/
Project-URL: Tracker, https://github.com/oussjarrousse/pytest-minio-mock/issues
Keywords: pytest minio mock
Platform: any
Classifier: Framework :: Pytest
Classifier: Programming Language :: Python :: 3
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Topic :: Software Development :: Testing
Requires-Python: >=3.6
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: pytest >=5.0.0
Requires-Dist: minio
Requires-Dist: pytest-mock
Requires-Dist: validators
Provides-Extra: dev
Requires-Dist: pre-commit ; extra == 'dev'
Requires-Dist: tox ; extra == 'dev'

# pytest-minio-mock

## 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.

## 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
        )
        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()

```

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:

```
@pytest.fixture()
def system_under_test(minio_mock: MockMinioClient, storage_provider_stub: StorageProvider):
```

## 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! The Contributing Guide is still under construction.

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
```

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