Merge pull request #65 from taigaio/bug/attachments

Attachments related bugfixes
remotes/origin/enhancement/email-actions
David Barragán Merino 2014-09-06 13:12:39 +02:00
commit b712d73bdd
28 changed files with 314 additions and 243 deletions

View File

@ -14,8 +14,6 @@
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from django.db.models import Q
# Patch api view for correctly return 401 responses on
# request is authenticated instead of 403
from . import monkey

View File

@ -18,9 +18,14 @@ import json
from rest_framework.utils import encoders
def to_json(data, ensure_ascii=True, encoder_class=encoders.JSONEncoder):
def dumps(data, ensure_ascii=True, encoder_class=encoders.JSONEncoder):
return json.dumps(data, cls=encoder_class, indent=None, ensure_ascii=ensure_ascii)
def from_json(data):
def loads(data):
return json.loads(data)
# Some backward compatibility that should
# be removed in near future.
to_json = dumps
from_json = loads

View File

@ -34,7 +34,6 @@ from taiga.users.models import User
from taiga.projects.notifications import WatchedResourceMixin
from taiga.projects.history import HistoryResourceMixin
from . import permissions
from . import serializers
from . import models
@ -47,6 +46,12 @@ class BaseAttachmentViewSet(HistoryResourceMixin, WatchedResourceMixin, ModelCru
content_type = None
def update(self, *args, **kwargs):
partial = kwargs.get("partial", False)
if not partial:
raise exc.NotSupported("Non partial updates not supported")
return super().update(*args, **kwargs)
def get_content_type(self):
app_name, model = self.content_type.split(".", 1)
return get_object_or_404(ContentType, app_label=app_name, model=model)
@ -56,6 +61,9 @@ class BaseAttachmentViewSet(HistoryResourceMixin, WatchedResourceMixin, ModelCru
obj.content_type = self.get_content_type()
obj.owner = self.request.user
if obj.project_id != obj.content_object.project_id:
raise exc.WrongArguments("Project ID not matches between object and project")
super().pre_save(obj)
def post_delete(self, obj):
@ -72,36 +80,24 @@ class UserStoryAttachmentViewSet(BaseAttachmentViewSet):
permission_classes = (permissions.UserStoryAttachmentPermission,)
filter_backends = (filters.CanViewUserStoryAttachmentFilterBackend,)
content_type = "userstories.userstory"
create_notification_template = "create_userstory_notification"
update_notification_template = "update_userstory_notification"
destroy_notification_template = "destroy_userstory_notification"
class IssueAttachmentViewSet(BaseAttachmentViewSet):
permission_classes = (permissions.IssueAttachmentPermission,)
filter_backends = (filters.CanViewIssueAttachmentFilterBackend,)
content_type = "issues.issue"
create_notification_template = "create_issue_notification"
update_notification_template = "update_issue_notification"
destroy_notification_template = "destroy_issue_notification"
class TaskAttachmentViewSet(BaseAttachmentViewSet):
permission_classes = (permissions.TaskAttachmentPermission,)
filter_backends = (filters.CanViewTaskAttachmentFilterBackend,)
content_type = "tasks.task"
create_notification_template = "create_task_notification"
update_notification_template = "update_task_notification"
destroy_notification_template = "destroy_task_notification"
class WikiAttachmentViewSet(BaseAttachmentViewSet):
permission_classes = (permissions.WikiAttachmentPermission,)
filter_backends = (filters.CanViewWikiAttachmentFilterBackend,)
content_type = "wiki.wikipage"
create_notification_template = "create_wiki_notification"
update_notification_template = "update_wiki_notification"
destroy_notification_template = "destroy_wiki_notification"
class RawAttachmentView(generics.RetrieveAPIView):

View File

@ -16,7 +16,7 @@
from taiga.base.api.permissions import (TaigaResourcePermission, HasProjectPerm,
IsProjectOwner, AllowAny, PermissionComponent)
AllowAny, PermissionComponent)
class IsAttachmentOwnerPerm(PermissionComponent):

View File

@ -21,7 +21,9 @@ from django.conf import settings
from rest_framework import serializers
from taiga.base.serializers import ModelSerializer
from taiga.base.utils.urls import reverse
from . import models
@ -30,6 +32,8 @@ class AttachmentSerializer(serializers.ModelSerializer):
url = serializers.SerializerMethodField("get_url")
size = serializers.SerializerMethodField("get_size")
attached_file = serializers.FileField(required=True)
class Meta:
model = models.Attachment
fields = ("id", "project", "owner", "name", "attached_file", "size", "url",

View File

@ -16,6 +16,8 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import pytest
import mock
import functools
class Object:
@ -27,11 +29,36 @@ def object():
return Object()
class PartialMethodCaller:
def __init__(self, obj, **partial_params):
self.obj = obj
self.partial_params = partial_params
def __getattr__(self, name):
return functools.partial(getattr(self.obj, name), **self.partial_params)
@pytest.fixture
def client():
from testclient_extensions import Client
from django.test.client import Client
from django.test.client import MULTIPART_CONTENT
return Client()
class _Client(Client):
def login(self, user=None, backend="django.contrib.auth.backends.ModelBackend", **credentials):
if user is None:
return super().login(**credentials)
# This will be changed on django1.7 branch with other location
with mock.patch('django.test.client.authenticate') as authenticate:
user.backend = backend
authenticate.return_value = user
return super().login(**credentials)
@property
def json(self):
return PartialMethodCaller(obj=self, content_type='application/json;charset="utf-8"')
return _Client()
@pytest.fixture

View File

@ -1,16 +1,19 @@
import pytest
from django.core.urlresolvers import reverse
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test.client import MULTIPART_CONTENT
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from taiga.projects.attachments.serializers import AttachmentSerializer
from tests import factories as f
from tests.utils import helper_test_http_method, helper_test_http_method_and_count, disconnect_signals, reconnect_signals
import json
from tests.utils import helper_test_http_method
from tests.utils import helper_test_http_method_and_count
from tests.utils import disconnect_signals
from tests.utils import reconnect_signals
import pytest
pytestmark = pytest.mark.django_db
@ -72,11 +75,14 @@ def data():
def data_us(data):
m = type("Models", (object,), {})
m.public_user_story = f.UserStoryFactory(project=data.public_project, ref=1)
m.public_user_story_attachment = f.UserStoryAttachmentFactory(project=data.public_project, content_object=m.public_user_story)
m.public_user_story_attachment = f.UserStoryAttachmentFactory(project=data.public_project,
content_object=m.public_user_story)
m.private_user_story1 = f.UserStoryFactory(project=data.private_project1, ref=5)
m.private_user_story1_attachment = f.UserStoryAttachmentFactory(project=data.private_project1, content_object=m.private_user_story1)
m.private_user_story1_attachment = f.UserStoryAttachmentFactory(project=data.private_project1,
content_object=m.private_user_story1)
m.private_user_story2 = f.UserStoryFactory(project=data.private_project2, ref=9)
m.private_user_story2_attachment = f.UserStoryAttachmentFactory(project=data.private_project2, content_object=m.private_user_story2)
m.private_user_story2_attachment = f.UserStoryAttachmentFactory(project=data.private_project2,
content_object=m.private_user_story2)
return m
@pytest.fixture
@ -197,9 +203,12 @@ def test_wiki_attachment_retrieve(client, data, data_wiki):
def test_user_story_attachment_update(client, data, data_us):
public_url = reverse('userstory-attachments-detail', kwargs={"pk": data_us.public_user_story_attachment.pk})
private_url1 = reverse('userstory-attachments-detail', kwargs={"pk": data_us.private_user_story1_attachment.pk})
private_url2 = reverse('userstory-attachments-detail', kwargs={"pk": data_us.private_user_story2_attachment.pk})
public_url = reverse("userstory-attachments-detail",
args=[data_us.public_user_story_attachment.pk])
private_url1 = reverse("userstory-attachments-detail",
args=[data_us.private_user_story1_attachment.pk])
private_url2 = reverse("userstory-attachments-detail",
args=[data_us.private_user_story2_attachment.pk])
users = [
None,
@ -211,14 +220,20 @@ def test_user_story_attachment_update(client, data, data_us):
attachment_data = AttachmentSerializer(data_us.public_user_story_attachment).data
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
results = helper_test_http_method(client, 'put', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url1, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url2, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, "put", public_url, attachment_data, users)
# assert results == [401, 403, 403, 400, 400]
assert results == [405, 405, 405, 405, 405]
results = helper_test_http_method(client, "put", private_url1, attachment_data, users)
# assert results == [401, 403, 403, 400, 400]
assert results == [405, 405, 405, 405, 405]
results = helper_test_http_method(client, "put", private_url2, attachment_data, users)
# assert results == [401, 403, 403, 400, 400]
assert results == [405, 405, 405, 405, 405]
def test_task_attachment_update(client, data, data_task):
@ -236,14 +251,17 @@ def test_task_attachment_update(client, data, data_task):
attachment_data = AttachmentSerializer(data_task.public_task_attachment).data
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'put', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url1, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url2, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
def test_issue_attachment_update(client, data, data_issue):
@ -261,14 +279,17 @@ def test_issue_attachment_update(client, data, data_issue):
attachment_data = AttachmentSerializer(data_issue.public_issue_attachment).data
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'put', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url1, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
results = helper_test_http_method(client, 'put', private_url2, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
def test_wiki_attachment_update(client, data, data_wiki):
@ -286,14 +307,17 @@ def test_wiki_attachment_update(client, data, data_wiki):
attachment_data = AttachmentSerializer(data_wiki.public_wiki_attachment).data
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'put', public_url, attachment_data, users)
assert results == [401, 200, 200, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 200, 200, 200, 200]
results = helper_test_http_method(client, 'put', private_url1, attachment_data, users)
assert results == [401, 200, 200, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 200, 200, 200, 200]
results = helper_test_http_method(client, 'put', private_url2, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
assert results == [405, 405, 405, 405, 405]
# assert results == [401, 403, 403, 200, 200]
def test_user_story_attachment_patch(client, data, data_us):
@ -310,7 +334,7 @@ def test_user_story_attachment_patch(client, data, data_us):
]
attachment_data = {"description": "test"}
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'patch', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
@ -334,7 +358,7 @@ def test_task_attachment_patch(client, data, data_task):
]
attachment_data = {"description": "test"}
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'patch', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
@ -358,7 +382,7 @@ def test_issue_attachment_patch(client, data, data_issue):
]
attachment_data = {"description": "test"}
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'patch', public_url, attachment_data, users)
assert results == [401, 403, 403, 200, 200]
@ -382,7 +406,7 @@ def test_wiki_attachment_patch(client, data, data_wiki):
]
attachment_data = {"description": "test"}
attachment_data = JSONRenderer().render(attachment_data)
attachment_data = json.dumps(attachment_data)
results = helper_test_http_method(client, 'patch', public_url, attachment_data, users)
assert results == [401, 200, 200, 200, 200]
@ -482,11 +506,16 @@ def test_user_story_attachment_create(client, data, data_us):
data.project_owner
]
attachment_data = AttachmentSerializer(data_us.public_user_story_attachment).data
attachment_data["id"] = None
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
results = helper_test_http_method(client, 'post', url, attachment_data, users)
attachment_data = {"description": "test",
"object_id": data_us.public_user_story_attachment.object_id,
"project": data_us.public_user_story_attachment.project_id,
"attached_file": SimpleUploadedFile("test.txt", b"test")}
_after_each_request_hook = lambda: attachment_data["attached_file"].seek(0)
results = helper_test_http_method(client, 'post', url, attachment_data, users,
content_type=MULTIPART_CONTENT,
after_each_request=_after_each_request_hook)
assert results == [401, 403, 403, 201, 201]
@ -501,11 +530,16 @@ def test_task_attachment_create(client, data, data_task):
data.project_owner
]
attachment_data = AttachmentSerializer(data_task.public_task_attachment).data
attachment_data["id"] = None
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
results = helper_test_http_method(client, 'post', url, attachment_data, users)
attachment_data = {"description": "test",
"object_id": data_task.public_task_attachment.object_id,
"project": data_task.public_task_attachment.project_id,
"attached_file": SimpleUploadedFile("test.txt", b"test")}
_after_each_request_hook = lambda: attachment_data["attached_file"].seek(0)
results = helper_test_http_method(client, 'post', url, attachment_data, users,
content_type=MULTIPART_CONTENT,
after_each_request=_after_each_request_hook)
assert results == [401, 403, 403, 201, 201]
@ -520,11 +554,17 @@ def test_issue_attachment_create(client, data, data_issue):
data.project_owner
]
attachment_data = AttachmentSerializer(data_issue.public_issue_attachment).data
attachment_data["id"] = None
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
results = helper_test_http_method(client, 'post', url, attachment_data, users)
attachment_data = {"description": "test",
"object_id": data_issue.public_issue_attachment.object_id,
"project": data_issue.public_issue_attachment.project_id,
"attached_file": SimpleUploadedFile("test.txt", b"test")}
_after_each_request_hook = lambda: attachment_data["attached_file"].seek(0)
results = helper_test_http_method(client, 'post', url, attachment_data, users,
content_type=MULTIPART_CONTENT,
after_each_request=_after_each_request_hook)
assert results == [401, 403, 403, 201, 201]
@ -539,11 +579,17 @@ def test_wiki_attachment_create(client, data, data_wiki):
data.project_owner
]
attachment_data = AttachmentSerializer(data_wiki.public_wiki_attachment).data
attachment_data["id"] = None
attachment_data["description"] = "test"
attachment_data = JSONRenderer().render(attachment_data)
results = helper_test_http_method(client, 'post', url, attachment_data, users)
attachment_data = {"description": "test",
"object_id": data_wiki.public_wiki_attachment.object_id,
"project": data_wiki.public_wiki_attachment.project_id,
"attached_file": SimpleUploadedFile("test.txt", b"test")}
_after_each_request_hook = lambda: attachment_data["attached_file"].seek(0)
results = helper_test_http_method(client, 'post', url, attachment_data, users,
content_type=MULTIPART_CONTENT,
after_each_request=_after_each_request_hook)
assert results == [401, 201, 201, 201, 201]

