How to use a test bucket for MinIO?

1.6k Views Asked by At

I'm writing a Django app, and I use Minio as my object storage. I use this python package.enter link description here I want to create a test bucket for my unit tests. What should I do? In my models.py file, I add a default bucket to save objects; I don't know what I should do for the test request. It is my model:

    class PrivateAttachment(models.Model):   
    file = models.FileField(verbose_name="Object Upload",
                            storage=MinioBackend(bucket_name='django-backend-dev-private'),
                            upload_to=iso_date_prefix)

I really appreciate any help you can provide.

1

There are 1 best solutions below

3
On

Well, if you insist using a backend-layer like django-minio-backend, you should find a way adding a test bucket with that layer, documents say you can have multiple buckets by adding the buckets name to MINIO_PRIVATE_BUCKETS array in settings.py, give it a shot, add a test bucket name there, run your app and the bucket should be created, so you can refer to your test bucket.

MINIO_PRIVATE_BUCKETS = [
    'django-backend-dev-private',
    'my-test-bucket',
]
class PrivateAttachment(models.Model):   
    file = models.FileField(verbose_name="Object Upload",
                            storage=MinioBackend(bucket_name='my-test-bucket'),
                            upload_to=iso_date_prefix)