def test_missing_issues(): 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=1)) ]), "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="2", number=2, title="issue title") issues = {"2": issue} assert project.find_missing_issue_ids(issues) == {"2"}
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"
def parse_issue_card(card_edge: dict, config: Configuration): return { "id": card_edge.get('node', {}).get('id'), "cursor": card_edge['cursor'], "issue": Issue(**parse_issue(card_edge.get('node', {}).get('content')), priority_list=config.priority_list) }
def test_removing_issues(): 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=1)) ]), "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 class ClientMock(object): def delete_project_card(self, **kwargs): return project.remove_issues(ClientMock, config) assert project.get_all_issue_ids() == set()
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'
def construct_issue_object(self, github_issues): issues = {} for edge in github_issues: node_data = edge['node'] issue_labels = get_labels(node_data['labels']['edges']) if is_matching_issue(issue_labels, self.config.must_have_labels, self.config.cant_have_labels, self.config.filter_labels): issue = Issue(**parse_issue(node_data), priority_list=self.config.priority_list) issues[issue.id] = issue return issues
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=[ IssueCard(id="sdf", issue=Issue(id="sdf", title="issue 2", number=2, labels=["Low"])), IssueCard(id="sdf3", issue=Issue(id="sdf", title="issue 4", number=4, labels=["Medium" ])), IssueCard(id="sdf2", issue=Issue(id="sdf2", title="issue 3", number=3, labels=["High"])) ]) column_object.sort_cards(mock_client, config) card_titles_in_column = [card.issue.title for card in column_object.cards] assert card_titles_in_column == ['issue 3', "issue 4", 'issue 2']
def test_set_issue_to_issue_card(): issue_id = "=asdf=sdf=" title = "issue name" labels = ["HighEffort", "Low", "bug"] assignee = "ronykoz" issue = Issue(id=issue_id, number=1, title=title, labels=labels, assignees=[assignee]) card = IssueCard("id", issue=issue) assert card.id == 'id' assert card.issue == issue
def test_gt(): issue_id = "=asdf=sdf=" title = "issue name" labels = ["HighEffort", "Low", "bug"] assignee = "ronykoz" milestone = "test" issue = Issue(id=issue_id, number=1, title=title, labels=labels, assignees=[assignee], milestone=milestone) issue_id2 = "test" title2 = "issue name 2" labels2 = ["HighEffort", "bug"] issue2 = Issue( id=issue_id2, number=2, title=title2, labels=labels2, ) issue3 = Issue( id=issue_id2, number=3, title=title2, labels=labels2, ) assert issue2 < issue assert issue > issue2 assert issue2 > issue3 assert issue3 < issue2 < issue assert issue3 < issue
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
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
def test_no_priority_rank(): issue_id = "=asdf=sdf=" title = "issue name" labels = ["HighEffort", "bug"] assignees = ["ronykoz"] milestone = "test" number = 1 issue = Issue(id=issue_id, number=number, title=title, labels=labels, assignees=assignees, milestone=milestone) assert issue.id == issue_id assert issue.title == title assert issue.number == 1 assert sorted(issue.labels) == sorted(labels) assert issue.priority_rank == 0 assert issue.milestone == "test" assert issue.pull_request is None
def test_add_details(): issue_id = "=asdf=sdf=" title = "issue name" labels = ["HighEffort", "Low", "bug"] assignee = "ronykoz" milestone = "test" issue = Issue(id=issue_id, number=1, title=title, labels=labels, assignees=[assignee], milestone=milestone) issue.add_assignee("another one") assert sorted(issue.assignees) == sorted([assignee, "another one"]) labels_new = deepcopy(labels) issue.add_label("label") labels_new.append("label") assert sorted(issue.labels) == sorted(labels_new)
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=[ IssueCard(id="sdf", issue=Issue(id="sdf", title="issue 2", number=2, labels=["Low"])), IssueCard(id="sdf2", issue=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.issue.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.issue.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.issue.title for card in column_object.cards] assert card_titles_in_column == [ 'issue 5', 'issue 3', 'issue 4', 'issue 2' ] # Lower priority addition issue_to_inject3 = Issue(id="6", title="issue 6", number=6) column_object.add_card("id", issue_to_inject3, mock_client) card_titles_in_column = [card.issue.title for card in column_object.cards] assert card_titles_in_column == [ 'issue 5', 'issue 3', 'issue 4', 'issue 2', "issue 6" ] # Same priority different number issue_to_inject4 = Issue( id="7", title="issue 7", number=-1, ) column_object.add_card("id", issue_to_inject4, mock_client) card_titles_in_column = [card.issue.title for card in column_object.cards] assert card_titles_in_column == [ 'issue 5', 'issue 3', 'issue 4', 'issue 2', "issue 7", "issue 6" ]
def get_issue_object(self): issue_number = self.get_issue_number(self.event) issue_response = self.client.get_issue( self.project_owner, self.repository_name, issue_number) # need to address the remove here issue = Issue(**parse_issue(issue_response['repository']['issue'])) return issue
def test_get_matching_column(): config = Configuration(os.path.join(MOCK_FOLDER_PATH, 'conf.ini')) config.load_properties() issue_queue = Issue(id="1", title="issue 1", number=1) assert Project.get_matching_column(issue_queue, config) == 'Queue' issue_in_progress = Issue(id="1", title="issue 1", number=1) issue_in_progress.add_assignee("Rony") assert Project.get_matching_column(issue_in_progress, config) == '' issue_in_progress.add_label("Testing") assert Project.get_matching_column(issue_in_progress, config) == 'In progress' issue_review_in_progress = Issue(id="1", title="issue 1", number=1) issue_review_in_progress.add_assignee("Rony") class MockPullRequest(object): review_requested = True review_completed = False issue_review_in_progress.pull_request = MockPullRequest() assert Project.get_matching_column(issue_review_in_progress, config) == 'Review in progress' issue_docs = Issue(id="1", title="issue 1", number=1) issue_docs.add_assignee("Rony") class MockPullRequest2(object): review_requested = True review_completed = True assignees = "ronykoz" issue_docs.pull_request = MockPullRequest2() assert Project.get_matching_column(issue_docs, config) == 'Waiting for Docs' class MockPullRequest3(object): review_requested = True review_completed = True assignees = "someone" issue_docs.pull_request = MockPullRequest3() assert Project.get_matching_column(issue_docs, config) == 'Review in progress' # faulty field from issues config.column_to_rules["Waiting for Docs"] = { "issue.not_existent": "field" } assert Project.get_matching_column(issue_docs, config) == 'Review in progress'
def test_issue_params(): issue_id = "=asdf=sdf=" title = "issue name" labels = ["HighEffort", "Low", "bug"] assignee = "ronykoz" issue = Issue(**parse_issue({ "projectCards": { "nodes": [{ "id": "id=", "project": { "number": 1, "columns": { "nodes": [{ "name": "testing" }] } } }, { "id": "id2=", "project": { "number": 2, "columns": { "nodes": [{ "name": "Queue" }] } } }] }, "timelineItems": { "__typename": "IssueTimelineItemsConnection", "nodes": [{ "willCloseTarget": True, "source": { "__typename": "PullRequest", "state": "OPEN", "isDraft": False, "assignees": { "nodes": [{ "login": "******" }, { "login": "******" }] }, "labels": { "nodes": [{ "name": "label" }] }, "reviewRequests": { "totalCount": 0 }, "reviews": { "totalCount": 3 }, "number": 1, "reviewDecision": "APPROVED" } }] }, "title": title, "id": issue_id, "number": 1, "milestone": { "title": "test" }, "labels": { "edges": [{ "node": { "name": labels[0] } }, { "node": { "name": labels[1] } }, { "node": { "name": labels[2] } }] }, "assignees": { "edges": [{ "node": { "login": assignee } }] } })) assert issue.id == issue_id assert issue.title == title assert issue.number == 1 assert sorted(issue.labels) == sorted(labels) assert issue.priority_rank == 1 assert issue.milestone == "test" assert sorted(issue.get_associated_project()) == [1, 2] assert issue.get_card_id_from_project(1) == 'id=' assert issue.get_card_id_from_project(2) == 'id2=' assert issue.get_card_id_from_project(3) is None assert issue.pull_request.number == 1 assert issue.pull_request.assignees == ['test', 'test2']