Skip to content

Commit

Permalink
Fix Trello import when list deleted (#151)
Browse files Browse the repository at this point in the history
  • Loading branch information
seralot committed Apr 3, 2024
1 parent b6eac2c commit fc6b1c7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion taiga/importers/trello/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ def _transform_action_data(self, us, action, statuses, options):
result['change_new']["description"] = str(action['data']['card'].get('desc', ''))
result['change_old']["description_html"] = mdrender(us.project, str(action['data']['old'].get('desc', '')))
result['change_new']["description_html"] = mdrender(us.project, str(action['data']['card'].get('desc', '')))
if 'idList' in action['data']['old']:
if (
'idList' in action['data']['old']
and action["data"]["old"]["idList"] in statuses
and action["data"]["card"]["idList"] in statuses
):
old_status_name = statuses[action['data']['old']['idList']]['name']
result['change_old']["status"] = us.project.us_statuses.get(name=old_status_name).id
new_status_name = statuses[action['data']['card']['idList']]['name']
Expand Down
26 changes: 26 additions & 0 deletions tests/integration/test_importers_trello_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from taiga.base.utils import json
from taiga.base import exceptions as exc

import taiga.importers.trello.importer

pytestmark = pytest.mark.django_db

Expand Down Expand Up @@ -195,6 +196,31 @@ def test_import_trello_project_without_project_id(client, settings):
settings.CELERY_ENABLED = False


def test_import_trello_transform_action_data_wrong_id_old(client, settings):
user = f.UserFactory.create()
client.login(user)

us = f.UserStoryFactory.create()
f.UserStoryStatusFactory.create(name="completed", project=us.project)
f.UserStoryStatusFactory.create(name="pending", project=us.project)
action = {
"data": {"old": {"idList": "notExists"}, "card": {"idList": "notExists"}},
"type": "updateCard",
}
statuses = {"1": {"name": "completed"}, "2": {"name": "pending"}}

with mock.patch("taiga.importers.trello.importer.TrelloClient") as TrelloClientMock:
TrelloClientMock.get.return_value = {"id": 1234, "name": "Not exists board"}
trello_importer = taiga.importers.trello.importer.TrelloImporter(user, "token")

assert (
trello_importer._transform_action_data(
us, action=action, statuses=statuses, options={}
)
is None
)


def test_import_trello_project_with_celery_enabled(client, settings):
settings.CELERY_ENABLED = True

Expand Down

0 comments on commit fc6b1c7

Please sign in to comment.