|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +dj-rest-auth is a Django REST Framework package providing authentication API endpoints (login, logout, registration, password reset/change, JWT auth). It integrates with django-allauth for social auth and registration. |
| 8 | + |
| 9 | +## Common Commands |
| 10 | + |
| 11 | +### Running Tests |
| 12 | +```bash |
| 13 | +# All tests |
| 14 | +python runtests.py |
| 15 | + |
| 16 | +# Single test |
| 17 | +DJANGO_SETTINGS_MODULE=dj_rest_auth.tests.settings python -m django test dj_rest_auth.tests.test_api.APIBasicTests.test_login |
| 18 | + |
| 19 | +# With coverage |
| 20 | +coverage run ./runtests.py && coverage report |
| 21 | +``` |
| 22 | + |
| 23 | +### Linting |
| 24 | +```bash |
| 25 | +flake8 dj_rest_auth/ |
| 26 | +``` |
| 27 | + |
| 28 | +### Tox (full CI matrix: Python 3.8-3.12, Django 4.2/5.0) |
| 29 | +```bash |
| 30 | +tox # all envs |
| 31 | +tox -e flake8 # lint only |
| 32 | +tox -e coverage # coverage only |
| 33 | +``` |
| 34 | + |
| 35 | +### Install Test Dependencies |
| 36 | +```bash |
| 37 | +pip install -r dj_rest_auth/tests/requirements.txt |
| 38 | +``` |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +### Core Package (`dj_rest_auth/`) |
| 43 | + |
| 44 | +- **`app_settings.py`** — Central configuration via `REST_AUTH` Django setting dict. All serializers and the token model are specified as dotted import strings, making everything overridable without subclassing. Access settings via the `api_settings` singleton. |
| 45 | +- **`views.py`** — `LoginView`, `LogoutView`, `UserDetailsView`, `PasswordResetView`, `PasswordResetConfirmView`, `PasswordChangeView`. All views use `throttle_scope = 'dj_rest_auth'`. |
| 46 | +- **`serializers.py`** — Core serializers for all auth operations. |
| 47 | +- **`jwt_auth.py`** — `JWTCookieAuthentication` (subclasses simplejwt's `JWTAuthentication`), cookie helpers, refresh view factory. Only active when `USE_JWT=True`. |
| 48 | +- **`urls.py`** — Uses `re_path` with trailing `/?` to make slashes optional. JWT endpoints conditionally registered. |
| 49 | +- **`models.py`** — No custom models; resolves and re-exports the configured Token model via `get_token_model()`. |
| 50 | + |
| 51 | +### Registration Sub-package (`dj_rest_auth/registration/`) |
| 52 | + |
| 53 | +Requires django-allauth. Provides `RegisterView`, `VerifyEmailView`, social login/connect views, and corresponding serializers. |
| 54 | + |
| 55 | +### Key Design Patterns |
| 56 | + |
| 57 | +- **Conditional allauth integration**: Checks `'allauth' in settings.INSTALLED_APPS` at runtime to branch between allauth and plain Django auth. |
| 58 | +- **Settings-as-import-strings**: Serializers, token model, and token creator are all configurable via dotted path strings in `REST_AUTH`. |
| 59 | +- **Custom validation hooks**: `custom_validation()` methods on password serializers for subclass extension. |
| 60 | +- **i18n**: All user-facing strings use `gettext_lazy`. |
| 61 | + |
| 62 | +### Testing (`dj_rest_auth/tests/`) |
| 63 | + |
| 64 | +- **`settings.py`** — Test Django settings (SQLite in-memory, allauth configured). |
| 65 | +- **`mixins.py`** — `TestsMixin` with HTTP helpers and status assertions; custom `APIClient`. |
| 66 | +- **`utils.py`** — `override_api_settings` context manager for temporarily changing `REST_AUTH` values in tests. |
| 67 | +- Test files: `test_api.py`, `test_serializers.py`, `test_social.py`, `test_utils.py`. |
| 68 | + |
| 69 | +## Code Style |
| 70 | + |
| 71 | +- flake8 with max line length 120 (configured in `setup.cfg`) |
| 72 | +- `F403` (star imports) ignored globally |
0 commit comments