View File

@ -1,15 +1,12 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from taiga.base.utils import json
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
from tests.utils import disconnect_signals, reconnect_signals
import pytest
pytestmark = pytest.mark.django_db

View File

@ -1,15 +1,11 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db

View File

@ -1,17 +1,14 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.projects.issues.serializers import IssueSerializer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from taiga.base.utils import json
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
from taiga.projects.votes.services import add_vote
import json
import pytest
pytestmark = pytest.mark.django_db
@ -125,19 +122,19 @@ def test_issue_update(client, data):
issue_data = IssueSerializer(data.public_issue).data
issue_data["subject"] = "test"
issue_data = JSONRenderer().render(issue_data)
issue_data = json.dumps(issue_data)
results = helper_test_http_method(client, 'put', public_url, issue_data, users)
assert results == [401, 403, 403, 200, 200]
issue_data = IssueSerializer(data.private_issue1).data
issue_data["subject"] = "test"
issue_data = JSONRenderer().render(issue_data)
issue_data = json.dumps(issue_data)
results = helper_test_http_method(client, 'put', private_url1, issue_data, users)
assert results == [401, 403, 403, 200, 200]
issue_data = IssueSerializer(data.private_issue2).data
issue_data["subject"] = "test"
issue_data = JSONRenderer().render(issue_data)
issue_data = json.dumps(issue_data)
results = helper_test_http_method(client, 'put', private_url2, issue_data, users)
assert results == [401, 403, 403, 200, 200]
@ -295,15 +292,18 @@ def test_issue_bulk_create(client, data):
]
bulk_data = json.dumps({"bulk_issues": "test1\ntest2", "project_id": data.public_issue.project.pk})
bulk_data = json.dumps({"bulk_issues": "test1\ntest2",
"project_id": data.public_issue.project.pk})
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 200, 200, 200, 200]
bulk_data = json.dumps({"bulk_issues": "test1\ntest2", "project_id": data.private_issue1.project.pk})
bulk_data = json.dumps({"bulk_issues": "test1\ntest2",
"project_id": data.private_issue1.project.pk})
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 200, 200, 200, 200]
bulk_data = json.dumps({"bulk_issues": "test1\ntest2", "project_id": data.private_issue2.project.pk})
bulk_data = json.dumps({"bulk_issues": "test1\ntest2",
"project_id": data.private_issue2.project.pk})
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 403, 403, 200, 200]

