Merge pull request #161 from taigaio/bug/points/error-when-using-duplicated-names-for-project

Fixing error 500 when using duplicated names for project points
remotes/origin/enhancement/email-actions
David Barragán Merino 2014-11-19 14:01:08 +01:00
commit edea9ff28b
2 changed files with 31 additions and 1 deletions

View File

@ -39,6 +39,23 @@ class PointsSerializer(ModelSerializer):
class Meta:
model = models.Points
def validate_name(self, attrs, source):
"""
Check the points name is not duplicated in the project on creation
"""
qs = None
# If the user story status exists:
if self.object and attrs.get("name", None):
qs = models.Points.objects.filter(project=self.object.project, name=attrs[source])
if not self.object and attrs.get("project", None) and attrs.get("name", None):
qs = models.Points.objects.filter(project=attrs["project"], name=attrs[source])
if qs and qs.exists():
raise serializers.ValidationError("Name duplicated for the project")
return attrs
class UserStoryStatusSerializer(ModelSerializer):
class Meta:

View File

@ -83,3 +83,16 @@ def test_issue_status_slug_generation(client):
response = client.json.patch(url, json.dumps(data))
assert response.status_code == 200
assert response.data["slug"] == "new-status"
def test_points_name_duplicated(client):
point_1 = f.PointsFactory()
point_2 = f.PointsFactory(project=point_1.project)
client.login(point_1.project.owner)
url = reverse("points-detail", kwargs={"pk": point_2.pk})
data = {"name": point_1.name}
response = client.json.patch(url, json.dumps(data))
assert response.status_code == 400
assert response.data["name"][0] == "Name duplicated for the project"