-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
697d378
commit b4cd97b
Showing
1 changed file
with
49 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,79 @@ | ||
import os | ||
from typing import Sequence | ||
|
||
from dotenv import load_dotenv | ||
from jira import Issue | ||
from pytest import fixture | ||
import pytest | ||
|
||
from intelligence_layer.connectors.jira.jira_adapter import JiraAdapter | ||
|
||
PROJECT_ID = "TPIJAJW" | ||
|
||
@fixture | ||
def jira_adapter() -> JiraAdapter: | ||
load_dotenv() | ||
return JiraAdapter() | ||
|
||
def setup(jira_adapter: JiraAdapter) -> Sequence[Issue]: | ||
issues = jira_adapter.jira.search_issues(f"project={PROJECT_ID}") | ||
for issue in issues: | ||
issue.delete() | ||
|
||
@fixture | ||
def project_id() -> str: | ||
project_id = os.environ.get("JIRA_PROJECT_ID") | ||
assert project_id | ||
return project_id | ||
|
||
|
||
def setup(jira_adapter: JiraAdapter, project_id: str) -> Sequence[Issue]: | ||
old_issues = jira_adapter.jira.search_issues(f"project={project_id}") | ||
for issue in old_issues: | ||
assert isinstance(issue, Issue) | ||
issue.delete() # type: ignore | ||
|
||
issues = [] | ||
issues.append(jira_adapter.jira.create_issue(project=PROJECT_ID, summary='New issue 1 from jira-python', | ||
description='Look into this one', issuetype={'name': 'Bug'})) | ||
|
||
issues.append(jira_adapter.jira.create_issue(project=PROJECT_ID, summary='New issue 2 from jira-python', | ||
description='Look into this one', issuetype={'name': 'Bug'})) | ||
|
||
issues.append( | ||
jira_adapter.jira.create_issue( | ||
project=project_id, | ||
summary="New issue 1 from jira-python", | ||
description="Look into this one", | ||
issuetype={"name": "Bug"}, | ||
) | ||
) | ||
|
||
issues.append( | ||
jira_adapter.jira.create_issue( | ||
project=project_id, | ||
summary="New issue 2 from jira-python", | ||
description="Look into this one", | ||
issuetype={"name": "Bug"}, | ||
) | ||
) | ||
|
||
issue_dict = { | ||
'project': PROJECT_ID, | ||
'summary': 'New issue from jira-python', | ||
'description': 'Look into this one', | ||
'issuetype': {'name': 'Bug'}, | ||
"project": project_id, | ||
"summary": "New issue from jira-python", | ||
"description": "Look into this one", | ||
"issuetype": {"name": "Bug"}, | ||
} | ||
issues.append(jira_adapter.jira.create_issue(fields=issue_dict)) | ||
|
||
return issues | ||
|
||
def test_tickets(jira_adapter: JiraAdapter) -> None: | ||
issues = setup(jira_adapter) | ||
|
||
tickets = jira_adapter.tickets(PROJECT_ID) | ||
@pytest.mark.skip(reason="currently no CI User for Jira configured") | ||
def test_tickets(jira_adapter: JiraAdapter, project_id: str) -> None: | ||
issues = setup(jira_adapter, project_id) | ||
|
||
tickets = jira_adapter.tickets(project_id) | ||
|
||
issue_ids = [issue.id for issue in issues] | ||
assert len(issues) == len(tickets) | ||
for ticket in tickets: | ||
assert ticket.jira_id in issue_ids | ||
|
||
def test_tickets_by_id(jira_adapter: JiraAdapter) -> None: | ||
issues = setup(jira_adapter) | ||
@pytest.mark.skip(reason="currently no CI User for Jira configured") | ||
def test_tickets_by_id(jira_adapter: JiraAdapter, project_id: str) -> None: | ||
issues = setup(jira_adapter, project_id) | ||
ids = [issues[0].id, issues[1].id] | ||
|
||
tickets = jira_adapter.tickets_by_id(PROJECT_ID, ids) | ||
|
||
assert len(tickets) == 2 | ||
|
||
|
||
tickets = jira_adapter.tickets_by_id(project_id, ids) | ||
|
||
assert len(tickets) == 2 |