View File

@ -1,8 +1,6 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects.milestones.serializers import MilestoneSerializer
from taiga.projects.milestones.models import Milestone
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
@ -10,8 +8,7 @@ from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS,
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db
@ -110,19 +107,19 @@ def test_milestone_update(client, data):
milestone_data = MilestoneSerializer(data.public_milestone).data
milestone_data["name"] = "test"
milestone_data = JSONRenderer().render(milestone_data)
milestone_data = json.dumps(milestone_data)
results = helper_test_http_method(client, 'put', public_url, milestone_data, users)
assert results == [401, 403, 403, 200, 200]
milestone_data = MilestoneSerializer(data.private_milestone1).data
milestone_data["name"] = "test"
milestone_data = JSONRenderer().render(milestone_data)
milestone_data = json.dumps(milestone_data)
results = helper_test_http_method(client, 'put', private_url1, milestone_data, users)
assert results == [401, 403, 403, 200, 200]
milestone_data = MilestoneSerializer(data.private_milestone2).data
milestone_data["name"] = "test"
milestone_data = JSONRenderer().render(milestone_data)
milestone_data = json.dumps(milestone_data)
results = helper_test_http_method(client, 'put', private_url2, milestone_data, users)
assert results == [401, 403, 403, 200, 200]
@ -240,6 +237,7 @@ def test_milestone_patch(client, data):
results = helper_test_http_method(client, 'patch', private_url2, patch_data, users)
assert results == [401, 403, 403, 200, 200]
def test_milestone_action_stats(client, data):
public_url = reverse('milestones-stats', kwargs={"pk": data.public_milestone.pk})
private_url1 = reverse('milestones-stats', kwargs={"pk": data.private_milestone1.pk})

