Exemplo n.º 1
0
def test_push_event_user_story_processing(client):
    creation_status = f.UserStoryStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_us"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.UserStoryStatusFactory(project=creation_status.project)
    user_story = f.UserStoryFactory.create(status=creation_status,
                                           project=creation_status.project,
                                           owner=creation_status.project.owner)
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   TG-%s    #%s   ok
            bye!
        """ % (user_story.ref, new_status.slug),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]
    payload["total_commits_count"] = 1

    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(user_story.project, payload)
    ev_hook.process_event()
    user_story = UserStory.objects.get(id=user_story.id)
    assert user_story.status.id == new_status.id
    assert len(mail.outbox) == 1
Exemplo n.º 2
0
def test_push_event_processing_case_insensitive(client):
    creation_status = f.TaskStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_tasks"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.TaskStatusFactory(project=creation_status.project)
    task = f.TaskFactory.create(status=creation_status,
                                project=creation_status.project,
                                owner=creation_status.project.owner)
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   tg-%s    #%s   ok
            bye!
        """ % (task.ref, new_status.slug.upper()),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]
    payload["total_commits_count"] = 1
    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(task.project, payload)
    ev_hook.process_event()
    task = Task.objects.get(id=task.id)
    assert task.status.id == new_status.id
    assert len(mail.outbox) == 1
Exemplo n.º 3
0
def test_push_event_user_story_mention(client):
    creation_status = f.UserStoryStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_us"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    user_story = f.UserStoryFactory.create(status=creation_status,
                                           project=creation_status.project,
                                           owner=creation_status.project.owner)
    take_snapshot(user_story, user=creation_status.project.owner)
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   TG-%s   ok
            bye!
        """ % (user_story.ref),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]

    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(user_story.project, payload)
    ev_hook.process_event()
    us_history = get_history_queryset_by_model_instance(user_story)
    assert us_history.count() == 1
    assert us_history[0].comment.startswith(
        "This user story has been mentioned by")
    assert len(mail.outbox) == 1
def test_push_event_processing_case_insensitive(client):
    creation_status = f.TaskStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_tasks"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.TaskStatusFactory(project=creation_status.project)
    task = f.TaskFactory.create(status=creation_status,
                                project=creation_status.project,
                                owner=creation_status.project.owner)
    payload = {
        "commits": [
            {
                "message":
                """test message
            test   tg-%s    #%s   ok
            bye!
        """ % (task.ref, new_status.slug.upper())
            },
        ]
    }
    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(task.project, payload)
    ev_hook.process_event()
    task = Task.objects.get(id=task.id)
    assert task.status.id == new_status.id
    assert len(mail.outbox) == 1
def test_push_event_multiple_actions(client):
    creation_status = f.IssueStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_issues"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.IssueStatusFactory(project=creation_status.project)
    issue1 = f.IssueFactory.create(status=creation_status,
                                   project=creation_status.project,
                                   owner=creation_status.project.owner)
    issue2 = f.IssueFactory.create(status=creation_status,
                                   project=creation_status.project,
                                   owner=creation_status.project.owner)
    payload = {
        "commits": [
            {
                "message":
                """test message
            test   TG-%s    #%s   ok
            test   TG-%s    #%s   ok
            bye!
        """ % (issue1.ref, new_status.slug, issue2.ref, new_status.slug)
            },
        ]
    }
    mail.outbox = []
    ev_hook1 = event_hooks.PushEventHook(issue1.project, payload)
    ev_hook1.process_event()
    issue1 = Issue.objects.get(id=issue1.id)
    issue2 = Issue.objects.get(id=issue2.id)
    assert issue1.status.id == new_status.id
    assert issue2.status.id == new_status.id
    assert len(mail.outbox) == 2
def test_push_event_user_story_processing(client):
    creation_status = f.UserStoryStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_us"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.UserStoryStatusFactory(project=creation_status.project)
    user_story = f.UserStoryFactory.create(status=creation_status,
                                           project=creation_status.project,
                                           owner=creation_status.project.owner)
    payload = {
        "commits": [
            {
                "message":
                """test message
            test   TG-%s    #%s   ok
            bye!
        """ % (user_story.ref, new_status.slug)
            },
        ]
    }

    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(user_story.project, payload)
    ev_hook.process_event()
    user_story = UserStory.objects.get(id=user_story.id)
    assert user_story.status.id == new_status.id
    assert len(mail.outbox) == 1
Exemplo n.º 7
0
def test_push_event_task_processing(client):
    creation_status = f.TaskStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_tasks"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.TaskStatusFactory(project=creation_status.project)
    task = f.TaskFactory.create(status=creation_status,
                                project=creation_status.project,
                                owner=creation_status.project.owner)
    payload = {
        "commits": [{
            "message":
            """test message
            test   TG-%s    #%s   ok
            bye!
        """ % (task.ref, new_status.slug),
            "id":
            123,
            "url":
            "http://gitlab.com/test/project/issues/123",
        }]
    }
    mail.outbox = []
    ev_hook = event_hooks.PushEventHook(task.project, payload)
    ev_hook.process_event()
    task = Task.objects.get(id=task.id)
    assert task.status.id == new_status.id
    assert len(mail.outbox) == 1
Exemplo n.º 8
0
def test_push_event_task_bad_processing_non_existing_ref(client):
    issue_status = f.IssueStatusFactory()
    payload = {"commits": [
        {"message": """test message
            test   TG-6666666    #%s   ok
            bye!
        """ % (issue_status.slug)},
    ]}
    mail.outbox = []

    ev_hook = event_hooks.PushEventHook(issue_status.project, payload)
    with pytest.raises(ActionSyntaxException) as excinfo:
        ev_hook.process_event()

    assert str(excinfo.value) == "The referenced element doesn't exist"
    assert len(mail.outbox) == 0
Exemplo n.º 9
0
def test_push_event_bad_processing_non_existing_status(client):
    issue = f.IssueFactory.create()
    payload = {"commits": [
        {"message": """test message
            test   TG-%s    #non-existing-slug   ok
            bye!
        """ % (issue.ref)},
    ]}

    mail.outbox = []

    ev_hook = event_hooks.PushEventHook(issue.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
Exemplo n.º 10
0
def test_push_event_task_bad_processing_non_existing_ref(client):
    issue_status = f.IssueStatusFactory()
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   TG-6666666    #%s   ok
            bye!
        """ % (issue_status.slug),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]
    payload["total_commits_count"] = 1
    mail.outbox = []

    ev_hook = event_hooks.PushEventHook(issue_status.project, payload)
    with pytest.raises(ActionSyntaxException) as excinfo:
        ev_hook.process_event()

    assert str(excinfo.value) == "The referenced element doesn't exist"
    assert len(mail.outbox) == 0
