Esempio n. 1
0
def test_missing_items():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()
    project = Project(
        name="test project",
        config=config,
        columns={
            "Queue": ProjectColumn(id="id", name="Queue",
                                   cards=[ItemCard(id="sdf",
                                                   item=Issue(id="sdf", title="title", number=1))]),
            "Review in progress": ProjectColumn(id="id", name="Review in progress",
                                                cards=[])
        }
    )

    assert len(project.get_all_item_ids()) == 1
    assert len(project.columns.keys()) == 2

    issue = Issue(
        id="2",
        number=2,
        title="issue title"
    )
    issues = {
        "2": issue
    }
    assert project.find_missing_item_ids(issues) == {"2"}
Esempio n. 2
0
def test_removing_items():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()
    project = Project(
        name="test project",
        config=config,
        columns={
            "Queue": ProjectColumn(id="id", name="Queue",
                                   cards=[ItemCard(id="sdf",
                                                   item=Issue(id="sdf", title="title", number=1)),
                                          ItemCard(id="sdff",
                                                   item=PullRequest(id="sdff", title="title", number=2))]),
            "Review in progress": ProjectColumn(id="id", name="Review in progress",
                                                cards=[])
        }
    )

    assert len(project.get_all_item_ids()) == 2
    assert len(project.columns.keys()) == 2

    class ClientMock(object):
        def delete_project_card(self, **kwargs):
            return

    project.remove_items(ClientMock, config)
    assert project.get_all_item_ids() == set()
Esempio n. 3
0
def test_sort_column():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()

    class MockClient(object):
        def add_to_column(*args, **kwargs):
            return

        def move_to_specific_place_in_column(*args, **kwargs):
            return

    mock_client = MockClient()
    # Sorting
    config.priority_list = DEFAULT_PRIORITY_LIST
    column_object = ProjectColumn(
        id="id", name="Review in progress",
        cards=[
            ItemCard(id="sdf",
                     item=Issue(id="sdf", title="issue 2", number=2, labels=["Low"])),
            ItemCard(id="sdf3",
                     item=Issue(id="sdf", title="issue 4", number=4, labels=["Medium"])),
            ItemCard(id="sdf2",
                     item=PullRequest(id="sdf2", title="pull request 3", number=3, labels=["High"])),
        ])

    column_object.sort_cards(mock_client, config)
    card_titles_in_column = [card.item.title for card in column_object.cards]

    assert card_titles_in_column == ['pull request 3', "issue 4", 'issue 2']
Esempio n. 4
0
def test_project_empty_card():
    project = Project(
        name="test project",
        config=Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini')),
        columns={
            "Queue":
            ProjectColumn(id="id",
                          name="Queue",
                          cards=[
                              IssueCard(id="sdf",
                                        issue=Issue(id="sdf",
                                                    title="title",
                                                    number=1))
                          ]),
            "Review in progress":
            ProjectColumn(id="id", name="Review in progress", cards=[])
        })

    assert project.name == "test project"
    assert len(project.get_all_issue_ids()) == 1
    assert len(project.columns.keys()) == 2

    assert project.columns['Queue'].name == 'Queue'

    assert project.columns['Review in progress'].name == 'Review in progress'
Esempio n. 5
0
def test_adding_issue():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()
    project = Project(name="test project",
                      config=config,
                      columns={
                          "Queue":
                          ProjectColumn(id="id",
                                        name="Queue",
                                        cards=[
                                            IssueCard(id="sdf",
                                                      issue=Issue(
                                                          id="sdf",
                                                          title="title",
                                                          number=2))
                                        ]),
                          "Review in progress":
                          ProjectColumn(id="id",
                                        name="Review in progress",
                                        cards=[])
                      })

    assert len(project.get_all_issue_ids()) == 1
    assert len(project.columns.keys()) == 2

    issue = Issue(id="1", number=1, title="Rony")
    assert issue.priority_rank == 0
    issues = {"1": issue}

    class ClientMock(object):
        def add_issues_to_project(*args, **kwargs):
            return {'addProjectCard': {'cardEdge': {'node': {'id': "1"}}}}

        def add_to_column(*args, **kwargs):
            return

        def move_to_specific_place_in_column(*args, **kwargs):
            return

    project.add_issues(ClientMock, issues, {"1"}, config)
    assert project.columns['Queue'].cards[0].issue.title == "Rony"

    # testing non existent column
    with pytest.raises(Exception) as err:
        project.add_issue(ClientMock, issue, "non existent", config)
        assert "Did not found a matching column" in err

    issue2 = Issue(id="1",
                   number=1,
                   title="Rony",
                   card_id_to_project={"1": {
                       "project_number": 1
                   }})
    issues2 = {"2": issue2}
    project.add_issues(ClientMock, issues2, {"2"}, config)
    assert project.columns['Queue'].cards[0].issue.title == "Rony"
Esempio n. 6
0
def test_move_issues():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()
    issue = Issue(id="1",
                  title="title",
                  number=1,
                  assignees=["Rony"],
                  labels=["Testing"],
                  card_id_to_project={"sdf": {
                      "project_number": 1
                  }})
    project = Project(name="test project",
                      config=config,
                      columns={
                          "Queue":
                          ProjectColumn(
                              id="id",
                              name="Queue",
                              cards=[IssueCard(id="sdf", issue=issue)]),
                          "In progress":
                          ProjectColumn(id="id", name="In progress", cards=[])
                      })

    class MockClient(object):
        def add_to_column(*args, **kwargs):
            return

        def move_to_specific_place_in_column(*args, **kwargs):
            return

    project.move_issues(MockClient(), config)
    assert project.is_in_column("Queue", "1") is False
    assert project.is_in_column("In progress", "1") is True

    # Move within the same column
    project.move_issues(MockClient(), config)
    assert project.is_in_column("Queue", "1") is False
    assert project.is_in_column("In progress", "1") is True
