diff --git a/tests/factories.py b/tests/factories.py index 3a3728eb..12c266ac 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -99,6 +99,7 @@ class UserStoryAttachmentFactory(Factory): project = factory.SubFactory("tests.factories.ProjectFactory") owner = factory.SubFactory("tests.factories.UserFactory") content_object = factory.SubFactory("tests.factories.UserStoryFactory") + attached_file = factory.django.FileField(data=b"File contents") class Meta: model = "attachments.Attachment" @@ -109,6 +110,7 @@ class TaskAttachmentFactory(Factory): project = factory.SubFactory("tests.factories.ProjectFactory") owner = factory.SubFactory("tests.factories.UserFactory") content_object = factory.SubFactory("tests.factories.TaskFactory") + attached_file = factory.django.FileField(data=b"File contents") class Meta: model = "attachments.Attachment" @@ -119,15 +121,18 @@ class IssueAttachmentFactory(Factory): project = factory.SubFactory("tests.factories.ProjectFactory") owner = factory.SubFactory("tests.factories.UserFactory") content_object = factory.SubFactory("tests.factories.IssueFactory") + attached_file = factory.django.FileField(data=b"File contents") class Meta: model = "attachments.Attachment" strategy = factory.CREATE_STRATEGY + class WikiAttachmentFactory(Factory): project = factory.SubFactory("tests.factories.ProjectFactory") owner = factory.SubFactory("tests.factories.UserFactory") content_object = factory.SubFactory("tests.factories.WikiFactory") + attached_file = factory.django.FileField(data=b"File contents") class Meta: model = "attachments.Attachment" diff --git a/tests/integration/test_attachments.py b/tests/integration/test_attachments.py index 3c498101..2d8cc791 100644 --- a/tests/integration/test_attachments.py +++ b/tests/integration/test_attachments.py @@ -4,73 +4,22 @@ from django.core.urlresolvers import reverse from django.core.files.base import File from django.core.files.uploadedfile import SimpleUploadedFile -from .. import factories as f -from ..utils import set_settings - from taiga.projects.attachments.serializers import AttachmentSerializer +from .. import factories as f pytestmark = pytest.mark.django_db -def test_authentication(client): - "User can't access an attachment if not authenticated" - attachment = f.UserStoryAttachmentFactory.create() - url = reverse("attachment-url", kwargs={"pk": attachment.pk}) - - response = client.get(url) - - assert response.status_code == 401 - - -def test_authorization(client): - "User can't access an attachment if not authorized" - attachment = f.UserStoryAttachmentFactory.create() - user = f.UserFactory.create() - - url = reverse("attachment-url", kwargs={"pk": attachment.pk}) - - client.login(user) - response = client.get(url) - - assert response.status_code == 403 - - -@set_settings(IN_DEVELOPMENT_SERVER=True) -def test_attachment_redirect_in_devserver(client): - "When accessing the attachment in devserver redirect to the real attachment url" - attachment = f.UserStoryAttachmentFactory.create(attached_file="test") - - url = reverse("attachment-url", kwargs={"pk": attachment.pk}) - - client.login(attachment.owner) - response = client.get(url) - - assert response.status_code == 302 - - -@set_settings(IN_DEVELOPMENT_SERVER=False) -def test_attachment_redirect(client): - "When accessing the attachment redirect using X-Accel-Redirect header" - attachment = f.UserStoryAttachmentFactory.create() - - url = reverse("attachment-url", kwargs={"pk": attachment.pk}) - - client.login(attachment.owner) - response = client.get(url) - - assert response.status_code == 200 - assert response.has_header('x-accel-redirect') - - -# Bug test "Don't create attachments without attached_file" def test_create_user_story_attachment_without_file(client): + """ + Bug test "Don't create attachments without attached_file" + """ us = f.UserStoryFactory.create() - attachment = f.UserStoryAttachmentFactory(project=us.project, content_object=us) - - attachment_data = AttachmentSerializer(attachment).data - attachment_data["id"] = None - attachment_data["description"] = "test" - attachment_data["attached_file"] = None + attachment_data = { + "description": "test", + "attached_file": None, + "project": us.project_id, + } url = reverse('userstory-attachments-list')