Exemplo n.º 11
0
def test_push_event_us_bad_processing_non_existing_status(client):
    user_story = f.UserStoryFactory.create()
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   TG-%s    #non-existing-slug   ok
            bye!
        """ % (user_story.ref),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]
    payload["total_commits_count"] = 1

    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
Exemplo n.º 12
0
def test_push_event_multiple_actions(client):
    creation_status = f.IssueStatusFactory()
    role = f.RoleFactory(project=creation_status.project,
                         permissions=["view_issues"])
    f.MembershipFactory(project=creation_status.project,
                        role=role,
                        user=creation_status.project.owner)
    new_status = f.IssueStatusFactory(project=creation_status.project)
    issue1 = f.IssueFactory.create(status=creation_status,
                                   project=creation_status.project,
                                   owner=creation_status.project.owner)
    issue2 = f.IssueFactory.create(status=creation_status,
                                   project=creation_status.project,
                                   owner=creation_status.project.owner)
    payload = deepcopy(push_base_payload)
    payload["commits"] = [{
        "message":
        """test message
            test   TG-%s    #%s   ok
            test   TG-%s    #%s   ok
            bye!
        """ % (issue1.ref, new_status.slug, issue2.ref, new_status.slug),
        "id":
        "b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
        "url":
        "http://example.com/mike/diaspora/commit/b6568db1bc1dcd7f8b4d5a946b0b91f9dacd7327",
    }]
    payload["total_commits_count"] = 1
    mail.outbox = []
    ev_hook1 = event_hooks.PushEventHook(issue1.project, payload)
    ev_hook1.process_event()
    issue1 = Issue.objects.get(id=issue1.id)
    issue2 = Issue.objects.get(id=issue2.id)
    assert issue1.status.id == new_status.id
    assert issue2.status.id == new_status.id
    assert len(mail.outbox) == 2
Exemplo n.º 13
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),
            "id":
            123,
            "url":
            "http://gitlab.com/test/project/issues/123",
        }]
    }

    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