View File

@ -1,16 +1,13 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects import serializers
from taiga.permissions.permissions import MEMBERS_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method
import json
import pytest
pytestmark = pytest.mark.django_db
@ -132,19 +129,19 @@ def test_roles_update(client, data):
role_data = serializers.RoleSerializer(data.public_project.roles.all()[0]).data
role_data["name"] = "test"
role_data = JSONRenderer().render(role_data)
role_data = json.dumps(role_data)
results = helper_test_http_method(client, 'put', public_url, role_data, users)
assert results == [401, 403, 403, 403, 200]
role_data = serializers.RoleSerializer(data.private_project1.roles.all()[0]).data
role_data["name"] = "test"
role_data = JSONRenderer().render(role_data)
role_data = json.dumps(role_data)
results = helper_test_http_method(client, 'put', private1_url, role_data, users)
assert results == [401, 403, 403, 403, 200]
role_data = serializers.RoleSerializer(data.private_project2.roles.all()[0]).data
role_data["name"] = "test"
role_data = JSONRenderer().render(role_data)
role_data = json.dumps(role_data)
results = helper_test_http_method(client, 'put', private2_url, role_data, users)
assert results == [401, 403, 403, 403, 200]
@ -260,19 +257,19 @@ def test_points_update(client, data):
points_data = serializers.PointsSerializer(data.public_points).data
points_data["name"] = "test"
points_data = JSONRenderer().render(points_data)
points_data = json.dumps(points_data)
results = helper_test_http_method(client, 'put', public_url, points_data, users)
assert results == [401, 403, 403, 403, 200]
points_data = serializers.PointsSerializer(data.private_points1).data
points_data["name"] = "test"
points_data = JSONRenderer().render(points_data)
points_data = json.dumps(points_data)
results = helper_test_http_method(client, 'put', private1_url, points_data, users)
assert results == [401, 403, 403, 403, 200]
points_data = serializers.PointsSerializer(data.private_points2).data
points_data["name"] = "test"
points_data = JSONRenderer().render(points_data)
points_data = json.dumps(points_data)
results = helper_test_http_method(client, 'put', private2_url, points_data, users)
assert results == [401, 403, 403, 403, 200]
@ -421,19 +418,19 @@ def test_user_story_status_update(client, data):
user_story_status_data = serializers.UserStoryStatusSerializer(data.public_user_story_status).data
user_story_status_data["name"] = "test"
user_story_status_data = JSONRenderer().render(user_story_status_data)
user_story_status_data = json.dumps(user_story_status_data)
results = helper_test_http_method(client, 'put', public_url, user_story_status_data, users)
assert results == [401, 403, 403, 403, 200]
user_story_status_data = serializers.UserStoryStatusSerializer(data.private_user_story_status1).data
user_story_status_data["name"] = "test"
user_story_status_data = JSONRenderer().render(user_story_status_data)
user_story_status_data = json.dumps(user_story_status_data)
results = helper_test_http_method(client, 'put', private1_url, user_story_status_data, users)
assert results == [401, 403, 403, 403, 200]
user_story_status_data = serializers.UserStoryStatusSerializer(data.private_user_story_status2).data
user_story_status_data["name"] = "test"
user_story_status_data = JSONRenderer().render(user_story_status_data)
user_story_status_data = json.dumps(user_story_status_data)
results = helper_test_http_method(client, 'put', private2_url, user_story_status_data, users)
assert results == [401, 403, 403, 403, 200]
@ -582,19 +579,19 @@ def test_task_status_update(client, data):
task_status_data = serializers.TaskStatusSerializer(data.public_task_status).data
task_status_data["name"] = "test"
task_status_data = JSONRenderer().render(task_status_data)
task_status_data = json.dumps(task_status_data)
results = helper_test_http_method(client, 'put', public_url, task_status_data, users)
assert results == [401, 403, 403, 403, 200]
task_status_data = serializers.TaskStatusSerializer(data.private_task_status1).data
task_status_data["name"] = "test"
task_status_data = JSONRenderer().render(task_status_data)
task_status_data = json.dumps(task_status_data)
results = helper_test_http_method(client, 'put', private1_url, task_status_data, users)
assert results == [401, 403, 403, 403, 200]
task_status_data = serializers.TaskStatusSerializer(data.private_task_status2).data
task_status_data["name"] = "test"
task_status_data = JSONRenderer().render(task_status_data)
task_status_data = json.dumps(task_status_data)
results = helper_test_http_method(client, 'put', private2_url, task_status_data, users)
assert results == [401, 403, 403, 403, 200]
@ -743,19 +740,19 @@ def test_issue_status_update(client, data):
issue_status_data = serializers.IssueStatusSerializer(data.public_issue_status).data
issue_status_data["name"] = "test"
issue_status_data = JSONRenderer().render(issue_status_data)
issue_status_data = json.dumps(issue_status_data)
results = helper_test_http_method(client, 'put', public_url, issue_status_data, users)
assert results == [401, 403, 403, 403, 200]
issue_status_data = serializers.IssueStatusSerializer(data.private_issue_status1).data
issue_status_data["name"] = "test"
issue_status_data = JSONRenderer().render(issue_status_data)
issue_status_data = json.dumps(issue_status_data)
results = helper_test_http_method(client, 'put', private1_url, issue_status_data, users)
assert results == [401, 403, 403, 403, 200]
issue_status_data = serializers.IssueStatusSerializer(data.private_issue_status2).data
issue_status_data["name"] = "test"
issue_status_data = JSONRenderer().render(issue_status_data)
issue_status_data = json.dumps(issue_status_data)
results = helper_test_http_method(client, 'put', private2_url, issue_status_data, users)
assert results == [401, 403, 403, 403, 200]
@ -904,19 +901,19 @@ def test_issue_type_update(client, data):
issue_type_data = serializers.IssueTypeSerializer(data.public_issue_type).data
issue_type_data["name"] = "test"
issue_type_data = JSONRenderer().render(issue_type_data)
issue_type_data = json.dumps(issue_type_data)
results = helper_test_http_method(client, 'put', public_url, issue_type_data, users)
assert results == [401, 403, 403, 403, 200]
issue_type_data = serializers.IssueTypeSerializer(data.private_issue_type1).data
issue_type_data["name"] = "test"
issue_type_data = JSONRenderer().render(issue_type_data)
issue_type_data = json.dumps(issue_type_data)
results = helper_test_http_method(client, 'put', private1_url, issue_type_data, users)
assert results == [401, 403, 403, 403, 200]
issue_type_data = serializers.IssueTypeSerializer(data.private_issue_type2).data
issue_type_data["name"] = "test"
issue_type_data = JSONRenderer().render(issue_type_data)
issue_type_data = json.dumps(issue_type_data)
results = helper_test_http_method(client, 'put', private2_url, issue_type_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1065,19 +1062,19 @@ def test_priority_update(client, data):
priority_data = serializers.PrioritySerializer(data.public_priority).data
priority_data["name"] = "test"
priority_data = JSONRenderer().render(priority_data)
priority_data = json.dumps(priority_data)
results = helper_test_http_method(client, 'put', public_url, priority_data, users)
assert results == [401, 403, 403, 403, 200]
priority_data = serializers.PrioritySerializer(data.private_priority1).data
priority_data["name"] = "test"
priority_data = JSONRenderer().render(priority_data)
priority_data = json.dumps(priority_data)
results = helper_test_http_method(client, 'put', private1_url, priority_data, users)
assert results == [401, 403, 403, 403, 200]
priority_data = serializers.PrioritySerializer(data.private_priority2).data
priority_data["name"] = "test"
priority_data = JSONRenderer().render(priority_data)
priority_data = json.dumps(priority_data)
results = helper_test_http_method(client, 'put', private2_url, priority_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1226,19 +1223,19 @@ def test_severity_update(client, data):
severity_data = serializers.SeveritySerializer(data.public_severity).data
severity_data["name"] = "test"
severity_data = JSONRenderer().render(severity_data)
severity_data = json.dumps(severity_data)
results = helper_test_http_method(client, 'put', public_url, severity_data, users)
assert results == [401, 403, 403, 403, 200]
severity_data = serializers.SeveritySerializer(data.private_severity1).data
severity_data["name"] = "test"
severity_data = JSONRenderer().render(severity_data)
severity_data = json.dumps(severity_data)
results = helper_test_http_method(client, 'put', private1_url, severity_data, users)
assert results == [401, 403, 403, 403, 200]
severity_data = serializers.SeveritySerializer(data.private_severity2).data
severity_data["name"] = "test"
severity_data = JSONRenderer().render(severity_data)
severity_data = json.dumps(severity_data)
results = helper_test_http_method(client, 'put', private2_url, severity_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1387,19 +1384,19 @@ def test_membership_update(client, data):
membership_data = serializers.MembershipSerializer(data.public_membership).data
membership_data["token"] = "test"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'put', public_url, membership_data, users)
assert results == [401, 403, 403, 403, 200]
membership_data = serializers.MembershipSerializer(data.private_membership1).data
membership_data["token"] = "test"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'put', private1_url, membership_data, users)
assert results == [401, 403, 403, 403, 200]
membership_data = serializers.MembershipSerializer(data.private_membership2).data
membership_data["token"] = "test"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'put', private2_url, membership_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1492,21 +1489,21 @@ def test_membership_create(client, data):
membership_data = serializers.MembershipSerializer(data.public_membership).data
membership_data["id"] = None
membership_data["email"] = "test1@test.com"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'post', url, membership_data, users)
assert results == [401, 403, 403, 403, 201]
membership_data = serializers.MembershipSerializer(data.private_membership1).data
membership_data["id"] = None
membership_data["email"] = "test2@test.com"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'post', url, membership_data, users)
assert results == [401, 403, 403, 403, 201]
membership_data = serializers.MembershipSerializer(data.private_membership2).data
membership_data["id"] = None
membership_data["email"] = "test3@test.com"
membership_data = JSONRenderer().render(membership_data)
membership_data = json.dumps(membership_data)
results = helper_test_http_method(client, 'post', url, membership_data, users)
assert results == [401, 403, 403, 403, 201]
@ -1529,7 +1526,7 @@ def test_membership_action_bulk_create(client, data):
{"role_id": data.public_membership.role.pk, "email": "test2@test.com"},
]
}
bulk_data = JSONRenderer().render(bulk_data)
bulk_data = json.dumps(bulk_data)
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1540,7 +1537,7 @@ def test_membership_action_bulk_create(client, data):
{"role_id": data.private_membership1.role.pk, "email": "test2@test.com"},
]
}
bulk_data = JSONRenderer().render(bulk_data)
bulk_data = json.dumps(bulk_data)
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1551,7 +1548,7 @@ def test_membership_action_bulk_create(client, data):
{"role_id": data.private_membership2.role.pk, "email": "test2@test.com"},
]
}
bulk_data = JSONRenderer().render(bulk_data)
bulk_data = json.dumps(bulk_data)
results = helper_test_http_method(client, 'post', url, bulk_data, users)
assert results == [401, 403, 403, 403, 200]
@ -1607,7 +1604,7 @@ def test_project_template_update(client, data):
project_template_data = serializers.ProjectTemplateSerializer(data.project_template).data
project_template_data["default_owner_role"] = "test"
project_template_data = JSONRenderer().render(project_template_data)
project_template_data = json.dumps(project_template_data)
results = helper_test_http_method(client, 'put', url, project_template_data, users)
assert results == [401, 403, 200]
@ -1657,9 +1654,3 @@ def test_project_template_patch(client, data):
results = helper_test_http_method(client, 'patch', url, '{"name": "Test"}', users)
assert results == [401, 403, 200]
# def test_project_template_action_create_from_project(client, data):
# assert False
#
#

