Skip to content

Commit

Permalink
Test changes towards getting them passing on Travis too
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Jan 7, 2015
1 parent c060601 commit dd7b7f8
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 75 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ os:
- linux
- osx
python:
- "2.6"
# - "2.6"
- "2.7"
- "3.3"
- "3.4"
# - "3.3"
# - "3.4"
env:
global:
- secure: EUpWmrnhHKPkz9cOGbEEwhBtUBRqtQ775ck042B8/pI9ZZZghbKl3Jm8ahpfms3JiZcHMCG06MBREs1ISK/g2OfHKsdULCg5g3UFXteVQo769kwh/x4lniSbU2eipcN0s9Q/Ak5zStwTa5aNQ4FU/3zSgTDxi/OcDKGXDbVwHD8=
Expand Down
27 changes: 8 additions & 19 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,24 @@
import copy
import os
import re
import sys
import string
import warnings
import tempfile
import logging
import requests
import json
import warnings


from six import string_types
from six.moves import html_parser
from six import print_ as print


from jira.exceptions import raise_on_error, JIRAError
# JIRA specific resources
from jira.resources import Resource, Issue, Comment, Project, Attachment, Component, Dashboard, Filter, Votes, Watchers, Worklog, IssueLink, IssueLinkType, IssueType, Priority, Version, Role, Resolution, SecurityLevel, Status, User, CustomFieldOption, RemoteLink
# GreenHopper specific resources
from jira.resources import GreenHopperResource, Board, Sprint
from jira.resilientsession import ResilientSession
from .utils import threaded_requests

try:
from random import SystemRandom
Expand All @@ -51,18 +49,6 @@
# warnings.warn("Python default encoding is '%s' instead of 'UTF8' which means that there is a big change of having problems. Possible workaround http://stackoverflow.com/a/17628350/99834" % encoding)


def threaded_requests(requests):
for fn, url, request_args in requests:
th = threading.Thread(
target=fn, args=(url,), kwargs=request_args, name=url,
)
th.start()

for th in threading.enumerate():
if th.name.startswith('http'):
th.join()


def translate_resource_args(func):
"""
Decorator that converts Issue and Project resources to their keys when used as arguments.
Expand Down Expand Up @@ -1731,8 +1717,11 @@ def _get_json(self, path, params=None, base=JIRA_BASE_URL):
url = self._get_url(path, base)
r = self._session.get(url, params=params, headers=self._options['headers'])
raise_on_error(r)

r_json = json.loads(r.text)
try:
r_json = json.loads(r.text)
except ValueError as e:
logging.error("%s\n%s" % (e, r.text))
raise e
return r_json

def _find_for_resource(self, resource_cls, ids, expand=None):
Expand Down Expand Up @@ -1865,7 +1854,7 @@ def rename_user(self, old_user, new_user):
p = re.compile("type=\"hidden\" name=\"cannedScriptArgs_Hidden_output\" value=\"(.*?)\"\/>", re.MULTILINE | re.DOTALL)
m = p.search(r.content)
if m:
h = HTMLParser.HTMLParser()
h = html_parser.HTMLParser()
msg = h.unescape(m.group(1))
logging.info(msg)

Expand Down
15 changes: 8 additions & 7 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,13 @@
"""

import re
import sys
import logging
import random
import pprint
import json

from six import iteritems, string_types, text_type
from six import print_ as print

from jira.exceptions import raise_on_error, get_error_list
from .utils import threaded_requests
from .exceptions import raise_on_error, get_error_list


class Resource(object):
Expand Down Expand Up @@ -194,8 +191,12 @@ def delete(self, params=None):
def _load(self, url, headers=None, params=None):
r = self._session.get(url, headers=headers, params=params)
raise_on_error(r)

self._parse_raw(json.loads(r.text))
try:
j = json.loads(r.text)
except ValueError as e:
logging.error("%s:\n%s" % (e, r.text))
raise e
self._parse_raw(j)

def _parse_raw(self, raw):
self.raw = raw
Expand Down
14 changes: 14 additions & 0 deletions jira/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# -*- coding: utf-8 -*-
import threading


def threaded_requests(requests):
for fn, url, request_args in requests:
th = threading.Thread(
target=fn, args=(url,), kwargs=request_args, name=url,
)
th.start()

for th in threading.enumerate():
if th.name.startswith('http'):
th.join()
2 changes: 2 additions & 0 deletions requirements-opt.txt
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
ipython>=0.13
pytest-osxnotify
pytest-cache
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ upload-dir = docs/build/html
[pytest]
norecursedirs = . .svn jira _build tmp* lib/third lib *.egg bin distutils build docs demo
python_files = *.py
addopts = -p no:xdist --ignore=setup.py --tb=long -rsxX -v --junitxml=reports --maxfail=3 --pep8 tests
addopts = -p no:xdist --ignore=setup.py --tb=long -rsxX -v --junitxml=reports --maxfail=10 --pep8 tests
# -n 1
# --maxfail=2 -n4
# -n4 runs up to 4 parallel procs
Expand Down
7 changes: 7 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ def initialize_options(self):
TestCommand.initialize_options(self)
self.pytest_args = []

# if we have pytest-cache module we enable the test failures first mode
try:
import pytest_cache
self.pytest_args.append("--ff")
except ImportError:
pass

def finalize_options(self):
TestCommand.finalize_options(self)
self.test_args = []
Expand Down
64 changes: 19 additions & 45 deletions tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import random
import string
from time import sleep
import py

