Skip to content

Commit

Permalink
remove Comments and Dashboards resources; specify a better couple of …
Browse files Browse the repository at this point in the history
…createmeta tests
  • Loading branch information
Ben Speakmon committed May 23, 2012
1 parent 30f4323 commit c45e7a7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 33 deletions.
14 changes: 6 additions & 8 deletions jira/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import requests
import json
from jira.exceptions import JIRAError
from jira.resources import Resource, Issue, Comments, Comment, Project, Attachment, Component, Dashboards, Dashboard, Filter, Votes, Watchers, Worklog, IssueLink, IssueLinkType, IssueType, Priority, Version, Role, Resolution, SecurityLevel, Status, User, CustomFieldOption, RemoteLink
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

class JIRA(object):
"""
Expand Down Expand Up @@ -219,7 +219,6 @@ def custom_field_option(self, id):

### Dashboards

# TODO: Should this be _get_json instead of resource?
def dashboards(self, filter=None, startAt=0, maxResults=20):
"""
Return a list of Dashboard resources.
Expand All @@ -228,13 +227,14 @@ def dashboards(self, filter=None, startAt=0, maxResults=20):
:param startAt: index of the first dashboard to return
:param maxResults: maximum number of dashboards to return
"""
dashboards = Dashboards(self._options, self._session)
params = {}
if filter is not None:
params['filter'] = filter
params['startAt'] = startAt
params['maxResults'] = maxResults
dashboards.find(params=params)

r_json = self._get_json('dashboard', params=params)
dashboards = [Dashboard(self._options, self._session, raw_dash_json) for raw_dash_json in r_json['dashboards']]
return dashboards

def dashboard(self, id):
Expand Down Expand Up @@ -385,17 +385,15 @@ def assign_issue(self, issue, assignee):
r = self._session.put(url, data=json.dumps(payload))
self._raise_on_error(r)

# TODO: Should this be _get_json instead of resource?
def comments(self, issue):
"""
Get a list of comment Resources.
:param issue: the issue to get comments from
"""
resource = Comments(self._options, self._session)
resource.find(issue)
r_json = self._get_json('issue/' + issue + '/comment')

comments = [Comment(self._options, self._session, raw_comment_json) for raw_comment_json in resource.raw['comments']]
comments = [Comment(self._options, self._session, raw_comment_json) for raw_comment_json in r_json['comments']]
return comments

def comment(self, issue, comment):
Expand Down
17 changes: 0 additions & 17 deletions jira/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ def __init__(self, options, session, raw=None):
self._parse_raw(raw)


class Dashboards(Resource):
"""A collection of dashboards."""

def __init__(self, options, session, raw=None):
Resource.__init__(self, 'dashboard', options, session)
if raw:
self._parse_raw(raw)


class Dashboard(Resource):
"""A JIRA dashboard."""

Expand Down Expand Up @@ -213,12 +204,6 @@ def delete(self, deleteSubtasks=False):
"""
super(Issue, self).delete(params={'deleteSubtasks': deleteSubtasks})

class Comments(Resource):
"""A collection of issue comments."""

def __init__(self, options, session):
Resource.__init__(self, 'issue/{0}/comment', options, session)


class Comment(Resource):
"""An issue comment."""
Expand Down Expand Up @@ -491,10 +476,8 @@ def dict2resource(raw, top=None, options=None, session=None):
r'component/[^/]+$': Component,
r'customFieldOption/[^/]+$': CustomFieldOption,
r'dashboard/[^/]+$': Dashboard,
r'dashboard$': Dashboards,
r'filter/[^/]$': Filter,
r'issue/[^/]+$': Issue,
r'issue/[^/]+/comment$': Comments,
r'issue/[^/]+/comment/[^/]+$': Comment,
r'issue/[^/]+/votes$': Votes,
r'issue/[^/]+/watchers$': Watchers,
Expand Down
21 changes: 13 additions & 8 deletions jira/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,20 +160,20 @@ def setUp(self):

def test_dashboards(self):
dashboards = self.jira.dashboards()
self.assertEqual(len(dashboards.dashboards), 3)
self.assertEqual(len(dashboards), 3)

def test_dashboards_filter(self):
dashboards = self.jira.dashboards(filter='my')
self.assertEqual(len(dashboards.dashboards), 1)
self.assertEqual(dashboards.dashboards[0].id, '10031')
self.assertEqual(len(dashboards), 1)
self.assertEqual(dashboards[0].id, '10031')

def test_dashboards_startAt(self):
dashboards = self.jira.dashboards(startAt=2, maxResults=2)
self.assertEqual(len(dashboards.dashboards), 1)
self.assertEqual(len(dashboards), 1)

def test_dashboards_maxResults(self):
dashboards = self.jira.dashboards(maxResults=1)
self.assertEqual(len(dashboards.dashboards), 1)
self.assertEqual(len(dashboards), 1)

def test_dashboard(self):
dashboard = self.jira.dashboard('10031')
Expand Down Expand Up @@ -333,17 +333,22 @@ def test_createmeta(self):
xss_proj = find_by_key(meta['projects'], 'XSS')
self.assertEqual(len(xss_proj['issuetypes']), 12)

def test_createmeta_filter_by_name(self):
def test_createmeta_filter_by_projectkey_and_name(self):
meta = self.jira.createmeta(projectKeys='BULK', issuetypeNames='Bug')
self.assertEqual(len(meta['projects']), 1)
self.assertEqual(len(meta['projects'][0]['issuetypes']), 1)

def test_createmeta_filter_by_projectkeys_and_name(self):
meta = self.jira.createmeta(projectKeys=('BULK', 'XSS'), issuetypeNames='Improvement')
self.assertEqual(len(meta['projects']), 2)
for project in meta['projects']:
self.assertTrue(len(project['issuetypes']), 1)
self.assertEqual(len(project['issuetypes']), 1)

def test_createmeta_filter_by_id(self):
meta = self.jira.createmeta(projectIds=('10001', '10040'), issuetypeIds=('3', '4', '5'))
self.assertEqual(len(meta['projects']), 2)
for project in meta['projects']:
self.assertTrue(len(project['issuetypes']), 3)
self.assertEqual(len(project['issuetypes']), 3)

def test_createmeta_expando(self):
# limit to SCR project so the call returns promptly
Expand Down

0 comments on commit c45e7a7

Please sign in to comment.