View File

@ -1,17 +1,14 @@
import pytest
from django.core.urlresolvers import reverse
from django.db.models.loading import get_model
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects.serializers import ProjectDetailSerializer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, helper_test_http_method_and_count
import json
import pytest
pytestmark = pytest.mark.django_db
@ -100,7 +97,7 @@ def test_project_update(client, data):
project_data = ProjectDetailSerializer(data.private_project2).data
project_data["is_private"] = False
project_data = JSONRenderer().render(project_data)
project_data = json.dumps(project_data)
users = [
None,

View File

@ -1,15 +1,12 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db

View File

@ -1,17 +1,12 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.projects.issues.serializers import IssueSerializer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method_and_keys, disconnect_signals, reconnect_signals
from taiga.projects.votes.services import add_vote
import json
import pytest
pytestmark = pytest.mark.django_db

View File

@ -1,19 +1,17 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.userstorage.serializers import StorageEntrySerializer
from taiga.base.utils import json
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, helper_test_http_method_and_count, disconnect_signals, reconnect_signals
from taiga.projects.votes.services import add_vote
from taiga.userstorage.serializers import StorageEntrySerializer
from taiga.userstorage.models import StorageEntry
import json
from tests import factories as f
from tests.utils import helper_test_http_method
from tests.utils import helper_test_http_method_and_count
from tests.utils import disconnect_signals, reconnect_signals
import pytest
pytestmark = pytest.mark.django_db
@ -63,7 +61,7 @@ def test_storage_update(client, data):
storage_data = StorageEntrySerializer(data.storage_user1).data
storage_data["key"] = "test"
storage_data = JSONRenderer().render(storage_data)
storage_data = json.dumps(storage_data)
results = helper_test_http_method(client, 'put', url, storage_data, users)
assert results == [401, 200, 201]

View File

@ -1,16 +1,13 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects.tasks.serializers import TaskSerializer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db
@ -125,19 +122,19 @@ def test_task_update(client, data):
task_data = TaskSerializer(data.public_task).data
task_data["subject"] = "test"
task_data = JSONRenderer().render(task_data)
task_data = json.dumps(task_data)
results = helper_test_http_method(client, 'put', public_url, task_data, users)
assert results == [401, 403, 403, 200, 200]
task_data = TaskSerializer(data.private_task1).data
task_data["subject"] = "test"
task_data = JSONRenderer().render(task_data)
task_data = json.dumps(task_data)
results = helper_test_http_method(client, 'put', private_url1, task_data, users)
assert results == [401, 403, 403, 200, 200]
task_data = TaskSerializer(data.private_task2).data
task_data["subject"] = "test"
task_data = JSONRenderer().render(task_data)
task_data = json.dumps(task_data)
results = helper_test_http_method(client, 'put', private_url2, task_data, users)
assert results == [401, 403, 403, 200, 200]

View File

@ -1,15 +1,11 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db

View File

@ -1,17 +1,14 @@
import pytest
from tempfile import NamedTemporaryFile
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.users.serializers import UserSerializer
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
from tempfile import NamedTemporaryFile
import pytest
pytestmark = pytest.mark.django_db
DUMMY_BMP_DATA = b'BM:\x00\x00\x00\x00\x00\x00\x006\x00\x00\x00(\x00\x00\x00\x01\x00\x00\x00\x01\x00\x00\x00\x01\x00\x18\x00\x00\x00\x00\x00\x04\x00\x00\x00\x13\x0b\x00\x00\x13\x0b\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
@ -62,7 +59,7 @@ def test_user_update(client, data):
user_data = UserSerializer(data.registered_user).data
user_data["full_name"] = "test"
user_data = JSONRenderer().render(user_data)
user_data = json.dumps(user_data)
results = helper_test_http_method(client, 'put', url, user_data, users)
assert results == [401, 200, 403, 200]

View File

@ -1,16 +1,13 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects.userstories.serializers import UserStorySerializer
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
import json
import pytest
pytestmark = pytest.mark.django_db
@ -123,19 +120,19 @@ def test_user_story_update(client, data):
user_story_data = UserStorySerializer(data.public_user_story).data
user_story_data["subject"] = "test"
user_story_data = JSONRenderer().render(user_story_data)
user_story_data = json.dumps(user_story_data)
results = helper_test_http_method(client, 'put', public_url, user_story_data, users)
assert results == [401, 403, 403, 200, 200]
user_story_data = UserStorySerializer(data.private_user_story1).data
user_story_data["subject"] = "test"
user_story_data = JSONRenderer().render(user_story_data)
user_story_data = json.dumps(user_story_data)
results = helper_test_http_method(client, 'put', private_url1, user_story_data, users)
assert results == [401, 403, 403, 200, 200]
user_story_data = UserStorySerializer(data.private_user_story2).data
user_story_data["subject"] = "test"
user_story_data = JSONRenderer().render(user_story_data)
user_story_data = json.dumps(user_story_data)
results = helper_test_http_method(client, 'put', private_url2, user_story_data, users)
assert results == [401, 403, 403, 200, 200]

View File

@ -1,18 +1,14 @@
import pytest
from django.core.urlresolvers import reverse
from rest_framework.renderers import JSONRenderer
from taiga.base.utils import json
from taiga.projects.wiki.serializers import WikiPageSerializer, WikiLinkSerializer
from taiga.projects.wiki.models import WikiPage, WikiLink
from taiga.permissions.permissions import MEMBERS_PERMISSIONS, ANON_PERMISSIONS, USER_PERMISSIONS
from tests import factories as f
from tests.utils import helper_test_http_method, disconnect_signals, reconnect_signals
from taiga.projects.votes.services import add_vote
import json
import pytest
pytestmark = pytest.mark.django_db
@ -115,19 +111,19 @@ def test_wiki_page_update(client, data):
wiki_page_data = WikiPageSerializer(data.public_wiki_page).data
wiki_page_data["content"] = "test"
wiki_page_data = JSONRenderer().render(wiki_page_data)
wiki_page_data = json.dumps(wiki_page_data)
results = helper_test_http_method(client, 'put', public_url, wiki_page_data, users)
assert results == [401, 200, 200, 200, 200]
wiki_page_data = WikiPageSerializer(data.private_wiki_page1).data
wiki_page_data["content"] = "test"
wiki_page_data = JSONRenderer().render(wiki_page_data)
wiki_page_data = json.dumps(wiki_page_data)
results = helper_test_http_method(client, 'put', private_url1, wiki_page_data, users)
assert results == [401, 200, 200, 200, 200]
wiki_page_data = WikiPageSerializer(data.private_wiki_page2).data
wiki_page_data["content"] = "test"
wiki_page_data = JSONRenderer().render(wiki_page_data)
wiki_page_data = json.dumps(wiki_page_data)
results = helper_test_http_method(client, 'put', private_url2, wiki_page_data, users)
assert results == [401, 403, 403, 200, 200]
@ -294,19 +290,19 @@ def test_wiki_link_update(client, data):
wiki_link_data = WikiLinkSerializer(data.public_wiki_link).data
wiki_link_data["title"] = "test"
wiki_link_data = JSONRenderer().render(wiki_link_data)
wiki_link_data = json.dumps(wiki_link_data)
results = helper_test_http_method(client, 'put', public_url, wiki_link_data, users)
assert results == [401, 200, 200, 200, 200]
wiki_link_data = WikiLinkSerializer(data.private_wiki_link1).data
wiki_link_data["title"] = "test"
wiki_link_data = JSONRenderer().render(wiki_link_data)
wiki_link_data = json.dumps(wiki_link_data)
results = helper_test_http_method(client, 'put', private_url1, wiki_link_data, users)
assert results == [401, 200, 200, 200, 200]
wiki_link_data = WikiLinkSerializer(data.private_wiki_link2).data
wiki_link_data["title"] = "test"
wiki_link_data = JSONRenderer().render(wiki_link_data)
wiki_link_data = json.dumps(wiki_link_data)
results = helper_test_http_method(client, 'put', private_url2, wiki_link_data, users)
assert results == [401, 403, 403, 200, 200]

View File

@ -2,12 +2,16 @@ import pytest
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
pytestmark = pytest.mark.django_db
def test_authentication(client):
"User can't access an attachment if not authenticated"
attachment = f.UserStoryAttachmentFactory.create()
@ -56,3 +60,39 @@ def test_attachment_redirect(client):
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):
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
url = reverse('userstory-attachments-list')
client.login(us.owner)
response = client.post(url, attachment_data)
assert response.status_code == 400
def test_create_attachment_on_wrong_project(client):
issue1 = f.create_issue()
issue2 = f.create_issue(owner=issue1.owner)
assert issue1.owner == issue2.owner
assert issue1.project.owner == issue2.project.owner
url = reverse("issue-attachments-list")
data = {"description": "test",
"object_id": issue2.pk,
"project": issue1.project.id,
"attached_file": SimpleUploadedFile("test.txt", b"test")}
client.login(issue1.owner)
response = client.post(url, data)
assert response.status_code == 400

