Skip to content

Commit 3932f51

Browse files
committed
Fixes #13
+ unittest
1 parent ae026f8 commit 3932f51

File tree

4 files changed

+32
-4
lines changed

4 files changed

+32
-4
lines changed

joft/actions.py

+8-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ def create_ticket(
2323

2424
logging.info(f"New Jira ticket created: {new_issue.permalink()}")
2525

26-
reference_pool[action.object_id] = new_issue
26+
if action.object_id:
27+
reference_pool[action.object_id] = new_issue
2728

2829

2930
# TODO jira_session is not needed here. Maybe remove?
@@ -53,6 +54,9 @@ def update_ticket(
5354

5455
logging.info(f"Ticket '{ticket_to.key}' updated.")
5556

57+
if action.object_id:
58+
reference_pool[action.object_id] = ticket_to
59+
5660

5761
def link_issues(
5862
action: joft.models.LinkIssuesAction,
@@ -105,3 +109,6 @@ def transition_issue(
105109
jira_session.transition_issue(
106110
ticket_to, action.transition, action.fields, action.comment
107111
)
112+
113+
if action.object_id:
114+
reference_pool[action.object_id] = ticket_to

joft/base.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ def validate_uniqueness_of_object_ids(jira_template: joft.models.JiraTemplate) -
148148
object_ids.append(jira_template.jira_search.object_id)
149149

150150
for action in jira_template.jira_actions:
151-
object_ids.append(action.object_id)
151+
if action.object_id:
152+
object_ids.append(action.object_id)
152153

153154
# check if all the object ids are unique
154155
if len(object_ids) != len(set(object_ids)):

joft/models.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ class ReferenceData:
1919
class Action:
2020
# required fields
2121
type: str
22-
object_id: str
2322
fields: typing.Dict[str, typing.Any]
2423

2524
def reuse_data_must_be_list(self, reuse_data):
@@ -34,6 +33,7 @@ def reuse_data_must_be_list(self, reuse_data):
3433
@dataclasses.dataclass(kw_only=True)
3534
class CreateTicketAction(Action):
3635
reuse_data: dataclasses.InitVar[typing.List[ReferenceData] | None] = None
36+
object_id: str | None = None
3737

3838
reference_data: typing.List[ReferenceData] = dataclasses.field(default_factory=list)
3939

@@ -48,6 +48,7 @@ def __post_init__(self, reuse_data):
4848
@dataclasses.dataclass(kw_only=True)
4949
class UpdateTicketAction(Action):
5050
reference_id: str
51+
object_id: str | None = None
5152
reuse_data: dataclasses.InitVar[typing.List[ReferenceData] | None] = None
5253

5354
reference_data: typing.List[ReferenceData] = dataclasses.field(default_factory=list)
@@ -63,6 +64,7 @@ def __post_init__(self, reuse_data):
6364
@dataclasses.dataclass(kw_only=True)
6465
class LinkIssuesAction(Action):
6566
reuse_data: dataclasses.InitVar[typing.List[ReferenceData] | None] = None
67+
object_id: str | None = None
6668

6769
reference_data: typing.List[ReferenceData] = dataclasses.field(default_factory=list)
6870

@@ -79,6 +81,7 @@ class TransitionAction(Action):
7981
reference_id: str
8082
transition: str
8183
comment: str
84+
object_id: str | None = None
8285
reuse_data: dataclasses.InitVar[typing.List[ReferenceData] | None] = None
8386

8487
reference_data: typing.List[ReferenceData] = dataclasses.field(default_factory=list)

tests/test_base.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99

1010

1111
def _setup_jira_template_yaml(
12-
duplicate_id: bool = False, invalid_action: bool = False
12+
duplicate_id: bool = False,
13+
invalid_action: bool = False,
14+
no_object_ids: bool = False,
1315
) -> dict[str, typing.Any]:
1416
"""Setup function that provides different types of yaml structures"""
1517

@@ -63,6 +65,10 @@ def _setup_jira_template_yaml(
6365
if invalid_action:
6466
jira_template_yaml["actions"][0]["type"] = "invalid_action"
6567

68+
if no_object_ids:
69+
for action in jira_template_yaml["actions"]:
70+
action.pop("object_id", None)
71+
6672
return jira_template_yaml
6773

6874

@@ -350,3 +356,14 @@ def test_validate_template_success(
350356
assert ret_code == 0
351357
mock_load_and_parse_yaml.assert_called_once_with(yaml_file_path)
352358
mock_validate_uniqueness_object_ids.assert_called_once_with(jira_template)
359+
360+
361+
def test_object_id_not_present() -> None:
362+
"""Test that Object IDs are optional, but still present in the dataclasses with
363+
None value"""
364+
365+
jira_template_yaml = _setup_jira_template_yaml(no_object_ids=True)
366+
jira_template = joft.models.JiraTemplate(**jira_template_yaml)
367+
368+
for action in jira_template.jira_actions:
369+
assert not action.object_id

0 commit comments

Comments
 (0)