Alex Rothberg
Alex Rothberg

Reputation: 10993

S3BotoStorage and Unit Testing

I am using the storages.backends.s3boto.S3BotoStorage for my DEFAULT_FILE_STORAGE in a Django project.

Ideally I would like to either use the default FileSystemStorage during unit tests or perhaps create a temporary bucket that is deleted on the conclusion of the tests.

What is the best way to accomplish this?

Upvotes: 5

Views: 2502

Answers (2)

kevinharvey
kevinharvey

Reputation: 858

I typically keep a separate settings file for tests, test.py. You can configure the storage backend there, as well as any other settings you want to change during tests. Then, run the tests like this:

python manage.py tests --settings=project.test

The --settings flag is the dotted path the the settings module you want to use (The default would be project.settings).

Good optimizations for a test settings file: https://web.archive.org/web/20180204071529/http://www.daveoncode.com/2013/09/23/effective-tdd-tricks-to-speed-up-django-tests-up-to-10x-faster/

Two Scoops of Django is a good place to read about the multi-settings file setup.

Upvotes: 3

hspandher
hspandher

Reputation: 16733

First of all, use separate file for testing as pointed out above.

Secondly, there is a python library called moto for mocking and testing botos3.

git repository:- https://github.com/spulec/moto

Upvotes: 2

Related Questions