View File

@ -1,13 +1,13 @@
from unittest import mock
import pytest
from django.core.urlresolvers import reverse
from taiga.projects.issues import services, models
from taiga.base.utils import json
from .. import factories as f
import pytest
pytestmark = pytest.mark.django_db
@ -51,7 +51,7 @@ def test_api_create_issues_in_bulk(client):
"project_id": project.id}
client.login(project.owner)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 200, response.data

View File

@ -1,13 +1,12 @@
from unittest import mock
import pytest
from django.core.urlresolvers import reverse
from taiga.projects import services
from taiga.base.utils import json
from .. import factories as f
import pytest
pytestmark = pytest.mark.django_db
@ -47,7 +46,7 @@ def test_api_create_bulk_members(client):
]
}
client.login(project.owner)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 200
assert response.data[0]["email"] == john.email
@ -76,7 +75,7 @@ def test_api_invite_existing_user(client, outbox):
url = reverse("memberships-list")
data = {"role": role.pk, "project": role.project.pk, "email": user.email}
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.data
assert len(outbox) == 1

View File

@ -1,9 +1,9 @@
import pytest
from django.core.urlresolvers import reverse
from taiga.base.utils import json
from .. import factories as f
import pytest
pytestmark = pytest.mark.django_db
@ -13,7 +13,7 @@ def test_api_create_project(client):
data = {"name": "project name", "description": "project description"}
client.login(user)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
@ -24,6 +24,6 @@ def test_api_partially_update_project(client):
data = {"name": ""}
client.login(project.owner)
response = client.json.patch(url, data)
response = client.json.patch(url, json.dumps(data))
assert response.status_code == 400

