Skip to content

Commit

Permalink
Add owns_thread test
Browse files Browse the repository at this point in the history
  • Loading branch information
pamella committed Jun 13, 2024
1 parent 323e236 commit bbea938
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/test_permissions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.contrib.auth.models import User

import pytest

from django_ai_assistant.models import Thread
from django_ai_assistant.permissions import owns_thread


@pytest.fixture()
def superuser(db):
return User.objects.create_superuser(username="superuser", password="password")


@pytest.fixture()
def regular_user(db):
return User.objects.create_user(username="regular", password="password")


@pytest.mark.django_db()
def test_owns_thread(superuser, regular_user):
thread = Thread.objects.create(name="AAA")
assert owns_thread(superuser, thread)
assert not owns_thread(regular_user, thread)

thread = Thread.objects.create(name="CCC", created_by=superuser)
assert owns_thread(superuser, thread)
assert not owns_thread(regular_user, thread)

thread = Thread.objects.create(name="BBB", created_by=regular_user)
assert owns_thread(superuser, thread)
assert owns_thread(regular_user, thread)

0 comments on commit bbea938

Please sign in to comment.