Esempio n. 7
0
def test_event_manager_flow(mocker):
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()

    project_object = Project(name="project_name",
                             columns={
                                 "In progress":
                                 ProjectColumn(id="some id",
                                               name='In progress',
                                               cards=[])
                             },
                             config=config)
    mocker.patch.object(EventManager,
                        "get_issue_object",
                        return_value=Issue(id="1",
                                           title="this is a test title",
                                           number=1,
                                           assignees=["ronykoz"],
                                           labels=['test', 'Testing', 'bug']))
    mocker.patch.object(EventManager,
                        "load_project_column",
                        return_value=project_object)

    class MockClient(object):
        def add_issues_to_project(*args, **kwargs):
            return {"addProjectCard": {"cardEdge": {"node": {"id": "1"}}}}

        def add_to_column(self, **kwargs):
            return

        def move_to_specific_place_in_column(self, **kwargs):
            return

    client = MockClient()
    manager = EventManager(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'),
                           client=client,
                           event=json.dumps({"text": "text"}))
    manager.run()
    assert len(project_object.get_all_issue_ids()) == 1
Esempio n. 8
0
def test_move_items():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()
    issue = Issue(id="1",
                  title="title",
                  number=1,
                  assignees=["Rony"],
                  labels=["Testing"],
                  card_id_to_project={
                      "sdf": {
                          "project_number": 1
                      }
                  }
                  )
    pull_request = PullRequest(id="10",
                               title="title",
                               number=10,
                               assignees=["Daud"],
                               labels=["Testing"],
                               card_id_to_project={
                                   "dsf": {
                                       "project_number": 1
                                   }
                               })
    project = Project(
        name="test project",
        config=config,
        columns={
            "Queue": ProjectColumn(id="id", name="Queue",
                                   cards=[ItemCard(id="sdf",
                                                   item=issue),
                                          ItemCard(id="dsf",
                                                   item=pull_request)
                                          ]),
            "In progress": ProjectColumn(id="id", name="In progress", cards=[])
        }
    )

    class MockClient(object):
        def add_to_column(*args, **kwargs):
            return

        def move_to_specific_place_in_column(*args, **kwargs):
            return

    project.move_items(MockClient(), config, {'1': issue})
    assert project.is_in_column("Queue", "1") is False
    assert project.is_in_column("In progress", "1") is True

    project.move_items(MockClient(), config, {'10': pull_request})
    assert project.is_in_column("Queue", "10") is False
    assert project.is_in_column("In progress", "10") is True

    # Move within the same column
    project.move_items(MockClient(), config, {'1': issue})
    assert project.is_in_column("Queue", "1") is False
    assert project.is_in_column("In progress", "1") is True

    issue.state = 'closed'
    project.move_item(MockClient(), issue, 'In progress', config)
    assert project.is_in_column("In progress", "1") is True
Esempio n. 9
0
def test_add_card_to_column():
    config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini'))
    config.load_properties()

    config.priority_list = DEFAULT_PRIORITY_LIST
    column_object = ProjectColumn(id="id", name="Review in progress",
                                  cards=[
                                      ItemCard(id="sdf",
                                               item=Issue(id="sdf", title="issue 2", number=2, labels=["Low"])),
                                      ItemCard(id="sdf2",
                                               item=Issue(id="sdf2", title="issue 3", number=3, labels=["High"]))
                                  ])
    issue_to_inject = Issue(
        id="4",
        title="issue 4",
        number=4,
        labels=['Medium']
    )
    issue_to_inject.set_priority(DEFAULT_PRIORITY_LIST)

    class MockClient(object):
        def add_to_column(*args, **kwargs):
            return

        def move_to_specific_place_in_column(*args, **kwargs):
            return

    mock_client = MockClient()

    # Sorting
    column_object.sort_cards(mock_client, config)
    card_titles_in_column = [card.item.title for card in column_object.cards]
    assert card_titles_in_column == ['issue 3', 'issue 2']

    # Adding in the middle
    column_object.add_card("id", issue_to_inject, mock_client)
    card_titles_in_column = [card.item.title for card in column_object.cards]
    assert card_titles_in_column == ['issue 3', 'issue 4', 'issue 2']

    # Higher priority addition
    issue_to_inject2 = Issue(
        id="5",
        title="issue 5",
        number=5,
        labels=['Critical']
    )
    issue_to_inject2.set_priority(DEFAULT_PRIORITY_LIST)

    column_object.add_card("id", issue_to_inject2, mock_client)
    card_titles_in_column = [card.item.title for card in column_object.cards]
    assert card_titles_in_column == ['issue 5', 'issue 3', 'issue 4', 'issue 2']

    # Lower priority addition
    pr_to_inject3 = PullRequest(
        id="6",
        title="pull request 6",
        number=6
    )

    column_object.add_card("id", pr_to_inject3, mock_client)
    card_titles_in_column = [card.item.title for card in column_object.cards]
    assert card_titles_in_column == ['issue 5', 'issue 3', 'issue 4', 'issue 2', "pull request 6"]

    # Same priority different number
    pr_to_inject4 = PullRequest(
        id="7",
        title="pull request 7",
        number=-1,
    )

    column_object.add_card("id", pr_to_inject4, mock_client)
    card_titles_in_column = [card.item.title for card in column_object.cards]
    assert card_titles_in_column == ['issue 5', 'issue 3', 'issue 4', 'issue 2', "pull request 7", "pull request 6"]