1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
from __future__ import annotations
from collections.abc import Iterator
from contextlib import contextmanager
from functools import cached_property
from parameterized import parameterized
from jira.resources import Issue
from tests.conftest import JiraTestCase, rndstr
class EpicTests(JiraTestCase):
def setUp(self):
JiraTestCase.setUp(self)
self.issue_1 = self.test_manager.project_b_issue1
self.issue_2 = self.test_manager.project_b_issue2
self.epic_name: str = "My epic " + rndstr()
@cached_property
def epic_field_name(self):
"""The 'Epic Name' Custom field number. `customfield_X`."""
field_name = "Epic Name"
# Only Jira Server has a separate endpoint for custom fields!
# Jira Cloud gets them automatically with self.jira.fields()
custom_fields_json = self.jira._get_json("customFields")
all_custom_fields = custom_fields_json["values"]
epic_name_cf = [c for c in all_custom_fields if c["name"] == field_name][0]
return f"customfield_{epic_name_cf['numericId']}"
@contextmanager
def make_epic(self, **kwargs) -> Iterator[Issue]:
try:
# TODO: create_epic() method should exist!
new_epic = self.jira.create_issue(
fields={
"issuetype": {"name": "Epic"},
"project": self.project_b,
self.epic_field_name: self.epic_name,
"summary": f"Epic summary for '{self.epic_name}'",
},
)
if len(kwargs):
raise ValueError("Incorrect kwarg used !")
yield new_epic
finally:
new_epic.delete()
def test_epic_create_delete(self):
with self.make_epic():
pass
@parameterized.expand(
[("str", str), ("list", list)],
)
def test_add_issues_to_epic(self, name: str, input_type):
issue_list = [self.issue_1, self.issue_2]
with self.make_epic() as new_epic:
self.jira.add_issues_to_epic(
new_epic.id,
",".join(issue_list) if input_type == str else issue_list, # noqa: E721
)
|