Skip to content

Commit

Permalink
Attempt to fix the unittest and to eliminate warnings from the test e…
Browse files Browse the repository at this point in the history
…xecutions.
  • Loading branch information
ssbarnea committed Jul 15, 2015
1 parent 02f7273 commit c815fea
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 33 deletions.
12 changes: 6 additions & 6 deletions docs/index.rst
Expand Up @@ -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
Expand Down Expand Up @@ -227,7 +227,7 @@ Updating components::


Fields
~~~~~~
------

issue.fields.worklogs # list of Worklog objects
issue.fields.worklogs[0].author
Expand All @@ -249,7 +249,7 @@ Fields


Searching
^^^^^^^^^
---------

Leverage the power of `JQL <https://confluence.atlassian.com/display/JIRA/Advanced+Searching>`_
to quickly find the issues you want::
Expand All @@ -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::
Expand All @@ -285,7 +285,7 @@ Adding, editing and deleting comments is similarly straightforward::
comment.delete()

Transitions
^^^^^^^^^^^
-----------

Learn what transitions are available on an issue::

Expand Down
23 changes: 13 additions & 10 deletions jira/client.py
Expand Up @@ -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:
Expand Down Expand Up @@ -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("&")))
Expand Down Expand Up @@ -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

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

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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],
Expand Down
10 changes: 5 additions & 5 deletions jira/resources.py
Expand Up @@ -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 = {}
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion jira/version.py
Expand Up @@ -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'
10 changes: 6 additions & 4 deletions test
Expand Up @@ -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:
Expand Down
6 changes: 4 additions & 2 deletions tests/tests.py
Expand Up @@ -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):
Expand Down
20 changes: 15 additions & 5 deletions 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]
Expand All @@ -18,23 +18,33 @@ 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
downloadcache={toxworkdir}/downloadcache
deps=
{[testenv]deps}
unittest2
setenv =
PYTHONPATH =

0 comments on commit c815fea

Please sign in to comment.