Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Configuration of Test Folder Path #421

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,14 @@ The backend will return a JSON response:
}
```

## Settings overrides

You can provide `settings.HEALTH_CHECK_TEST_FOLDER` to alter the default storage behavior. It is helpful if your user doesn't have permissions to create a folder within the current dir.

```python
HEALTH_CHECK_TEST_FOLDER = '/tmp'
```

## Writing a custom health check

Writing a health check is quick and easy:
Expand Down
14 changes: 13 additions & 1 deletion health_check/storage/backends.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import uuid

import django
Expand Down Expand Up @@ -43,7 +44,18 @@ def get_storage(self):
return self.storage

def get_file_name(self):
return "health_check_storage_test/test-%s.txt" % uuid.uuid4()
"""
Generate a unique filename for a test file within the specified folder.

If the `HEALTH_CHECK_TEST_FOLDER` setting is defined, the generated filename will be within that folder.
Otherwise, it will be within a folder named 'health_check_storage_test' in the current directory.

Returns:
str: A string representing the path to the generated test file.
"""
path = settings.HEALTH_CHECK_TEST_FOLDER or 'health_check_storage_test'
filename = f'test-{uuid.uuid4()}.txt'
return os.path.join(path, filename)

def get_file_content(self):
return b"this is the healthtest file content"
Expand Down