Skip to content

Commit

Permalink
Replace direct JSONRender usage with taiga own json module on all tests.
Browse files Browse the repository at this point in the history
So unify the json interface in all tests code.
  • Loading branch information
Andrey Antukh committed Sep 6, 2014
1 parent 4f27a8b commit 0b375be
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 165 deletions.
9 changes: 7 additions & 2 deletions taiga/base/utils/json.py
Expand Up @@ -18,9 +18,14 @@
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
Expand Up @@ -2,7 +2,6 @@
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
Expand Down Expand Up @@ -222,7 +221,7 @@ 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 = json.to_json(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, 400, 400]
Expand Down Expand Up @@ -252,7 +251,7 @@ 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 == [405, 405, 405, 405, 405]
Expand Down Expand Up @@ -280,7 +279,7 @@ 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 == [405, 405, 405, 405, 405]
Expand Down Expand Up @@ -308,7 +307,7 @@ 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 == [405, 405, 405, 405, 405]
Expand All @@ -335,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]
Expand All @@ -359,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]
Expand All @@ -383,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]
Expand All @@ -407,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]
Expand Down
@@ -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


Expand Down
@@ -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


Expand Down
22 changes: 11 additions & 11 deletions tests/integration/resources_permissions/test_issues_resources.py
@@ -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


Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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]

Expand Down
@@ -1,17 +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.milestones.serializers import MilestoneSerializer
from taiga.projects.milestones.models import Milestone
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


Expand Down Expand Up @@ -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]

Expand Down Expand Up @@ -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})
Expand Down

0 comments on commit 0b375be

Please sign in to comment.