Skip to content

Commit

Permalink
Make TestJiraSensor more robust
Browse files Browse the repository at this point in the history
The sample ticket object used in the test is mocked more realistically and the original field_checker_func is used.
  • Loading branch information
kianelbo committed Jun 20, 2022
1 parent 17c1b98 commit 2f4589d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions tests/providers/jira/sensors/test_jira.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,22 @@
DEFAULT_DATE = timezone.datetime(2017, 1, 1)
jira_client_mock = Mock(name="jira_client_for_test")

minimal_test_ticket = {
"id": "911539",
"self": "https://sandbox.localhost/jira/rest/api/2/issue/911539",
"key": "TEST-1226",
"fields": {
"labels": ["test-label-1", "test-label-2"],
"description": "this is a test description",
},
}

class _MockJiraTicket(dict):
class _TicketFields:
labels = ["test-label-1", "test-label-2"]
description = "this is a test description"

fields = _TicketFields


minimal_test_ticket = _MockJiraTicket(
{
"id": "911539",
"self": "https://sandbox.localhost/jira/rest/api/2/issue/911539",
"key": "TEST-1226",
}
)


class TestJiraSensor(unittest.TestCase):
Expand All @@ -62,7 +69,8 @@ def test_issue_label_set(self, jira_mock):
method_name='issue',
task_id='search-ticket-test',
ticket_id='TEST-1226',
field_checker_func=TestJiraSensor.field_checker_func,
field='labels',
expected_value='test-label-1',
timeout=518400,
poke_interval=10,
dag=self.dag,
Expand All @@ -72,7 +80,3 @@ def test_issue_label_set(self, jira_mock):

assert jira_mock.called
assert jira_mock.return_value.issue.called

@staticmethod
def field_checker_func(issue):
return "test-label-1" in issue['fields']['labels']

0 comments on commit 2f4589d

Please sign in to comment.