fix question edit permissions
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
|
||||
from django.urls import reverse
|
||||
import pytest
|
||||
|
||||
from longs.models import Long
|
||||
|
||||
|
||||
def create_question():
|
||||
return Long.objects.create(
|
||||
description="Test Question",
|
||||
)
|
||||
|
||||
def create_user(db, django_user_model):
|
||||
return django_user_model.objects.create_user(
|
||||
"user1", "user1@user.com", "password"
|
||||
)
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_question_creation(client, db, django_user_model):
|
||||
question = create_question()
|
||||
assert question.description == "Test Question"
|
||||
assert question.get_absolute_url() == f"/longs/question/{question.pk}/"
|
||||
|
||||
# Test access
|
||||
user = create_user(db, django_user_model)
|
||||
client.force_login(user)
|
||||
|
||||
# View access
|
||||
response = client.get(reverse("longs:question_detail", kwargs={"pk": question.pk}), follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
response = client.get(reverse("longs:long_update", kwargs={"pk": question.pk}), follow=True)
|
||||
assert response.status_code == 403
|
||||
|
||||
|
||||
# Add author
|
||||
question.add_author(user)
|
||||
|
||||
# Test author access
|
||||
response = client.get(reverse("longs:question_detail", kwargs={"pk": question.pk}), follow=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
response = client.get(reverse("longs:long_update", kwargs={"pk": question.pk}), follow=True)
|
||||
assert response.status_code == 200
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -506,7 +506,7 @@ class LongCreate(LongCreateBase):
|
||||
|
||||
|
||||
class LongUpdate(
|
||||
UpdateQuestionMixin,AuthorOrCheckerRequiredMixin
|
||||
UpdateQuestionMixin
|
||||
):
|
||||
model = Long
|
||||
form_class = LongForm
|
||||
|
||||
Reference in New Issue
Block a user