Skip to content

Commit

Permalink
Only request a small number of fields from Bugzilla. Fixes #3
Browse files Browse the repository at this point in the history
  • Loading branch information
AutomatedTester committed Jul 11, 2014
1 parent 15136a5 commit 4e62855
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
7 changes: 6 additions & 1 deletion bugsy/bugsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from search import Search




class BugsyException(Exception):
"""
If while interacting with Bugzilla and we try do something that is not
Expand Down Expand Up @@ -32,6 +34,9 @@ class Bugsy(object):
Bugsy allows easy getting and putting of Bugzilla bugs
"""

DEFAULT_SEARCH = ['version', 'id', 'summary', 'status', 'op_sys',
'resolution', 'product', 'component', 'platform']

def __init__(self, username=None, password=None, bugzilla_url='https://bugzilla.mozilla.org/rest'):
"""
Initialises a new instance of Bugsy
Expand Down Expand Up @@ -70,7 +75,7 @@ def get(self, bug_number):
>>> bugzilla = Bugsy()
>>> bug = bugzilla.get(123456)
"""
bug = self.request('bug/%s' % bug_number).json()
bug = self.request('bug/%s' % bug_number, params={"include_fields" : self.DEFAULT_SEARCH}).json()
return Bug(self, **bug['bugs'][0])

def put(self, bug):
Expand Down
6 changes: 4 additions & 2 deletions bugsy/search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import copy

import requests
from bug import Bug
import bugsy as Bugsy


class Search(object):
Expand All @@ -13,8 +16,7 @@ def __init__(self, bugsy):
:param bugsy: Bugsy instance to use to connect to Bugzilla.
"""
self._bugsy = bugsy
self._includefields = ['version', 'id', 'summary', 'status', 'op_sys',
'resolution', 'product', 'component', 'platform']
self._includefields = copy.copy(bugsy.DEFAULT_SEARCH)
self._keywords = []
self._assigned = []
self._summaries = []
Expand Down
8 changes: 4 additions & 4 deletions tests/test_bugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def test_we_can_get_a_dict_version_of_the_bug():

@responses.activate
def test_we_can_update_a_bug_from_bugzilla():
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy()
Expand Down Expand Up @@ -155,7 +155,7 @@ def test_we_can_update_a_bug_with_login_token():
body='{"token": "foobar"}', status=200,
content_type='application/json', match_querystring=True)

responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy("foo", "bar")
Expand All @@ -178,7 +178,7 @@ def test_that_we_can_add_a_comment_to_a_bug():
body='{"token": "foobar"}', status=200,
content_type='application/json', match_querystring=True)

responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy("foo", "bar")
Expand All @@ -195,7 +195,7 @@ def test_comment_retrieval():
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/login?login=foo&password=bar',
body='{"token": "foobar"}', status=200,
content_type='application/json', match_querystring=True)
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315/comment?token=foobar',
Expand Down
4 changes: 2 additions & 2 deletions tests/test_bugsy.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_we_cant_post_without_passing_a_bug_object():

@responses.activate
def test_we_can_get_a_bug():
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy()
Expand All @@ -71,7 +71,7 @@ def test_we_can_get_a_bug_with_login_token():
body='{"token": "foobar"}', status=200,
content_type='application/json', match_querystring=True)

responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar',
responses.add(responses.GET, 'https://bugzilla.mozilla.org/rest/bug/1017315?token=foobar&include_fields=version&include_fields=id&include_fields=summary&include_fields=status&include_fields=op_sys&include_fields=resolution&include_fields=product&include_fields=component&include_fields=platform',
body=json.dumps(example_return), status=200,
content_type='application/json', match_querystring=True)
bugzilla = Bugsy("foo", "bar")
Expand Down

0 comments on commit 4e62855

Please sign in to comment.