Merge pull request #142 from taigaio/bug/1438/error-when-import-export-finish-date-for-issues-and-user-stories
Fixing error when importing issues, the finished date was set to none by signals. Added some testsremotes/origin/enhancement/email-actions
commit
a2203d0bf8
|
@ -26,6 +26,7 @@ from taiga.base.api.mixins import CreateModelMixin
|
|||
from taiga.base.api.viewsets import GenericViewSet
|
||||
from taiga.base.decorators import detail_route
|
||||
from taiga.projects.models import Project, Membership
|
||||
from taiga.projects.issues.models import Issue
|
||||
|
||||
from . import serializers
|
||||
from . import service
|
||||
|
@ -117,6 +118,9 @@ class ProjectImporterViewSet(CreateModelMixin, GenericViewSet):
|
|||
project = self.get_object_or_none()
|
||||
self.check_permissions(request, 'import_item', project)
|
||||
|
||||
signals.pre_save.disconnect(sender=Issue,
|
||||
dispatch_uid="set_finished_date_when_edit_issue")
|
||||
|
||||
issue = service.store_issue(project, request.DATA.copy())
|
||||
|
||||
errors = service.get_errors()
|
||||
|
|
|
@ -27,9 +27,10 @@ class IssuesAppConfig(AppConfig):
|
|||
verbose_name = "Issues"
|
||||
|
||||
def ready(self):
|
||||
# Finixhed date
|
||||
# Finished date
|
||||
signals.pre_save.connect(handlers.set_finished_date_when_edit_issue,
|
||||
sender=apps.get_model("issues", "Issue"))
|
||||
sender=apps.get_model("issues", "Issue"),
|
||||
dispatch_uid="set_finished_date_when_edit_issue")
|
||||
|
||||
# Tags
|
||||
signals.pre_save.connect(generic_handlers.tags_normalization,
|
||||
|
|
|
@ -176,6 +176,26 @@ def test_invalid_issue_import(client):
|
|||
response = client.post(url, json.dumps(data), content_type="application/json")
|
||||
assert response.status_code == 400
|
||||
|
||||
def test_valid_user_story_import(client):
|
||||
user = f.UserFactory.create()
|
||||
project = f.ProjectFactory.create(owner=user)
|
||||
project.default_us_status = f.UserStoryStatusFactory.create(project=project)
|
||||
project.save()
|
||||
client.login(user)
|
||||
|
||||
url = reverse("importer-us", args=[project.pk])
|
||||
data = {
|
||||
"subject": "Imported issue",
|
||||
"finish_date": "2014-10-24T00:00:00+0000"
|
||||
}
|
||||
|
||||
response = client.post(url, json.dumps(data), content_type="application/json")
|
||||
assert response.status_code == 201
|
||||
response_data = json.loads(response.content.decode("utf-8"))
|
||||
assert response_data["subject"] == "Imported issue"
|
||||
assert response_data["finish_date"] == "2014-10-24T00:00:00+0000"
|
||||
|
||||
|
||||
def test_valid_issue_import_without_extra_data(client):
|
||||
user = f.UserFactory.create()
|
||||
project = f.ProjectFactory.create(owner=user)
|
||||
|
@ -211,6 +231,7 @@ def test_valid_issue_import_with_extra_data(client):
|
|||
data = {
|
||||
"subject": "Imported issue",
|
||||
"description": "Imported issue",
|
||||
"finished_date": "2014-10-24T00:00:00+0000",
|
||||
"attachments": [{
|
||||
"owner": user.email,
|
||||
"attached_file": {
|
||||
|
@ -226,6 +247,7 @@ def test_valid_issue_import_with_extra_data(client):
|
|||
assert len(response_data["attachments"]) == 1
|
||||
assert response_data["owner"] == user.email
|
||||
assert response_data["ref"] is not None
|
||||
assert response_data["finished_date"] == "2014-10-24T00:00:00+0000"
|
||||
|
||||
def test_invalid_issue_import_with_extra_data(client):
|
||||
user = f.UserFactory.create()
|
||||
|
|
|
@ -0,0 +1,35 @@
|
|||
# Copyright (C) 2014 Andrey Antukh <niwi@niwi.be>
|
||||
# Copyright (C) 2014 Jesús Espino <jespinog@gmail.com>
|
||||
# Copyright (C) 2014 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/>.
|
||||
|
||||
import pytest
|
||||
|
||||
from .. import factories as f
|
||||
|
||||
from taiga.export_import.service import project_to_dict
|
||||
|
||||
pytestmark = pytest.mark.django_db
|
||||
|
||||
|
||||
def test_export_issue_finish_date(client):
|
||||
issue = f.IssueFactory.create(finished_date="2014-10-22")
|
||||
finish_date = project_to_dict(issue.project)["issues"][0]["finished_date"]
|
||||
assert finish_date == "2014-10-22T00:00:00+0000"
|
||||
|
||||
|
||||
def test_export_user_story_finish_date(client):
|
||||
user_story = f.UserStoryFactory.create(finish_date="2014-10-22")
|
||||
finish_date = project_to_dict(user_story.project)["user_stories"][0]["finish_date"]
|
||||
assert finish_date == "2014-10-22T00:00:00+0000"
|
Loading…
Reference in New Issue