Add very basic tests

This commit is contained in:
Tobias Kunze 2025-03-23 00:03:04 +01:00
parent 832763cb2a
commit 1424fdf3bb
5 changed files with 137 additions and 3 deletions

41
src/tests/test_views.py Normal file
View file

@ -0,0 +1,41 @@
import pytest
@pytest.mark.parametrize("url,redirect", (
("/", "/accounts/login/?next=/"),
("/accounts/profile/", "/accounts/login/?next=/accounts/profile/")
))
def test_root_view_redirects_valid_urls(client, url, redirect):
response = client.get(url)
assert response.status_code == 302
assert response.url == redirect
def test_root_view_invalid_urls_404(client):
response = client.get("/foobarbaz/")
assert response.status_code == 404
@pytest.mark.django_db
def test_owner_can_access_dashboard(client, org_owner, organization):
client.force_login(org_owner)
response = client.get(organization.urls.base)
assert response.status_code == 200
assert organization.name in response.content.decode()
@pytest.mark.django_db
def test_user_cannot_see_other_organization(client, org_owner, other_organization):
client.force_login(org_owner)
response = client.get(other_organization.urls.base)
assert response.status_code == 403
assert other_organization.name not in response.content.decode()
@pytest.mark.django_db
def test_organization_linked_in_sidebar(client, org_owner, organization, other_organization):
client.force_login(org_owner)
response = client.get("/", follow=True)
assert response.status_code == 200
assert organization.name in response.content.decode()
assert other_organization.name not in response.content.decode()