from six import print_ as print
from requests.exceptions import ConnectionError
Expand All @@ -28,10 +29,10 @@
else:
import unittest

cmd_folder = os.path.abspath(os.path.join(os.path.split(inspect.getfile(
inspect.currentframe()))[0], ".."))
if cmd_folder not in sys.path:
sys.path.insert(0, cmd_folder)
# cmd_folder = os.path.abspath(os.path.join(os.path.split(inspect.getfile(
# inspect.currentframe()))[0], ".."))
# if cmd_folder not in sys.path:
# sys.path.insert(0, cmd_folder)

from jira.client import JIRA
from jira.exceptions import JIRAError
Expand Down Expand Up @@ -69,25 +70,8 @@ def get_status_code(host, path="/", auth=None):
return None


"""
if CI_JIRA_ADMIN_USER:
j = JIRA(options={'server': CI_JIRA_URL}, basic_auth=(CI_JIRA_ADMIN_USER, CI_JIRA_ADMIN_PASSWORD))
else:
j = JIRA(options={'server': CI_JIRA_URL})
j.add_user('eviladmin', 'noreply@example.com', password='eviladmin') # , fullname=None, sendEmail=False, active=True)
j.add_user_to_group('eviladmin', 'jira-administrators')
j.add_user('fred', 'noreply@example.com', password='fred')
j.delete_project("XSS")
j.delete_project("BULK")
j.create_project("XSS", "XSS")
r = j.create_project("BULK", "BULK")
print(r)
j.create_issue(project={'key': 'BULK'}, summary='issue 1 from BULK', issuetype={'name': 'Bug'})
j.create_issue(project={'key': 'BULK'}, summary='issue 2 from BULK', issuetype={'name': 'Bug'})
j.create_issue(project={'key': 'BULK'}, summary='issue 3 from BULK', issuetype={'name': 'Bug'})
"""
def rndstr():
return ''.join(random.sample(string.ascii_letters, 6))


class Singleton(type):
Expand Down Expand Up @@ -272,9 +256,10 @@ def __init__(self):
logging.info("ccc4")

except Exception as e:
logging.fatal("Basic test setup failed, that's FATAL!. %s" % e)
msg = "Basic test setup failed, that's FATAL!. %s" % e
logging.fatal(msg)
self.initialized = 1
sys.exit(3)
py.test.exit(msg)

self.initialized = 1

Expand Down Expand Up @@ -440,10 +425,11 @@ def test_1_component(self):

def test_2_create_component(self):
proj = self.jira.project(self.project_b)
component = self.jira.create_component('Project b test component',
name = "project-%s-component-%s" % (proj, rndstr())
component = self.jira.create_component(name,
proj, description='test!!', assigneeType='COMPONENT_LEAD',
isAssigneeTypeValid=False)
self.assertEqual(component.name, 'Project b test component')
self.assertEqual(component.name, name)
self.assertEqual(component.description, 'test!!')
self.assertEqual(component.assigneeType, 'COMPONENT_LEAD')
self.assertFalse(component.isAssigneeTypeValid)
Expand Down Expand Up @@ -472,7 +458,7 @@ def test_3_update(self):
# We ignore errors as this code intends only to prepare for component creation
pass

name = 'component-' + ''.join(random.sample(string.ascii_letters, 15))
name = 'component-' + rndstr()

component = self.jira.create_component(name,
self.project_b, description='stand by!',
Expand Down Expand Up @@ -548,7 +534,7 @@ def setUp(self):

def test_filter(self):
jql = "project = %s and component is not empty" % self.project_b
name = 'same filter ' + ''.join(random.sample(string.ascii_letters, 15))
name = 'same filter ' + rndstr()
myfilter = self.jira.create_filter(name=name,
description="just some new test filter", jql=jql,
favourite=False)
Expand All @@ -560,7 +546,7 @@ def test_favourite_filters(self):
filters = self.jira.favourite_filters()
initial_len = len(filters)
jql = "project = %s and component is not empty" % self.project_b
name = "filter-to-fav-" + ''.join(random.sample(string.ascii_letters, 15))
name = "filter-to-fav-" + rndstr()
myfilter = self.jira.create_filter(name=name,
description="just some new test filter", jql=jql,
favourite=True)
Expand Down Expand Up @@ -1335,27 +1321,15 @@ def find_selected_avatar(avatars):

def test_project_components(self):
proj = self.jira.project(self.project_b)
component = self.jira.create_component('Project b test component',
name = "component-%s from project %s" % (proj, rndstr())
component = self.jira.create_component(name,
proj, description='test!!', assigneeType='COMPONENT_LEAD',
isAssigneeTypeValid=False)
components = self.jira.project_components(self.project_b)
self.assertGreaterEqual(len(components), 1)
sample = find_by_id(components, component.id)
self.assertEqual(sample.id, component.id)
self.assertEqual(sample.name, 'Project b test component')
component.delete()

def test_project_components_with_project_obj(self):
proj = self.jira.project(self.project_b)
component = self.jira.create_component('Project b test component',
proj, description='test!!', assigneeType='COMPONENT_LEAD',
isAssigneeTypeValid=False)
project = self.jira.project(self.project_b)
components = self.jira.project_components(project)
self.assertGreaterEqual(len(components), 1)
sample = find_by_id(components, component.id)
self.assertEqual(sample.id, component.id)
self.assertEqual(sample.name, 'Project b test component')
self.assertEqual(sample.name, name)
component.delete()

def test_project_versions(self):
Expand Down

0 comments on commit dd7b7f8

Please sign in to comment.