Skip to content

Commit

Permalink
add tests for draft/wip status and update UDA
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Gallegos <[email protected]>
  • Loading branch information
thekad committed Feb 16, 2024
1 parent 88601e0 commit 8cacbf1
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 17 deletions.
2 changes: 1 addition & 1 deletion tests/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
45 changes: 33 additions & 12 deletions tests/test_gerrit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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': [],
Expand All @@ -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(
Expand All @@ -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': []}
Expand Down
43 changes: 39 additions & 4 deletions tests/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
'updated_at': ARBITRARY_UPDATED.isoformat(),
'repo': 'arbitrary_username/arbitrary_repo',
'state': 'closed',
'draft': True,
'draft': False,
}
ARBITRARY_EXTRA = {
'project': 'one',
Expand All @@ -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})
Expand All @@ -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'],
Expand All @@ -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()

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 8cacbf1

Please sign in to comment.