Fix tests, identations and pass the Flake8
parent
13e0e79f44
commit
c82288faa3
|
@ -35,6 +35,10 @@ from taiga.projects.notifications.utils import attach_watchers_to_queryset
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Bulk actions
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def get_issues_from_bulk(bulk_data, **additional_fields):
|
def get_issues_from_bulk(bulk_data, **additional_fields):
|
||||||
"""Convert `bulk_data` into a list of issues.
|
"""Convert `bulk_data` into a list of issues.
|
||||||
|
|
||||||
|
@ -83,6 +87,10 @@ def update_issues_order_in_bulk(bulk_data):
|
||||||
db.update_in_bulk_with_ids(issue_ids, new_order_values, model=models.Issue)
|
db.update_in_bulk_with_ids(issue_ids, new_order_values, model=models.Issue)
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# CSV
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def issues_to_csv(project, queryset):
|
def issues_to_csv(project, queryset):
|
||||||
csv_data = io.StringIO()
|
csv_data = io.StringIO()
|
||||||
fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
|
fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
|
||||||
|
@ -143,6 +151,10 @@ def issues_to_csv(project, queryset):
|
||||||
return csv_data
|
return csv_data
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Api filter data
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def _get_issues_statuses(project, queryset):
|
def _get_issues_statuses(project, queryset):
|
||||||
compiler = connection.ops.compiler(queryset.query.compiler)(queryset.query, connection, None)
|
compiler = connection.ops.compiler(queryset.query.compiler)(queryset.query, connection, None)
|
||||||
queryset_where_tuple = queryset.query.where.as_sql(compiler, connection)
|
queryset_where_tuple = queryset.query.where.as_sql(compiler, connection)
|
||||||
|
@ -394,7 +406,7 @@ def _get_issues_owners(project, queryset):
|
||||||
FROM projects_membership
|
FROM projects_membership
|
||||||
LEFT OUTER JOIN counters ON ("projects_membership"."user_id" = "counters"."owner_id")
|
LEFT OUTER JOIN counters ON ("projects_membership"."user_id" = "counters"."owner_id")
|
||||||
INNER JOIN "users_user" ON ("projects_membership"."user_id" = "users_user"."id")
|
INNER JOIN "users_user" ON ("projects_membership"."user_id" = "users_user"."id")
|
||||||
WHERE ("projects_membership"."project_id" = %s AND "projects_membership"."user_id" IS NOT NULL)
|
WHERE "projects_membership"."project_id" = %s AND "projects_membership"."user_id" IS NOT NULL
|
||||||
|
|
||||||
-- System users
|
-- System users
|
||||||
UNION
|
UNION
|
||||||
|
@ -430,27 +442,22 @@ def _get_issues_tags(project, queryset):
|
||||||
where_params = queryset_where_tuple[1]
|
where_params = queryset_where_tuple[1]
|
||||||
|
|
||||||
extra_sql = """
|
extra_sql = """
|
||||||
WITH
|
WITH issues_tags AS (
|
||||||
issues_tags AS (
|
SELECT tag,
|
||||||
SELECT tag, COUNT(tag) counter FROM (
|
COUNT(tag) counter FROM (
|
||||||
SELECT UNNEST(tags) tag
|
SELECT UNNEST(tags) tag
|
||||||
FROM issues_issue
|
FROM issues_issue
|
||||||
WHERE {where}
|
WHERE {where}) tags
|
||||||
) tags
|
GROUP BY tag),
|
||||||
GROUP BY tag
|
project_tags AS (
|
||||||
),
|
SELECT reduce_dim(tags_colors) tag_color
|
||||||
project_tags AS (
|
FROM projects_project
|
||||||
SELECT reduce_dim(tags_colors) tag_color
|
WHERE id=%s)
|
||||||
FROM projects_project
|
|
||||||
WHERE id=%s
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT
|
SELECT tag_color[1] tag, issues_tags.counter counter
|
||||||
tag_color[1] tag, issues_tags.counter counter
|
|
||||||
FROM project_tags
|
FROM project_tags
|
||||||
LEFT JOIN
|
LEFT JOIN issues_tags ON project_tags.tag_color[1] = issues_tags.tag
|
||||||
issues_tags ON project_tags.tag_color[1] = issues_tags.tag
|
ORDER BY tag
|
||||||
ORDER BY tag
|
|
||||||
""".format(where=where)
|
""".format(where=where)
|
||||||
|
|
||||||
with closing(connection.cursor()) as cursor:
|
with closing(connection.cursor()) as cursor:
|
||||||
|
|
|
@ -31,6 +31,7 @@ class TaskPermission(TaigaResourcePermission):
|
||||||
partial_update_perms = CommentAndOrUpdatePerm('modify_task', 'comment_task')
|
partial_update_perms = CommentAndOrUpdatePerm('modify_task', 'comment_task')
|
||||||
destroy_perms = HasProjectPerm('delete_task')
|
destroy_perms = HasProjectPerm('delete_task')
|
||||||
list_perms = AllowAny()
|
list_perms = AllowAny()
|
||||||
|
filters_data_perms = AllowAny()
|
||||||
csv_perms = AllowAny()
|
csv_perms = AllowAny()
|
||||||
bulk_create_perms = HasProjectPerm('add_task')
|
bulk_create_perms = HasProjectPerm('add_task')
|
||||||
bulk_update_order_perms = HasProjectPerm('modify_task')
|
bulk_update_order_perms = HasProjectPerm('modify_task')
|
||||||
|
|
|
@ -144,7 +144,7 @@ def tasks_to_csv(project, queryset):
|
||||||
"voters": task.total_voters,
|
"voters": task.total_voters,
|
||||||
"created_date": task.created_date,
|
"created_date": task.created_date,
|
||||||
"modified_date": task.modified_date,
|
"modified_date": task.modified_date,
|
||||||
"finished_date": task.finished_date,
|
"finished_date": task.finished_date,
|
||||||
}
|
}
|
||||||
for custom_attr in custom_attrs:
|
for custom_attr in custom_attrs:
|
||||||
value = task.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
|
value = task.custom_attributes_values.attributes_values.get(str(custom_attr.id), None)
|
||||||
|
|
|
@ -87,9 +87,6 @@ class UserStoryViewSet(OCCResourceMixin, VotedResourceMixin, HistoryResourceMixi
|
||||||
"kanban_order",
|
"kanban_order",
|
||||||
"total_voters"]
|
"total_voters"]
|
||||||
|
|
||||||
# Specific filter used for filtering neighbor user stories
|
|
||||||
_neighbor_tags_filter = filters.TagsFilter('neighbor_tags')
|
|
||||||
|
|
||||||
def get_serializer_class(self, *args, **kwargs):
|
def get_serializer_class(self, *args, **kwargs):
|
||||||
if self.action in ["retrieve", "by_ref"]:
|
if self.action in ["retrieve", "by_ref"]:
|
||||||
return serializers.UserStoryNeighborsSerializer
|
return serializers.UserStoryNeighborsSerializer
|
||||||
|
|
|
@ -28,9 +28,8 @@ from django.utils.translation import ugettext as _
|
||||||
|
|
||||||
from taiga.base.utils import db, text
|
from taiga.base.utils import db, text
|
||||||
from taiga.projects.history.services import take_snapshot
|
from taiga.projects.history.services import take_snapshot
|
||||||
from taiga.projects.userstories.apps import (
|
from taiga.projects.userstories.apps import connect_userstories_signals
|
||||||
connect_userstories_signals,
|
from taiga.projects.userstories.apps import disconnect_userstories_signals
|
||||||
disconnect_userstories_signals)
|
|
||||||
|
|
||||||
from taiga.events import events
|
from taiga.events import events
|
||||||
from taiga.projects.votes.utils import attach_total_voters_to_queryset
|
from taiga.projects.votes.utils import attach_total_voters_to_queryset
|
||||||
|
@ -39,6 +38,10 @@ from taiga.projects.notifications.utils import attach_watchers_to_queryset
|
||||||
from . import models
|
from . import models
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Bulk actions
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def get_userstories_from_bulk(bulk_data, **additional_fields):
|
def get_userstories_from_bulk(bulk_data, **additional_fields):
|
||||||
"""Convert `bulk_data` into a list of user stories.
|
"""Convert `bulk_data` into a list of user stories.
|
||||||
|
|
||||||
|
@ -72,7 +75,7 @@ def create_userstories_in_bulk(bulk_data, callback=None, precall=None, **additio
|
||||||
return userstories
|
return userstories
|
||||||
|
|
||||||
|
|
||||||
def update_userstories_order_in_bulk(bulk_data:list, field:str, project:object):
|
def update_userstories_order_in_bulk(bulk_data: list, field: str, project: object):
|
||||||
"""
|
"""
|
||||||
Update the order of some user stories.
|
Update the order of some user stories.
|
||||||
`bulk_data` should be a list of tuples with the following format:
|
`bulk_data` should be a list of tuples with the following format:
|
||||||
|
@ -92,7 +95,7 @@ def update_userstories_order_in_bulk(bulk_data:list, field:str, project:object):
|
||||||
db.update_in_bulk_with_ids(user_story_ids, new_order_values, model=models.UserStory)
|
db.update_in_bulk_with_ids(user_story_ids, new_order_values, model=models.UserStory)
|
||||||
|
|
||||||
|
|
||||||
def update_userstories_milestone_in_bulk(bulk_data:list, milestone:object):
|
def update_userstories_milestone_in_bulk(bulk_data: list, milestone: object):
|
||||||
"""
|
"""
|
||||||
Update the milestone of some user stories.
|
Update the milestone of some user stories.
|
||||||
`bulk_data` should be a list of user story ids:
|
`bulk_data` should be a list of user story ids:
|
||||||
|
@ -108,7 +111,6 @@ def update_userstories_milestone_in_bulk(bulk_data:list, milestone:object):
|
||||||
|
|
||||||
|
|
||||||
def snapshot_userstories_in_bulk(bulk_data, user):
|
def snapshot_userstories_in_bulk(bulk_data, user):
|
||||||
user_story_ids = []
|
|
||||||
for us_data in bulk_data:
|
for us_data in bulk_data:
|
||||||
try:
|
try:
|
||||||
us = models.UserStory.objects.get(pk=us_data['us_id'])
|
us = models.UserStory.objects.get(pk=us_data['us_id'])
|
||||||
|
@ -117,6 +119,10 @@ def snapshot_userstories_in_bulk(bulk_data, user):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Open/Close calcs
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def calculate_userstory_is_closed(user_story):
|
def calculate_userstory_is_closed(user_story):
|
||||||
if user_story.status is None:
|
if user_story.status is None:
|
||||||
return False
|
return False
|
||||||
|
@ -144,7 +150,11 @@ def open_userstory(us):
|
||||||
us.save(update_fields=["is_closed", "finish_date"])
|
us.save(update_fields=["is_closed", "finish_date"])
|
||||||
|
|
||||||
|
|
||||||
def userstories_to_csv(project,queryset):
|
#####################################################
|
||||||
|
# CSV
|
||||||
|
#####################################################
|
||||||
|
|
||||||
|
def userstories_to_csv(project, queryset):
|
||||||
csv_data = io.StringIO()
|
csv_data = io.StringIO()
|
||||||
fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
|
fieldnames = ["ref", "subject", "description", "sprint", "sprint_estimated_start",
|
||||||
"sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
|
"sprint_estimated_finish", "owner", "owner_full_name", "assigned_to",
|
||||||
|
@ -160,7 +170,7 @@ def userstories_to_csv(project,queryset):
|
||||||
"created_date", "modified_date", "finish_date",
|
"created_date", "modified_date", "finish_date",
|
||||||
"client_requirement", "team_requirement", "attachments",
|
"client_requirement", "team_requirement", "attachments",
|
||||||
"generated_from_issue", "external_reference", "tasks",
|
"generated_from_issue", "external_reference", "tasks",
|
||||||
"tags","watchers", "voters"]
|
"tags", "watchers", "voters"]
|
||||||
|
|
||||||
custom_attrs = project.userstorycustomattributes.all()
|
custom_attrs = project.userstorycustomattributes.all()
|
||||||
for custom_attr in custom_attrs:
|
for custom_attr in custom_attrs:
|
||||||
|
@ -230,6 +240,10 @@ def userstories_to_csv(project,queryset):
|
||||||
return csv_data
|
return csv_data
|
||||||
|
|
||||||
|
|
||||||
|
#####################################################
|
||||||
|
# Api filter data
|
||||||
|
#####################################################
|
||||||
|
|
||||||
def _get_userstories_statuses(project, queryset):
|
def _get_userstories_statuses(project, queryset):
|
||||||
compiler = connection.ops.compiler(queryset.query.compiler)(queryset.query, connection, None)
|
compiler = connection.ops.compiler(queryset.query.compiler)(queryset.query, connection, None)
|
||||||
queryset_where_tuple = queryset.query.where.as_sql(compiler, connection)
|
queryset_where_tuple = queryset.query.where.as_sql(compiler, connection)
|
||||||
|
@ -336,7 +350,8 @@ def _get_userstories_owners(project, queryset):
|
||||||
|
|
||||||
extra_sql = """
|
extra_sql = """
|
||||||
WITH counters AS (
|
WITH counters AS (
|
||||||
SELECT "userstories_userstory"."owner_id" owner_id, count(coalesce("userstories_userstory"."owner_id", -1)) count
|
SELECT "userstories_userstory"."owner_id" owner_id,
|
||||||
|
count(coalesce("userstories_userstory"."owner_id", -1)) count
|
||||||
FROM "userstories_userstory"
|
FROM "userstories_userstory"
|
||||||
INNER JOIN "projects_project" ON ("userstories_userstory"."project_id" = "projects_project"."id")
|
INNER JOIN "projects_project" ON ("userstories_userstory"."project_id" = "projects_project"."id")
|
||||||
WHERE {where}
|
WHERE {where}
|
||||||
|
@ -350,7 +365,7 @@ def _get_userstories_owners(project, queryset):
|
||||||
FROM projects_membership
|
FROM projects_membership
|
||||||
LEFT OUTER JOIN counters ON ("projects_membership"."user_id" = "counters"."owner_id")
|
LEFT OUTER JOIN counters ON ("projects_membership"."user_id" = "counters"."owner_id")
|
||||||
INNER JOIN "users_user" ON ("projects_membership"."user_id" = "users_user"."id")
|
INNER JOIN "users_user" ON ("projects_membership"."user_id" = "users_user"."id")
|
||||||
WHERE ("projects_membership"."project_id" = %s AND "projects_membership"."user_id" IS NOT NULL)
|
WHERE "projects_membership"."project_id" = %s AND "projects_membership"."user_id" IS NOT NULL
|
||||||
|
|
||||||
-- System users
|
-- System users
|
||||||
UNION
|
UNION
|
||||||
|
@ -386,27 +401,22 @@ def _get_userstories_tags(project, queryset):
|
||||||
where_params = queryset_where_tuple[1]
|
where_params = queryset_where_tuple[1]
|
||||||
|
|
||||||
extra_sql = """
|
extra_sql = """
|
||||||
WITH
|
WITH userstories_tags AS (
|
||||||
userstories_tags AS (
|
SELECT tag,
|
||||||
SELECT tag, COUNT(tag) counter FROM (
|
COUNT(tag) counter FROM (
|
||||||
SELECT UNNEST(tags) tag
|
SELECT UNNEST(tags) tag
|
||||||
FROM userstories_userstory
|
FROM userstories_userstory
|
||||||
WHERE {where}
|
WHERE {where}) tags
|
||||||
) tags
|
GROUP BY tag),
|
||||||
GROUP BY tag
|
project_tags AS (
|
||||||
),
|
SELECT reduce_dim(tags_colors) tag_color
|
||||||
project_tags AS (
|
FROM projects_project
|
||||||
SELECT reduce_dim(tags_colors) tag_color
|
WHERE id=%s)
|
||||||
FROM projects_project
|
|
||||||
WHERE id=%s
|
|
||||||
)
|
|
||||||
|
|
||||||
SELECT
|
SELECT tag_color[1] tag, userstories_tags.counter counter
|
||||||
tag_color[1] tag, userstories_tags.counter counter
|
|
||||||
FROM project_tags
|
FROM project_tags
|
||||||
LEFT JOIN
|
LEFT JOIN userstories_tags ON project_tags.tag_color[1] = userstories_tags.tag
|
||||||
userstories_tags ON project_tags.tag_color[1] = userstories_tags.tag
|
ORDER BY tag
|
||||||
ORDER BY tag
|
|
||||||
""".format(where=where)
|
""".format(where=where)
|
||||||
|
|
||||||
with closing(connection.cursor()) as cursor:
|
with closing(connection.cursor()) as cursor:
|
||||||
|
|
|
@ -229,6 +229,7 @@ def test_api_filter_by_text_6(client):
|
||||||
assert response.status_code == 200
|
assert response.status_code == 200
|
||||||
assert number_of_issues == 1
|
assert number_of_issues == 1
|
||||||
|
|
||||||
|
|
||||||
def test_api_filters_data(client):
|
def test_api_filters_data(client):
|
||||||
project = f.ProjectFactory.create()
|
project = f.ProjectFactory.create()
|
||||||
user1 = f.UserFactory.create(is_superuser=True)
|
user1 = f.UserFactory.create(is_superuser=True)
|
||||||
|
@ -378,8 +379,7 @@ def test_api_filters_data(client):
|
||||||
assert next(filter(lambda i: i['id'] == severity2.id, response.data["severities"]))["count"] == 0
|
assert next(filter(lambda i: i['id'] == severity2.id, response.data["severities"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['id'] == severity3.id, response.data["severities"]))["count"] == 1
|
assert next(filter(lambda i: i['id'] == severity3.id, response.data["severities"]))["count"] == 1
|
||||||
|
|
||||||
with pytest.raises(StopIteration):
|
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
|
||||||
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 4
|
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 4
|
||||||
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
||||||
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
||||||
|
@ -415,8 +415,7 @@ def test_api_filters_data(client):
|
||||||
assert next(filter(lambda i: i['id'] == severity2.id, response.data["severities"]))["count"] == 0
|
assert next(filter(lambda i: i['id'] == severity2.id, response.data["severities"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['id'] == severity3.id, response.data["severities"]))["count"] == 1
|
assert next(filter(lambda i: i['id'] == severity3.id, response.data["severities"]))["count"] == 1
|
||||||
|
|
||||||
with pytest.raises(StopIteration):
|
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
|
||||||
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 2
|
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 2
|
||||||
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
||||||
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
||||||
|
|
|
@ -504,8 +504,7 @@ def test_api_filters_data(client):
|
||||||
assert next(filter(lambda i: i['id'] == status2.id, response.data["statuses"]))["count"] == 1
|
assert next(filter(lambda i: i['id'] == status2.id, response.data["statuses"]))["count"] == 1
|
||||||
assert next(filter(lambda i: i['id'] == status3.id, response.data["statuses"]))["count"] == 4
|
assert next(filter(lambda i: i['id'] == status3.id, response.data["statuses"]))["count"] == 4
|
||||||
|
|
||||||
with pytest.raises(StopIteration):
|
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
|
||||||
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 4
|
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 4
|
||||||
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 3
|
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 3
|
||||||
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 3
|
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 3
|
||||||
|
@ -528,8 +527,7 @@ def test_api_filters_data(client):
|
||||||
assert next(filter(lambda i: i['id'] == status2.id, response.data["statuses"]))["count"] == 0
|
assert next(filter(lambda i: i['id'] == status2.id, response.data["statuses"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['id'] == status3.id, response.data["statuses"]))["count"] == 1
|
assert next(filter(lambda i: i['id'] == status3.id, response.data["statuses"]))["count"] == 1
|
||||||
|
|
||||||
with pytest.raises(StopIteration):
|
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
||||||
assert next(filter(lambda i: i['name'] == tag0, response.data["tags"]))["count"] == 0
|
|
||||||
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 2
|
assert next(filter(lambda i: i['name'] == tag1, response.data["tags"]))["count"] == 2
|
||||||
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
assert next(filter(lambda i: i['name'] == tag2, response.data["tags"]))["count"] == 2
|
||||||
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
assert next(filter(lambda i: i['name'] == tag3, response.data["tags"]))["count"] == 1
|
||||||
|
|
Loading…
Reference in New Issue