Merge pull request #162 from taigaio/bug/1634/update-role-failing

Fixing update_roles when project point "?" exists but is not null
remotes/origin/enhancement/email-actions
David Barragán Merino 2014-11-19 14:24:48 +01:00
commit 3d6863d6c1
2 changed files with 11 additions and 4 deletions

View File

@ -224,16 +224,17 @@ class Project(ProjectDefaults, TaggedMixin, models.Model):
user_stories = self.user_stories.all()
# Get point instance that represent a null/undefined
# The current model allows dulplicate values. Because
# The current model allows duplicate values. Because
# of it, we should get all poins with None as value
# and use the first one.
# In case of that not exists, creates one for avoid
# unxpected errors.
# unexpected errors.
none_points = list(self.points.filter(value=None))
if none_points:
null_points_value = none_points[0]
else:
null_points_value = Points.objects.create(name="?", value=None, project=self)
name = slugify_uniquely_for_queryset("?", self.points.all(), slugfield="name")
null_points_value = Points.objects.create(name=name, value=None, project=self)
for us in user_stories:
usroles = Role.objects.filter(role_points__in=us.role_points.all()).distinct()

View File

@ -84,7 +84,6 @@ def test_issue_status_slug_generation(client):
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)
@ -96,3 +95,10 @@ def test_points_name_duplicated(client):
response = client.json.patch(url, json.dumps(data))
assert response.status_code == 400
assert response.data["name"][0] == "Name duplicated for the project"
def test_update_points_when_not_null_values_for_points(client):
points = f.PointsFactory(name="?", value="6")
role = f.RoleFactory(project=points.project, computable=True)
assert points.project.points.filter(value__isnull=True).count() == 0
points.project.update_role_points()
assert points.project.points.filter(value__isnull=True).count() == 1