From 8cacbf10c09cd3e1ab1ce32860e0cb2eb97ee42a Mon Sep 17 00:00:00 2001 From: Jorge Gallegos Date: Thu, 15 Feb 2024 17:56:17 -0800 Subject: [PATCH] add tests for draft/wip status and update UDA Signed-off-by: Jorge Gallegos --- tests/test_db.py | 2 +- tests/test_gerrit.py | 45 ++++++++++++++++++++++++++++++++------------ tests/test_github.py | 43 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 73 insertions(+), 17 deletions(-) diff --git a/tests/test_db.py b/tests/test_db.py index f163d20b..b63ab794 100644 --- a/tests/test_db.py +++ b/tests/test_db.py @@ -227,7 +227,7 @@ def test_udas(self): 'uda.githubcreatedon.label=Github Created', 'uda.githubcreatedon.type=date', 'uda.githubdraft.label=GitHub Draft', - 'uda.githubdraft.type=string', + 'uda.githubdraft.type=numeric', 'uda.githubmilestone.label=Github Milestone', 'uda.githubmilestone.type=string', 'uda.githubnamespace.label=Github Namespace', diff --git a/tests/test_gerrit.py b/tests/test_gerrit.py index 44c8b08d..b55437dc 100644 --- a/tests/test_gerrit.py +++ b/tests/test_gerrit.py @@ -20,13 +20,20 @@ class TestGerritIssue(AbstractServiceTest, ServiceTest): 'branch': 'master', 'topic': 'test-topic', 'status': 'new', - 'work_in_progress': True, + 'work_in_progress': False, 'subject': 'this is a title', 'messages': [{'author': {'username': 'Iam Author'}, 'message': 'this is a message', '_revision_number': 1}], } + extra = { + 'annotations': [ + # TODO - test annotations? + ], + 'url': 'https://one.com/#/c/1/', + } + def setUp(self): super().setUp() @@ -38,14 +45,7 @@ def setUp(self): self.service = self.get_mock_service(GerritService) def test_to_taskwarrior(self): - extra = { - 'annotations': [ - # TODO - test annotations? - ], - 'url': 'this is a url', - } - - issue = self.service.get_issue_for_record(self.record, extra) + issue = self.service.get_issue_for_record(self.record, self.extra) actual = issue.to_taskwarrior() expected = { 'annotations': [], @@ -54,15 +54,36 @@ def test_to_taskwarrior(self): 'gerritid': 1, 'gerritstatus': 'new', 'gerritsummary': 'this is a title', - 'gerriturl': 'this is a url', + 'gerriturl': 'https://one.com/#/c/1/', 'gerritbranch': 'master', 'gerrittopic': 'test-topic', - 'gerritwip': 'wip', + 'gerritwip': 0, 'tags': [], } self.assertEqual(actual, expected) + def test_work_in_progress(self): + wip_record = dict(self.record) # make a copy of the dict + wip_record['work_in_progress'] = True + issue = self.service.get_issue_for_record(wip_record, self.extra) + + expected = { + 'annotations': [], + 'description': '(bw)PR#1 - this is a title .. https://one.com/#/c/1/', + 'gerritid': 1, + 'gerritsummary': 'this is a title', + 'gerritstatus': 'new', + 'gerriturl': 'https://one.com/#/c/1/', + 'gerritbranch': 'master', + 'gerrittopic': 'test-topic', + 'gerritwip': 1, + 'priority': 'M', + 'project': 'nova', + 'tags': []} + + self.assertEqual(issue.get_taskwarrior_record(), expected) + @responses.activate def test_issues(self): self.add_response( @@ -81,7 +102,7 @@ def test_issues(self): 'gerriturl': 'https://one.com/#/c/1/', 'gerritbranch': 'master', 'gerrittopic': 'test-topic', - 'gerritwip': 'wip', + 'gerritwip': 0, 'priority': 'M', 'project': 'nova', 'tags': []} diff --git a/tests/test_github.py b/tests/test_github.py index c670aa1d..c387929d 100644 --- a/tests/test_github.py +++ b/tests/test_github.py @@ -32,7 +32,7 @@ 'updated_at': ARBITRARY_UPDATED.isoformat(), 'repo': 'arbitrary_username/arbitrary_repo', 'state': 'closed', - 'draft': True, + 'draft': False, } ARBITRARY_EXTRA = { 'project': 'one', @@ -52,6 +52,41 @@ class TestGithubIssue(AbstractServiceTest, ServiceTest): 'username': 'arbitrary_username', } + def test_draft(self): + service = self.get_mock_service(GithubService) + draft = dict(ARBITRARY_ISSUE) + draft['draft'] = True + issue = service.get_issue_for_record( + draft, + ARBITRARY_EXTRA + ) + + expected = { + 'annotations': [], + 'description': '(bw)Is#10 - Hallo .. https://github.com/arbitrary_username/arbitrary_repo/pull/1', # noqa: E501 + 'entry': ARBITRARY_CREATED, + 'end': ARBITRARY_CLOSED, + 'githubbody': draft['body'], + 'githubcreatedon': ARBITRARY_CREATED, + 'githubclosedon': ARBITRARY_CLOSED, + 'githubdraft': int(draft['draft']), + 'githubmilestone': draft['milestone']['title'], + 'githubnamespace': draft['repo'].split('/')[0], + 'githubnumber': draft['number'], + 'githubrepo': draft['repo'], + 'githubtitle': draft['title'], + 'githubtype': 'issue', + 'githubupdatedat': ARBITRARY_UPDATED, + 'githuburl': draft['html_url'], + 'githubuser': draft['user']['login'], + 'githubstate': draft['state'], + 'priority': 'M', + 'project': ARBITRARY_EXTRA['project'], + 'tags': [] + } + + self.assertEqual(issue.get_taskwarrior_record(), expected) + def test_to_taskwarrior(self): service = self.get_mock_service(GithubService, config_overrides={ 'import_labels_as_tags': True}) @@ -69,6 +104,7 @@ def test_to_taskwarrior(self): 'end': ARBITRARY_CLOSED, issue.URL: ARBITRARY_ISSUE['html_url'], issue.REPO: ARBITRARY_ISSUE['repo'], + issue.DRAFT: ARBITRARY_ISSUE['draft'], issue.TYPE: ARBITRARY_EXTRA['type'], issue.TITLE: ARBITRARY_ISSUE['title'], issue.NUMBER: ARBITRARY_ISSUE['number'], @@ -80,7 +116,6 @@ def test_to_taskwarrior(self): issue.USER: ARBITRARY_ISSUE['user']['login'], issue.NAMESPACE: 'arbitrary_username', issue.STATE: 'closed', - issue.DRAFT: 'draft', } actual_output = issue.to_taskwarrior() @@ -128,7 +163,7 @@ def test_issues(self): 'githubbody': 'Something', 'githubcreatedon': ARBITRARY_CREATED, 'githubclosedon': ARBITRARY_CLOSED, - 'githubdraft': 'draft', + 'githubdraft': 0, 'githubmilestone': 'alpha', 'githubnamespace': 'arbitrary_username', 'githubnumber': 10, @@ -188,7 +223,7 @@ def test_issues(self): 'githubbody': 'Something', 'githubcreatedon': ARBITRARY_CREATED, 'githubclosedon': ARBITRARY_CLOSED, - 'githubdraft': 'draft', + 'githubdraft': 0, 'githubmilestone': 'alpha', 'githubnamespace': 'arbitrary_username', 'githubnumber': 10,