Private
Public Access
Scaffold Django project and add first-run auth flow
Sets up the Evection project structure: split settings supporting both SQLite and PostgreSQL via DATABASE_URL, Celery+Redis wiring, and the planned app layout (accounts, feeds, articles, rules, search, reader, pwa, core). Implements multi-user auth with a FreshRSS-style first-run setup wizard, login/logout, and admin-only user management, covered by automated tests. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
986206fe40
commit
c635cd9330
84 files changed
+897
No files matched your search
@@ -0,0 +1,92 @@
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
|
||||
from .middleware import SetupWizardMiddleware
|
||||
from .models import User
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_setup_wizard_cache():
|
||||
SetupWizardMiddleware._a_user_exists = False
|
||||
yield
|
||||
SetupWizardMiddleware._a_user_exists = False
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_root_redirects_to_setup_when_no_users_exist(client):
|
||||
response = client.get("/", follow=False)
|
||||
assert response.status_code == 302
|
||||
assert response.url == reverse("accounts:setup")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_setup_creates_admin_and_logs_in(client):
|
||||
response = client.post(
|
||||
reverse("accounts:setup"),
|
||||
{
|
||||
"username": "keith",
|
||||
"email": "keith@example.com",
|
||||
"password": "correct-horse-battery",
|
||||
"password_confirm": "correct-horse-battery",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert response.url == reverse("reader:stream")
|
||||
|
||||
user = User.objects.get(username="keith")
|
||||
assert user.is_staff
|
||||
assert user.is_superuser
|
||||
|
||||
stream_response = client.get(reverse("reader:stream"))
|
||||
assert stream_response.status_code == 200
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_setup_is_unreachable_once_a_user_exists(client):
|
||||
User.objects.create_user("existing", password="irrelevant")
|
||||
|
||||
response = client.get(reverse("accounts:setup"))
|
||||
assert response.status_code == 302
|
||||
assert response.url == reverse("accounts:login")
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_setup_rejects_mismatched_passwords(client):
|
||||
response = client.post(
|
||||
reverse("accounts:setup"),
|
||||
{
|
||||
"username": "keith",
|
||||
"email": "keith@example.com",
|
||||
"password": "correct-horse-battery",
|
||||
"password_confirm": "does-not-match",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert not User.objects.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_non_admin_cannot_manage_users(client):
|
||||
User.objects.create_user("regular", password="pw-regular-123")
|
||||
client.login(username="regular", password="pw-regular-123")
|
||||
|
||||
response = client.get(reverse("accounts:manage_users"))
|
||||
assert response.status_code == 302 # user_passes_test redirects non-staff
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_admin_can_create_user(client):
|
||||
admin = User.objects.create_user("admin", password="pw-admin-123", is_staff=True)
|
||||
client.login(username="admin", password="pw-admin-123")
|
||||
|
||||
response = client.post(
|
||||
reverse("accounts:create_user"),
|
||||
{
|
||||
"username": "newperson",
|
||||
"email": "newperson@example.com",
|
||||
"password": "pw-newperson-123",
|
||||
},
|
||||
)
|
||||
assert response.status_code == 302
|
||||
assert User.objects.filter(username="newperson").exists()
|
||||
assert admin.pk # sanity: fixture user untouched
|
||||
Reference in new issue
Block a user