Skip to content

Commit

Permalink
tests: Add tests for JIRA input translation
Browse files Browse the repository at this point in the history
  • Loading branch information
lhh committed Jan 19, 2024
1 parent 52154fb commit 239138a
Show file tree
Hide file tree
Showing 3 changed files with 305 additions and 61 deletions.
16 changes: 15 additions & 1 deletion jirate/jira_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ def in_owc(value):
'priority': in_name,
'version': in_name,
'securitylevel': in_name,
'option-with-child': in_owc
'option-with-child': in_owc,
'user': in_string # When setting array, you specify 'name': name
# When setting assignee, you just give the name
# as a string
}


Expand Down Expand Up @@ -132,6 +135,17 @@ def transmogrify_value(value, field_info):

# Channelling ... Calvin
def transmogrify_input(field_definitions, **args):
""" Translate text input into something Jira understands natively when
pasting to the API.
Parameters:
field_definitions: Create/Update metadata or /field dictionary
args: User-provided key,value pairs (strings)
Returns:
Updated dictionary with JIRA field IDs and values corresponding to
metadata in field_definitions
"""
drop_fields = ['attachment', 'reporter', 'issuelinks'] # These are not set during create/update
simple_fields = ['project', 'issuetype'] # Don't process these fields at all
output = {}
Expand Down
212 changes: 152 additions & 60 deletions jirate/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,53 @@


