From 4e628558aa8449c71018f4efe97d84b5db02c1c1 Mon Sep 17 00:00:00 2001 From: AutomatedTester Date: Fri, 11 Jul 2014 11:56:02 +0100 Subject: [PATCH] Only request a small number of fields from Bugzilla. Fixes #3 --- bugsy/bugsy.py | 7 ++++++- bugsy/search.py | 6 ++++-- tests/test_bugs.py | 8 ++++---- tests/test_bugsy.py | 4 ++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/bugsy/bugsy.py b/bugsy/bugsy.py index 2a57382..0b0689a 100644 --- a/bugsy/bugsy.py +++ b/bugsy/bugsy.py @@ -5,6 +5,8 @@ from search import Search + + class BugsyException(Exception): """ If while interacting with Bugzilla and we try do something that is not @@ -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 @@ -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): diff --git a/bugsy/search.py b/bugsy/search.py index 0bb8cc7..d088d42 100644 --- a/bugsy/search.py +++ b/bugsy/search.py @@ -1,5 +1,8 @@ +import copy + import requests from bug import Bug +import bugsy as Bugsy class Search(object): @@ -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 = [] diff --git a/tests/test_bugs.py b/tests/test_bugs.py index ec7cf39..1baae85 100644 --- a/tests/test_bugs.py +++ b/tests/test_bugs.py @@ -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() @@ -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") @@ -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") @@ -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', diff --git a/tests/test_bugsy.py b/tests/test_bugsy.py index c8b1062..26e29ab 100644 --- a/tests/test_bugsy.py +++ b/tests/test_bugsy.py @@ -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() @@ -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")