View File

@ -1,13 +1,13 @@
from unittest import mock
import pytest
from django.core.urlresolvers import reverse
from taiga.base.utils import json
from taiga.projects.tasks import services
from .. import factories as f
import pytest
pytestmark = pytest.mark.django_db
@ -40,7 +40,7 @@ def test_api_update_task_tags(client):
data = {"tags": ["back", "front"], "version": task.version}
client.login(task.owner)
response = client.json.patch(url, data)
response = client.json.patch(url, json.dumps(data))
assert response.status_code == 200, response.data
@ -57,7 +57,7 @@ def test_api_create_in_bulk_with_status(client):
}
client.login(us.owner)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 200
assert response.data[0]["status"] == us.project.default_task_status.id

View File

@ -1,13 +1,13 @@
from unittest import mock
import pytest
from django.core.urlresolvers import reverse
from taiga.base.utils import json
from taiga.projects.userstories import services, models
from .. import factories as f
import pytest
pytestmark = pytest.mark.django_db
@ -76,7 +76,7 @@ def test_api_create_in_bulk_with_status(client):
}
client.login(project.owner)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 200, response.data
assert response.data[0]["status"] == project.default_us_status.id
@ -94,6 +94,6 @@ def test_api_update_order_in_bulk(client):
}
client.login(project.owner)
response = client.json.post(url, data)
response = client.json.post(url, json.dumps(data))
assert response.status_code == 204, response.data

