3

https://docs.min.io/docs/python-client-api-reference.html

I have some implementation like below

class Minio:
    def initialize(self):
        # Create client with access key and secret key with specific region.
        self.client = Minio(
            "play.minio.io:9000",
            access_key="access-key",
            secret_key="secret-key",
            region="my-region",
        )

    def upload_to_minio(self):
        ## code to upload file into minio
        result = self.client.fput_object(
            "my-bucket", "my-object", "my-filename",
        )
        print(
            "created {0} object; etag: {1}, version-id: {2}".format(
                result.object_name, result.etag, result.version_id,
            ),
        )

    def download_from_minio(self):
        ## code to download file from minio
        self.client.fget_object(
            "my-bucket", "my-object", "my-filename",
            version_id="dfbd25b3-abec-4184-a4e8-5a35a5c1174d",
        )

I want to write unit test using pytest for the above class.

Is there any package available to mock minio buckets and behaviours?

Or should we write a class for mock connection and validate the upload and download.

Can someone help on this ?

srinath
  • 2,748
  • 6
  • 35
  • 56
  • create your own mock objects to mock `Minio`? – gold_cy May 26 '21 at 18:03
  • Any link you can point to .. i am new to pytest – srinath May 27 '21 at 04:35
  • https://pypi.org/project/pytest-mock/ https://realpython.com/python-mock-library/ – dosas May 27 '21 at 06:14
  • Have you considered using "boto3"? if you could switch to using "boto3" then you could use "moto" for mocking. Otherwise if you found a way to mock "minio" for pytest I would also be interested. – Ouss Jul 11 '23 at 16:06

0 Answers0