Skip to content

Commit

Permalink
bugfix use v2 api compatible field names
Browse files Browse the repository at this point in the history
  • Loading branch information
adehad committed Apr 24, 2021
1 parent 435c1c8 commit 61dd811
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 30 deletions.
19 changes: 10 additions & 9 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1581,13 +1581,13 @@ def createmeta(
params["expand"] = expand
return self._get_json("issue/createmeta", params)

def _get_user_accountid(self, user):
"""Internal method for translating an user to an accountId."""
def _get_user_key(self, user):
"""Internal method for translating an user (str) to an key."""
try:
accountId = self.search_users(user, maxResults=1)[0].accountId
key = self.search_users(user, maxResults=1)[0].key
except Exception as e:
raise JIRAError(e)
return accountId
return key

# non-resource
@translate_resource_args
Expand All @@ -1607,7 +1607,7 @@ def assign_issue(self, issue, assignee):
+ str(issue)
+ "/assignee"
)
payload = {"accountId": self._get_user_accountid(assignee)}
payload = {"name": self._get_user_key(assignee)}
# 'key' and 'name' are deprecated in favor of accountId
r = self._session.put(url, data=json.dumps(payload))
raise_on_error(r)
Expand Down Expand Up @@ -1940,7 +1940,7 @@ def add_watcher(self, issue, watcher):
"""Add a user to an issue's watchers list.
:param issue: ID or key of the issue affected
:param watcher: username of the user to add to the watchers list
:param watcher: key of the user to add to the watchers list
"""
url = self._get_url("issue/" + str(issue) + "/watchers")
self._session.post(url, data=json.dumps(watcher))
Expand All @@ -1950,11 +1950,12 @@ def remove_watcher(self, issue, watcher):
"""Remove a user from an issue's watch list.
:param issue: ID or key of the issue affected
:param watcher: accountId of the user to remove from the watchers list
:param watcher: key of the user to remove from the watchers list
:rtype: Response
"""
url = self._get_url("issue/" + str(issue) + "/watchers")
params = {"accountId": watcher}
# https://docs.atlassian.com/software/jira/docs/api/REST/8.13.6/#api/2/issue-removeWatcher
params = {"username": watcher}
result = self._session.delete(url, params=params)
return result

Expand Down Expand Up @@ -3653,7 +3654,7 @@ def create_project(
:type: str
:param name: If not specified it will use the key value.
:type name: Optional[str]
:param assignee: accountId of the lead, if not specified it will use current user.
:param assignee: key of the lead, if not specified it will use current user.
:type assignee: Optional[str]
:param type: Determines the type of project should be created.
:type ptype: Optional[str]
Expand Down
2 changes: 1 addition & 1 deletion jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ def dict2resource(raw, top=None, options=None, session=None):
r"securitylevel/[^/]+$": SecurityLevel,
r"status/[^/]+$": Status,
r"statuscategory/[^/]+$": StatusCategory,
r"user\?(username|accountId).+$": User,
r"user\?(username|key).+$": User,
r"group\?groupname.+$": Group,
r"version/[^/]+$": Version,
# GreenHopper specific resources
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/pycontribs/jira.git"
},
"dependencies": {
"cspell": "^4.0.23",
"cspell": "^4.2.8",
"npm": "^6.10.0"
}
}
4 changes: 2 additions & 2 deletions tests/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def test_templates(cl_admin):
"""
Agility
Basic
Basic software development
Bug tracking
Content Management
Customer service
Expand All @@ -99,8 +100,7 @@ def test_templates(cl_admin):
)
)

for t in expected_templates:
assert t in templates
assert set(templates).difference(set(expected_templates)) == set()


def test_result_list():
Expand Down
20 changes: 10 additions & 10 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def __init__(self):
):
break
except Exception as e:
if "A project with that name already exists" not in e.text:
if "A project with that name already exists" not in str(e):
raise e
self.project_a_id = self.jira_admin.project(self.project_a).id
self.jira_admin.create_project(self.project_b, self.project_b_name)
Expand Down Expand Up @@ -453,7 +453,7 @@ def test_application_property(self):
clone_prefix = self.jira.application_properties(
key="jira.lf.text.headingcolour"
)
self.assertEqual(clone_prefix["value"], "#292929")
self.assertEqual(clone_prefix["value"], "#172b4d")

def test_set_application_property(self):
prop = "jira.lf.favicon.hires.url"
Expand Down Expand Up @@ -1133,12 +1133,12 @@ def test_editmeta(self):
"comment",
"components",
"description",
"environment",
# "environment",
"fixVersions",
"issuelinks",
"labels",
"summary",
"versions",
# "versions",
}
for i in (self.issue_1, self.issue_2):
meta = self.jira.editmeta(i)
Expand Down Expand Up @@ -1304,15 +1304,15 @@ def test_votes_with_issue_obj(self):
def test_add_remove_watcher(self):

# removing it in case it exists, so we know its state
self.jira.remove_watcher(self.issue_1, self.test_manager.user_admin.accountId)
self.jira.remove_watcher(self.issue_1, self.test_manager.user_admin.key)
init_watchers = self.jira.watchers(self.issue_1).watchCount

# adding a new watcher
self.jira.add_watcher(self.issue_1, self.test_manager.user_admin.accountId)
self.jira.add_watcher(self.issue_1, self.test_manager.user_admin.key)
self.assertEqual(self.jira.watchers(self.issue_1).watchCount, init_watchers + 1)

# now we verify that remove does indeed remove watchers
self.jira.remove_watcher(self.issue_1, self.test_manager.user_admin.accountId)
self.jira.remove_watcher(self.issue_1, self.test_manager.user_admin.key)
new_watchers = self.jira.watchers(self.issue_1).watchCount
self.assertEqual(init_watchers, new_watchers)

Expand Down Expand Up @@ -1600,7 +1600,7 @@ def test_project_versions(self):
i = self.jira.issue(JiraTestManager().project_b_issue1)
i.update(
fields={
"versions": [{"id": version.id}],
# "versions": [{"id": version.id}],
"fixVersions": [{"id": version.id}],
}
)
Expand All @@ -1622,7 +1622,7 @@ def test_get_project_version_by_name(self):
i = self.jira.issue(JiraTestManager().project_b_issue1)
i.update(
fields={
"versions": [{"id": version.id}],
# "versions": [{"id": version.id}],
"fixVersions": [{"id": version.id}],
}
)
Expand All @@ -1649,7 +1649,7 @@ def test_rename_version(self):
i = self.jira.issue(JiraTestManager().project_b_issue1)
i.update(
fields={
"versions": [{"id": version.id}],
# "versions": [{"id": version.id}],
"fixVersions": [{"id": version.id}],
}
)
Expand Down
8 changes: 1 addition & 7 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ extras =
sitepackages=False
commands=
git clean -xdf jira tests
; bash -c 'find . | grep -E "(__pycache__|\.pyc|\.pyo$)" | xargs rm -rf'
python -m pip check
python make_local_jira_user.py
python -m pytest {posargs}
Expand Down Expand Up @@ -80,11 +79,7 @@ envars =
PIP_USER=no
whitelist_externals =
bash
echo
find
grep
rm
xargs
git

[testenv:pkg]
deps =
Expand All @@ -96,7 +91,6 @@ deps =
wheel>=0.33.6
commands =
git clean -xdf dist
; rm -rf {toxinidir}/dist
python setup.py check -m -s
# disabled due to errors with older setuptools:
# python setup.py sdist bdist_wheel
Expand Down

0 comments on commit 61dd811

Please sign in to comment.