From c815fea7cf14a2ece1db7da1bf5c857890693ee8 Mon Sep 17 00:00:00 2001 From: Sorin Sbarnea Date: Wed, 15 Jul 2015 15:15:02 +0100 Subject: [PATCH] Attempt to fix the unittest and to eliminate warnings from the test executions. --- docs/index.rst | 12 ++++++------ jira/client.py | 23 +++++++++++++---------- jira/resources.py | 10 +++++----- jira/version.py | 2 +- test | 10 ++++++---- tests/tests.py | 6 ++++-- tox.ini | 20 +++++++++++++++----- 7 files changed, 50 insertions(+), 33 deletions(-) diff --git a/docs/index.rst b/docs/index.rst index 8c0d80432..6060332e7 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -3,8 +3,8 @@ You can adapt this file completely to your liking, but it should at least contain the root `toctree` directive. -Welcome to jira-python's documentation! -============================================== +Python JIRA Library Documentation +================================= .. toctree:: :maxdepth: 2 @@ -227,7 +227,7 @@ Updating components:: Fields -~~~~~~ +------ issue.fields.worklogs # list of Worklog objects issue.fields.worklogs[0].author @@ -249,7 +249,7 @@ Fields Searching -^^^^^^^^^ +--------- Leverage the power of `JQL `_ to quickly find the issues you want:: @@ -264,7 +264,7 @@ to quickly find the issues you want:: print [issue.fields.summary for issue in jira.search_issues('reporter = currentUser() order by created desc', maxResults=3)] Comments -^^^^^^^^ +-------- Comments, like issues, are objects. Get at issue comments through the parent Issue object or the JIRA object's dedicated method:: @@ -285,7 +285,7 @@ Adding, editing and deleting comments is similarly straightforward:: comment.delete() Transitions -^^^^^^^^^^^ +----------- Learn what transitions are available on an issue:: diff --git a/jira/client.py b/jira/client.py index 21f707fec..6dc54d5a3 100644 --- a/jira/client.py +++ b/jira/client.py @@ -28,7 +28,8 @@ import datetime import calendar import hashlib -import urlparse +from six.moves.urllib.parse import urlparse, urlencode + try: from collections import OrderedDict except ImportError: @@ -106,11 +107,12 @@ def __init__(self, iterable=None, _total=None): class QshGenerator: + def __init__(self, context_path): - self.context_path= context_path + self.context_path = context_path def __call__(self, req): - parse_result = urlparse.urlparse(req.url) + parse_result = urlparse(req.url) path = parse_result.path[len(self.context_path):] if len(self.context_path) > 1 else parse_result.path query = '&'.join(sorted(parse_result.query.split("&"))) @@ -228,7 +230,7 @@ def __init__(self, server=None, options=None, basic_auth=None, oauth=None, jwt=N if self._options['server'].endswith('/'): self._options['server'] = self._options['server'][:-1] - context_path = urlparse.urlparse(self._options['server']).path + context_path = urlparse(self._options['server']).path if len(context_path) > 0: self._options['context_path'] = context_path @@ -383,7 +385,7 @@ def applicationlinks(self, cached=True): if cached and hasattr(self, '_applicationlinks'): return self._applicationlinks - #url = self._options['server'] + '/rest/applinks/latest/applicationlink' + # url = self._options['server'] + '/rest/applinks/latest/applicationlink' url = self._options['server'] + \ '/rest/applinks/latest/listApplicationlinks' @@ -604,7 +606,6 @@ def create_filter(self, name=None, description=None, def update_filter(self, filter_id, name=None, description=None, jql=None, favourite=None): - """ Updates a filter and return a filter Resource for it. @@ -991,7 +992,7 @@ def add_remote_link(self, issue, destination, globalId=None, application=None, r self._options, self._session, raw=json_loads(r)) return remote_link - def add_simple_link(self, issue, object): + def add_simple_link(self, issue, object): """ Add a simple remote link from an issue to web resource. This avoids the admin access problems from add_remote_link by just using a simple object and presuming all fields are correct and not requiring more complex ``application`` data. ``object`` should be a dict containing at least ``url`` to the linked external URL @@ -2004,7 +2005,7 @@ def _timestamp(dt=None): def _create_jwt_session(self, jwt): try: jwt_auth = JWTAuth(jwt['secret'], alg='HS256') - except NameError, e: + except NameError as e: globals()['logging'].error("JWT authentication requires requests_jwt") raise e jwt_auth.add_field("iat", lambda req: JIRA._timestamp()) @@ -2054,7 +2055,9 @@ def _try_magic(self): else: try: _magic = magic.Magic(flags=magic.MAGIC_MIME_TYPE) - cleanup = lambda _: _magic.close() + + def cleanup(): + _magic.close() self._magic_weakref = weakref.ref(self, cleanup) self._magic = _magic except TypeError: @@ -2310,7 +2313,7 @@ def delete_project(self, pid): 'Got %s response from calling delete_project.' % r.status_code) return r.status_code - def _gain_sudo_session (self, options, destination): + def _gain_sudo_session(self, options, destination): url = self._options['server'] + '/secure/admin/WebSudoAuthenticate.jspa' payload = { 'webSudoPassword': self._session.auth[1], diff --git a/jira/resources.py b/jira/resources.py index 97cb13023..c432dafcc 100644 --- a/jira/resources.py +++ b/jira/resources.py @@ -345,9 +345,9 @@ def update(self, fields=None, update=None, async=None, jira=None, **fieldargs): are available here: https://developer.atlassian.com/display/JIRADEV/JIRA+REST+API+Example+-+Edit+issues :param fields: a dict containing field names and the values to use - + :param update: a dict containing update operations to apply - + keyword arguments will generally be merged into fields, except lists, which will be merged into updates """ data = {} @@ -367,15 +367,15 @@ def update(self, fields=None, update=None, async=None, jira=None, **fieldargs): if field == 'assignee' or field == 'reporter': fields_dict['assignee'] = {'name': value} elif field == 'comment': - if not 'comment' in update_dict: + if 'comment' not in update_dict: update_dict['comment'] = [] update_dict['comment'].append({ - 'add': { 'body': value } + 'add': {'body': value} }) else: fields_dict[field] = value elif isinstance(value, list): - if not field in update_dict: + if field not in update_dict: update_dict[field] = [] update_dict[field].extend(value) else: diff --git a/jira/version.py b/jira/version.py index 0d8761214..f6469acc8 100644 --- a/jira/version.py +++ b/jira/version.py @@ -3,4 +3,4 @@ # 1) we don't load dependencies by storing it in __init__.py # 2) we can import it in setup.py for the same reason # 3) we can import it into the jira module -__version__ = '0.48.1' +__version__ = '0.49' diff --git a/test b/test index 867f9e325..ecdad1610 100755 --- a/test +++ b/test @@ -26,10 +26,12 @@ if __name__ == "__main__": #os.system("python setup.py test") #pip_cmd = "pip install --user --upgrade" - pip_cmd = "pip install --user " # "--exists-action w" not existing everywhere - cmds = ["%s -r requirements.txt" % pip_cmd, - "%s -r requirements-dev.txt" % pip_cmd, - "%s -r requirements-opt.txt || echo 'Warning: optional requirements install failed.'" % pip_cmd, + # --user + pip_cmd = "pip -q install" # "--exists-action w" not existing everywhere + cmds = [ + #"%s -r requirements.txt" % pip_cmd, + #"%s -r requirements-dev.txt" % pip_cmd, + #"%s -r requirements-opt.txt || echo 'Warning: optional requirements install failed.'" % pip_cmd, "python -m autopep8 --recursive --ignore=E501 -i *.py tests/*.py jira/*.py examples/*.py || echo 'Warning: autopep8 failed'", "python -m tox -e %s" % ",".join(detected_pys)] for cmd in cmds: diff --git a/tests/tests.py b/tests/tests.py index 3aa163bbc..0659e1d9b 100755 --- a/tests/tests.py +++ b/tests/tests.py @@ -1376,8 +1376,10 @@ def test_project_versions(self): self.assertEqual(test.name, name) i = self.jira.issue(JiraTestManager().project_b_issue1) - i.update(fixVersions=[{'id': version.id}]) - + i.update(fields={ + 'versions': [{'id': version.id}], + 'fixVersions': [{'id': version.id}] + }) version.delete() def test_project_versions_with_project_obj(self): diff --git a/tox.ini b/tox.ini index f99034010..07c9d5f9b 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] minversion=1.3 -envlist = py27,py26,py33,py34,docs +envlist = py27,py26,py34,docs addopts = --ignore=setup.py [testenv:docs] @@ -18,19 +18,27 @@ commands= sitepackages=False downloadcache={toxworkdir}/downloadcache deps= - yanc - pytest>=2.3 + filemagic>=1.6 + ordereddict pytest-cov pytest-pep8 pytest-xdist - xmlrunner + pytest>=2.3 + requests>=2.6.0 + requests_toolbelt + setuptools>=0.8.0 + six>=1.9.0 + tlslite>=0.4.4 wheel - six>=1.7.2 + xmlrunner + yanc commands= python -m py.test --cov-report xml --cov jira --pyargs jira # removed -n4 due to fixture failure -n4 #.tests +setenv = + PYTHONPATH = [testenv:py26] sitepackages=False @@ -38,3 +46,5 @@ downloadcache={toxworkdir}/downloadcache deps= {[testenv]deps} unittest2 +setenv = + PYTHONPATH =