190 lines
7.3 KiB
Python
190 lines
7.3 KiB
Python
# Copyright (C) 2015 Andrey Antukh <niwi@niwi.be>
|
|
# Copyright (C) 2015 Jesús Espino <jespinog@gmail.com>
|
|
# Copyright (C) 2015 David Barragán <bameda@dbarragan.com>
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU Affero General Public License as
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
# License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU Affero General Public License for more details.
|
|
#
|
|
# 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.core.urlresolvers import reverse
|
|
from taiga.base.utils import json
|
|
|
|
from .. import factories as f
|
|
|
|
import pytest
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
#########################################################
|
|
# User Story Custom Fields
|
|
#########################################################
|
|
|
|
def test_userstory_custom_attribute_duplicate_name_error_on_create(client):
|
|
custom_attr_1 = f.UserStoryCustomAttributeFactory()
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("userstory-custom-attributes-list")
|
|
data = {"name": custom_attr_1.name,
|
|
"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.post(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_userstory_custom_attribute_duplicate_name_error_on_update(client):
|
|
custom_attr_1 = f.UserStoryCustomAttributeFactory()
|
|
custom_attr_2 = f.UserStoryCustomAttributeFactory(project=custom_attr_1.project)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("userstory-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"name": custom_attr_1.name}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_userstory_custom_attribute_duplicate_name_error_on_move_between_projects(client):
|
|
custom_attr_1 = f.UserStoryCustomAttributeFactory()
|
|
custom_attr_2 = f.UserStoryCustomAttributeFactory(name=custom_attr_1.name)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_2.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("userstory-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
#########################################################
|
|
# Task Custom Fields
|
|
#########################################################
|
|
|
|
def test_task_custom_attribute_duplicate_name_error_on_create(client):
|
|
custom_attr_1 = f.TaskCustomAttributeFactory()
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("task-custom-attributes-list")
|
|
data = {"name": custom_attr_1.name,
|
|
"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.post(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_task_custom_attribute_duplicate_name_error_on_update(client):
|
|
custom_attr_1 = f.TaskCustomAttributeFactory()
|
|
custom_attr_2 = f.TaskCustomAttributeFactory(project=custom_attr_1.project)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("task-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"name": custom_attr_1.name}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_task_custom_attribute_duplicate_name_error_on_move_between_projects(client):
|
|
custom_attr_1 = f.TaskCustomAttributeFactory()
|
|
custom_attr_2 = f.TaskCustomAttributeFactory(name=custom_attr_1.name)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_2.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("task-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
#########################################################
|
|
# Issue Custom Fields
|
|
#########################################################
|
|
|
|
def test_issue_custom_attribute_duplicate_name_error_on_create(client):
|
|
custom_attr_1 = f.IssueCustomAttributeFactory()
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("issue-custom-attributes-list")
|
|
data = {"name": custom_attr_1.name,
|
|
"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.post(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_issue_custom_attribute_duplicate_name_error_on_update(client):
|
|
custom_attr_1 = f.IssueCustomAttributeFactory()
|
|
custom_attr_2 = f.IssueCustomAttributeFactory(project=custom_attr_1.project)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("issue-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"name": custom_attr_1.name}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|
|
|
|
|
|
def test_issue_custom_attribute_duplicate_name_error_on_move_between_projects(client):
|
|
custom_attr_1 = f.IssueCustomAttributeFactory()
|
|
custom_attr_2 = f.IssueCustomAttributeFactory(name=custom_attr_1.name)
|
|
member = f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_1.project,
|
|
is_owner=True)
|
|
f.MembershipFactory(user=custom_attr_1.project.owner,
|
|
project=custom_attr_2.project,
|
|
is_owner=True)
|
|
|
|
|
|
url = reverse("issue-custom-attributes-detail", kwargs={"pk": custom_attr_2.pk})
|
|
data = {"project": custom_attr_1.project.pk}
|
|
|
|
client.login(member.user)
|
|
response = client.json.patch(url, json.dumps(data))
|
|
assert response.status_code == 400
|