View File

@ -88,19 +88,21 @@ class SettingsTestCase(object):
override_settings(cls.ORIGINAL_SETTINGS)
cls.OVERRIDE_SETTINGS.clear()
def _helper_test_http_method_responses(client, method, url, data, users, after_each_request=None):
def _helper_test_http_method_responses(client, method, url, data, users, after_each_request=None,
content_type="application/json"):
results = []
for user in users:
if user is None:
client.logout()
else:
client.login(user)
if data:
response = getattr(client, method)(url, data, content_type="application/json")
response = getattr(client, method)(url, data, content_type=content_type)
else:
response = getattr(client, method)(url)
if response.status_code == 400:
print(response.content)
if response.status_code >= 400:
print("Response content:", response.content)
results.append(response)
@ -108,8 +110,10 @@ def _helper_test_http_method_responses(client, method, url, data, users, after_e
after_each_request()
return results
def helper_test_http_method(client, method, url, data, users, after_each_request=None):
responses = _helper_test_http_method_responses(client, method, url, data, users, after_each_request)
def helper_test_http_method(client, method, url, data, users, after_each_request=None,
content_type="application/json"):
responses = _helper_test_http_method_responses(client, method, url, data, users, after_each_request,
content_type=content_type)
return list(map(lambda r: r.status_code, responses))