feat: Django project skeleton with pytest setup
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
11
.env.example
Normal file
11
.env.example
Normal file
@@ -0,0 +1,11 @@
|
||||
# Django
|
||||
DJANGO_SECRET_KEY=CHANGE_ME
|
||||
DJANGO_PORT=8000
|
||||
DJANGO_ALLOWED_HOSTS=*
|
||||
|
||||
# Database (NAS)
|
||||
DB_HOST=192.168.x.x
|
||||
DB_PORT=5432
|
||||
DB_NAME=openclaw_archive
|
||||
DB_USER=openclaw
|
||||
DB_PASSWORD=CHANGE_ME
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*.so
|
||||
*.egg-info/
|
||||
dist/
|
||||
.venv/
|
||||
env/
|
||||
*.sqlite3
|
||||
20
manage.py
Normal file
20
manage.py
Normal file
@@ -0,0 +1,20 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||
try:
|
||||
from django.core.management import execute_from_command_line
|
||||
except ImportError as exc:
|
||||
raise ImportError(
|
||||
"Couldn't import Django. "
|
||||
"Are you sure it's installed and available on your PYTHONPATH "
|
||||
"environment variable is set? Did you forget to activate a virtual environment?"
|
||||
) from exc
|
||||
execute_from_command_line(sys.argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
4
pyproject.toml
Normal file
4
pyproject.toml
Normal file
@@ -0,0 +1,4 @@
|
||||
[tool.pytest.ini_options]
|
||||
DJANGO_SETTINGS_MODULE = "config.settings.dev"
|
||||
python_files = ["tests.py", "test_*.py"]
|
||||
pythonpath = ["src"]
|
||||
3
requirements-dev.txt
Normal file
3
requirements-dev.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
-r requirements.txt
|
||||
pytest>=8.0,<9.0
|
||||
pytest-django>=4.8,<5.0
|
||||
4
requirements.txt
Normal file
4
requirements.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
Django>=5.0,<6.0
|
||||
djangorestframework>=3.15,<4.0
|
||||
psycopg[binary]>=3.1,<4.0
|
||||
gunicorn>=22.0,<24.0
|
||||
0
src/config/__init__.py
Normal file
0
src/config/__init__.py
Normal file
1
src/config/settings/__init__.py
Normal file
1
src/config/settings/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from .base import * # noqa: F401,F403
|
||||
58
src/config/settings/base.py
Normal file
58
src/config/settings/base.py
Normal file
@@ -0,0 +1,58 @@
|
||||
import os
|
||||
|
||||
SECRET_KEY = os.environ.get("DJANGO_SECRET_KEY", "dev-secret-key")
|
||||
DEBUG = False
|
||||
ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS", "*").split(",")
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.admin",
|
||||
"django.contrib.auth",
|
||||
"django.contrib.contenttypes",
|
||||
"django.contrib.sessions",
|
||||
"django.contrib.messages",
|
||||
"django.contrib.staticfiles",
|
||||
"rest_framework",
|
||||
"openclaw",
|
||||
]
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
ROOT_URLCONF = "config.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.request",
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
],
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.postgresql",
|
||||
"HOST": os.environ.get("DB_HOST", "localhost"),
|
||||
"PORT": os.environ.get("DB_PORT", "5432"),
|
||||
"NAME": os.environ.get("DB_NAME", "openclaw_archive"),
|
||||
"USER": os.environ.get("DB_USER", "openclaw"),
|
||||
"PASSWORD": os.environ.get("DB_PASSWORD", ""),
|
||||
}
|
||||
}
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
|
||||
STATIC_URL = "static/"
|
||||
13
src/config/settings/dev.py
Normal file
13
src/config/settings/dev.py
Normal file
@@ -0,0 +1,13 @@
|
||||
from pathlib import Path
|
||||
|
||||
BASE_DIR = Path(__file__).resolve(strict=True).parent.parent.parent.parent
|
||||
|
||||
from .base import * # noqa: F401,F403
|
||||
|
||||
DEBUG = True
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": BASE_DIR / "db.sqlite3", # noqa: F821
|
||||
}
|
||||
}
|
||||
7
src/config/urls.py
Normal file
7
src/config/urls.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
urlpatterns = [
|
||||
path("admin/", admin.site.urls),
|
||||
path("api/", include("openclaw.urls")),
|
||||
]
|
||||
5
src/config/wsgi.py
Normal file
5
src/config/wsgi.py
Normal file
@@ -0,0 +1,5 @@
|
||||
import os
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings")
|
||||
application = get_wsgi_application()
|
||||
0
src/openclaw/__init__.py
Normal file
0
src/openclaw/__init__.py
Normal file
6
src/openclaw/apps.py
Normal file
6
src/openclaw/apps.py
Normal file
@@ -0,0 +1,6 @@
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class OpenclawConfig(AppConfig):
|
||||
default_auto_field = "django.db.models.BigAutoField"
|
||||
name = "openclaw"
|
||||
3
src/openclaw/urls.py
Normal file
3
src/openclaw/urls.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from django.urls import path
|
||||
|
||||
urlpatterns = []
|
||||
6
tests/conftest.py
Normal file
6
tests/conftest.py
Normal file
@@ -0,0 +1,6 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def media_storage(settings, tmpdir):
|
||||
settings.MEDIA_ROOT = str(tmpdir)
|
||||
Reference in New Issue
Block a user