fake_fields = [
{'clauseNames': ['priority', 'Priority'],
'custom': False,
'id': 'priority',
'name': 'Priority',
'schema': {'system': 'priority', 'type': 'priority'},
'allowedValues': [
{'id': 101,
'name': 'Blocker'},
{'id': 102,
'name': 'Critical'},
{'id': 103,
'name': 'Major'},
{'id': 104,
'name': 'Normal'},
{'id': 105,
'name': 'Minor'},
{'id': 106,
'name': 'Undefined'}],
'defaultValue': {'id': 104, 'name': 'Normal'},
'hasDefaultValue': True,
'operations': ['set']
},
{'clauseNames': ['description', 'Description'],
'custom': False,
'name': 'Description',
'id': 'description',
'required': True,
'operations': ['set'],
'schema': {'type': 'string'},
},
{'clauseNames': ['components', 'Component/s'],
'custom': False,
'id': 'components',
'name': 'Component/s',
'schema': {'system': 'items', 'type': 'array', 'items': 'component'},
'allowedValues': [
{'id': 1001,
'name': 'python'},
{'id': 1002,
'name': 'kernel'},
{'id': 1003,
'name': 'glibc'},
{'id': 1004,
'name': 'porkchop'}],
'operations': ['add', 'set', 'remove'],
'required': True
},
{'clauseNames': ['cf[1234567]', 'Fixed in Build'],
'custom': True,
'id': 'customfield_1234567',
Expand All @@ -17,6 +64,7 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:textfield',
'customId': 1234567,
'type': 'string'},
'operations': ['set'],
'searchable': True},
{'clauseNames': ['cf[1234568]', 'Score'],
'custom': True,
Expand All @@ -27,6 +75,7 @@
'schema': {'custom': 'org.jboss.labs.jira.plugin.jboss-custom-field-types-plugin:jbonlynumber',
'customId': 1234568,
'type': 'number'},
'operations': ['set'],
'searchable': True},
{'clauseNames': ['cf[1234569]', 'Array of Options'],
'custom': True,
Expand All @@ -38,6 +87,15 @@
'customId': 1234569,
'items': 'option',
'type': 'array'},
'allowedValues': [
{'value': 'One',
'id': '1'},
{'value': 'Two',
'id': '2'},
{'value': 'Three',
'id': '3'}
],
'operations': ['add', 'set', 'remove'],
'searchable': True},
{'clauseNames': ['cf[1234570]', 'Array of Versions'],
'custom': True,
Expand All @@ -49,6 +107,13 @@
'customId': 1234570,
'items': 'version',
'type': 'array'},
'allowedValues': [
{'name': '1.0.1',
'id': '11'},
{'name': '1.0.2',
'id': '12'}
],
'operations': ['add', 'set', 'remove'],
'searchable': True},
{'clauseNames': ['cf[1234571]', 'Array of Users'],
'custom': True,
Expand All @@ -60,6 +125,7 @@
'customId': 1234571,
'items': 'user',
'type': 'array'},
'operations': ['add', 'set', 'remove'],
'searchable': True},
{'clauseNames': ['cf[1234572]', 'Array of Strings'],
'custom': True,
Expand All @@ -71,6 +137,7 @@
'customId': 1234572,
'items': 'string',
'type': 'array'},
'operations': ['add', 'set', 'remove'],
'searchable': True},
{'clauseNames': ['cf[1234573]', 'Array of Groups'],
'custom': True,
Expand All @@ -92,6 +159,7 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234574,
'type': 'any'},
'operations': ['add', 'set', 'remove'],
'searchable': True},
{'clauseNames': ['cf[1234575]', 'Date Value'],
'custom': True,
Expand All @@ -102,6 +170,7 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234575,
'type': 'date'},
'operations': ['set'],
'searchable': True},
{'clauseNames': ['cf[1234576]', 'Datetime Value'],
'custom': True,
Expand All @@ -112,6 +181,7 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234576,
'type': 'datetime'},
'operations': ['set'],
'searchable': True},
{'clauseNames': ['cf[1234577]', 'Related Issue'],
'custom': True,
Expand All @@ -122,13 +192,23 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234577,
'type': 'issuelinks'},
'operations': ['set'],
'searchable': True},
{'clauseNames': ['cf[1234578]', 'Option Value'],
'custom': True,
'id': 'customfield_1234578',
'name': 'Option Value',
'navigable': True,
'orderable': True,
'operations': ['set'],
'allowedValues': [
{'value': 'One',
'id': '1'},
{'value': 'Two',
'id': '2'},
{'value': 'Three',
'id': '3'}
],
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234578,
'type': 'option'},
Expand All @@ -142,6 +222,14 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234579,
'type': 'option-with-child'},
'allowedValues': [
{'value': 'One',
'id': '1'},
{'value': 'Two',
'id': '2'},
{'value': 'Three',
'id': '3'}
],
'searchable': True},
{'clauseNames': ['cf[1234580]', 'User Value'],
'custom': True,
Expand All @@ -162,11 +250,20 @@
'schema': {'custom': 'com.atlassian.jira.plugin.system.customfieldtypes:multiselect',
'customId': 1234581,
'type': 'version'},
'allowedValues': [
{'name': '1.0.1',
'id': '11'},
{'name': '1.0.2',
'id': '12'}
],
'searchable': True}

]


fake_metadata = {val['id']: val for val in fake_fields}


