From 2e78d51edaa65722a5124719627f4af5014f27a6 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Thu, 6 Nov 2014 13:47:06 +0100 Subject: [PATCH] Fixing bug when changing us's to a non existing status --- taiga/github_hook/event_hooks.py | 6 +++--- tests/integration/test_github_hook.py | 22 +++++++++++++++++++++- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/taiga/github_hook/event_hooks.py b/taiga/github_hook/event_hooks.py index e91b17da..aa962ab4 100644 --- a/taiga/github_hook/event_hooks.py +++ b/taiga/github_hook/event_hooks.py @@ -74,10 +74,10 @@ class PushEventHook(BaseEventHook): if Issue.objects.filter(project=self.project, ref=ref).exists(): modelClass = Issue statusClass = IssueStatus - elif Task.objects.filter(ref=ref).exists(): + elif Task.objects.filter(project=self.project, ref=ref).exists(): modelClass = Task statusClass = TaskStatus - elif UserStory.objects.filter(ref=ref).exists(): + elif UserStory.objects.filter(project=self.project, ref=ref).exists(): modelClass = UserStory statusClass = UserStoryStatus else: @@ -87,7 +87,7 @@ class PushEventHook(BaseEventHook): try: status = statusClass.objects.get(project=self.project, slug=status_slug) - except IssueStatus.DoesNotExist: + except statusClass.DoesNotExist: raise ActionSyntaxException(_("The status doesn't exist")) element.status = status diff --git a/tests/integration/test_github_hook.py b/tests/integration/test_github_hook.py index a5d25122..60a7f8c2 100644 --- a/tests/integration/test_github_hook.py +++ b/tests/integration/test_github_hook.py @@ -146,7 +146,7 @@ def test_push_event_processing_case_insensitive(client): assert len(mail.outbox) == 1 -def test_push_event_bad_processing_non_existing_ref(client): +def test_push_event_task_bad_processing_non_existing_ref(client): issue_status = f.IssueStatusFactory() payload = {"commits": [ {"message": """test message @@ -164,6 +164,25 @@ def test_push_event_bad_processing_non_existing_ref(client): assert len(mail.outbox) == 0 +def test_push_event_us_bad_processing_non_existing_status(client): + user_story = f.UserStoryFactory.create() + payload = {"commits": [ + {"message": """test message + test TG-%s #non-existing-slug ok + bye! + """%(user_story.ref)}, + ]} + + mail.outbox = [] + + ev_hook = event_hooks.PushEventHook(user_story.project, payload) + with pytest.raises(ActionSyntaxException) as excinfo: + ev_hook.process_event() + + assert str(excinfo.value) == "The status doesn't exist" + assert len(mail.outbox) == 0 + + def test_push_event_bad_processing_non_existing_status(client): issue = f.IssueFactory.create() payload = {"commits": [ @@ -182,6 +201,7 @@ def test_push_event_bad_processing_non_existing_status(client): assert str(excinfo.value) == "The status doesn't exist" assert len(mail.outbox) == 0 + def test_issues_event_opened_issue(client): issue = f.IssueFactory.create() issue.project.default_issue_status = issue.status