Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
chore: add demo project
Browse files Browse the repository at this point in the history
  • Loading branch information
hartungstenio committed Aug 23, 2024
1 parent 58a908f commit a25d18c
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 62 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
.coverage
dist/
*.sqlite3
24 changes: 24 additions & 0 deletions manage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""

import os
import sys


def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproj.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
msg = (
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
)
raise ImportError(msg) from exc
execute_from_command_line(sys.argv)


if __name__ == "__main__":
main()
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ exclude_lines = [
]

[tool.pytest.ini_options]
DJANGO_SETTINGS_MODULE = "tests.settings"
DJANGO_SETTINGS_MODULE = "testproj.settings"
pythonpath = [".", "src"]

[tool.hatch.build.targets.wheel]
Expand Down
Empty file added testproj/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions testproj/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproj.settings")

application = get_asgi_application()
36 changes: 28 additions & 8 deletions tests/settings.py → testproj/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).absolute()
BASE_DIR = Path(__file__).resolve().parent.parent

SECRET_KEY = "12345healthy67890"
SECRET_KEY = "django-insecure-txy9b_=khny3ax$up%i&)&axs!inx7dy1b0nu26g!q-z$b)f-f" # noqa: S105

DEBUG = True

ALLOWED_HOSTS = []

INSTALLED_APPS = [
"django.contrib.auth",
"django.contrib.contenttypes",
Expand All @@ -30,7 +32,7 @@
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]

ROOT_URLCONF = "tests.urls"
ROOT_URLCONF = "testproj.urls"

TEMPLATES = [
{
Expand All @@ -48,6 +50,8 @@
},
]

WSGI_APPLICATION = "testproj.wsgi.application"

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
Expand All @@ -62,17 +66,32 @@
"dummy": {
"BACKEND": "django.core.cache.backends.dummy.DummyCache",
},
"broken": {
"BACKEND": "tests.cache.BrokenCache",
},
}

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.InMemoryStorage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

AUTH_PASSWORD_VALIDATORS = [
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]


LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
Expand All @@ -83,8 +102,9 @@

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"

# Application health
HEALTH_CHECK_BACKENDS = {
"default_cache": {
"cache": {
"BACKEND": "healthy.backends.CacheHealthBackend",
"OPTIONS": {
"alias": "default",
Expand All @@ -96,7 +116,7 @@
"alias": "default",
},
},
"default_storage": {
"storage": {
"BACKEND": "healthy.backends.StorageBackend",
"OPTIONS": {
"alias": "default",
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions testproj/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import os

from django.core.wsgi import get_wsgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproj.settings")

application = get_wsgi_application()
51 changes: 0 additions & 51 deletions tests/cache.py

This file was deleted.

7 changes: 5 additions & 2 deletions tests/test_backends.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from unittest import mock

import pytest
from django.core.cache import caches
from django.core.files.storage import storages
from django.db import connections

Expand Down Expand Up @@ -103,9 +104,11 @@ async def test_with_working_cache(self):
assert got.status == backends.HealthStatus.UP

async def test_with_broken_cache(self):
backend = backends.CacheHealthBackend("broken")
backend = backends.CacheHealthBackend()
cache = caches[backend.alias]

got = await backend.run_health_check()
with mock.patch.object(cache, "aset", side_effect=RuntimeError):
got = await backend.run_health_check()

assert isinstance(got, backends.Health)
assert got.status == backends.HealthStatus.DOWN
Expand Down

0 comments on commit a25d18c

Please sign in to comment.