fake_issues = {
'TEST-1': {'expand': 'renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations',
'fields': {'aggregateprogress': {'progress': 0, 'total': 0},
Expand Down Expand Up @@ -199,9 +296,7 @@
'subtask': False},
'labels': ['label1', 'label2'],
'lastViewed': '2023-11-22T15:51:50.281+0000',
'priority': {'id': '10200',
'name': 'Normal',
'self': 'https://domain.com/rest/api/2/priority/10200'},
'priority': {'id': '104', 'name': 'Normal'},
'progress': {'progress': 0, 'total': 0},
'project': {'id': '1234',
'key': 'TEST',
Expand Down Expand Up @@ -312,63 +407,60 @@
'subtask': False},
'labels': ['label2'],
'lastViewed': '2023-11-22T15:51:50.281+0000',
'priority': {
'id': '10200',
'name': 'Normal',
'self': 'https://domain.com/rest/api/2/priority/10200'},
'progress': {'progress': 0, 'total': 0},
'project': {'id': '1234',
'key': 'TEST',
'name': 'Test Project',
'projectCategory': {'description': 'Test Projects',
'id': '1073',
'name': 'Projecto',
'self': 'https://domain.com/rest/api/2/projectCategory/1073'},
'projectTypeKey': 'software',
'self': 'https://domain.com/rest/api/2/project/1234'},
'reporter': {'active': True,
'displayName': 'Pork Chop',
'emailAddress': '[email protected]',
'key': 'JIRAUSER1',
'name': '[email protected]',
'self': 'https://domain.com/rest/api/2/user?username=pchop%40domain.com',
'timeZone': 'Asia/Kolkata'},
'resolution': None,
'resolutiondate': None,
'security': None,
'status': {'description': 'Initial creation status. ',
'id': '10',
'name': 'New',
'self': 'https://domain.com/rest/api/2/status/10016',
'statusCategory': {'colorName': 'default',
'id': 2,
'key': 'new',
'name': 'To Do',
'self': 'https://domain.com/rest/api/2/statuscategory/2'}},
'subtasks': [],
'summary': 'Test 1',
'timeestimate': None,
'timeoriginalestimate': None,
'timespent': None,
'timetracking': {},
'updated': '2023-11-30T15:06:39.875+0000',
'versions': [{'archived': False,
'description': '',
'id': '6',
'name': 'version-6',
'released': False,
'self': 'https://domain.com/rest/api/2/version/6'}],
'votes': {'hasVoted': False,
'self': 'https://domain.com/rest/api/2/issue/TEST-1/votes',
'votes': 0},
'watches': {'isWatching': False,
'self': 'https://domain.com/rest/api/2/issue/TEST-1/watchers',
'watchCount': 2},
'worklog': {'maxResults': 20,
'startAt': 0,
'total': 0,
'worklogs': []},
'workratio': -1},
'priority': {'id': 104, 'name': 'Normal'},
'progress': {'progress': 0, 'total': 0},
'project': {'id': '1234',
'key': 'TEST',
'name': 'Test Project',
'projectCategory': {'description': 'Test Projects',
'id': '1073',
'name': 'Projecto',
'self': 'https://domain.com/rest/api/2/projectCategory/1073'},
'projectTypeKey': 'software',
'self': 'https://domain.com/rest/api/2/project/1234'},
'reporter': {'active': True,
'displayName': 'Pork Chop',
'emailAddress': '[email protected]',
'key': 'JIRAUSER1',
'name': '[email protected]',
'self': 'https://domain.com/rest/api/2/user?username=pchop%40domain.com',
'timeZone': 'Asia/Kolkata'},
'resolution': None,
'resolutiondate': None,
'security': None,
'status': {'description': 'Initial creation status. ',
'id': '10',
'name': 'New',
'self': 'https://domain.com/rest/api/2/status/10016',
'statusCategory': {'colorName': 'default',
'id': 2,
'key': 'new',
'name': 'To Do',
'self': 'https://domain.com/rest/api/2/statuscategory/2'}},
'subtasks': [],
'summary': 'Test 1',
'timeestimate': None,
'timeoriginalestimate': None,
'timespent': None,
'timetracking': {},
'updated': '2023-11-30T15:06:39.875+0000',
'versions': [{'archived': False,
'description': '',
'id': '6',
'name': 'version-6',
'released': False,
'self': 'https://domain.com/rest/api/2/version/6'}],
'votes': {'hasVoted': False,
'self': 'https://domain.com/rest/api/2/issue/TEST-1/votes',
'votes': 0},
'watches': {'isWatching': False,
'self': 'https://domain.com/rest/api/2/issue/TEST-1/watchers',
'watchCount': 2},
'worklog': {'maxResults': 20,
'startAt': 0,
'total': 0,
'worklogs': []},
'workratio': -1},
'id': '1000002',
'key': 'TEST-2',
'self': 'https://domain.com/rest/api/2/issue/1000002'}
Expand Down
Loading

0 comments on commit 239138a

Please sign in to comment.