def test_fetch_from_cache(self): """Test whether the cache works""" http_requests = setup_http_server() # First, we fetch the topics from the server, storing them # in a cache cache = Cache(self.tmp_path) bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2, cache=cache) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(http_requests), 9) # Now, we get the topics from the cache. # The contents should be the same and there won't be # any new request to the server cached_bugs = [bug for bug in bg.fetch_from_cache()] self.assertEqual(len(cached_bugs), len(bugs)) self.assertEqual(len(cached_bugs), 3) self.assertEqual(bugs[0]['data']['id'], 1273442) self.assertEqual(len(bugs[0]['data']['comments']), 7) self.assertEqual(len(bugs[0]['data']['history']), 6) self.assertEqual(len(bugs[0]['data']['attachments']), 1) self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db') self.assertEqual(bugs[0]['updated_on'], 1465257689.0) self.assertEqual(bugs[0]['category'], 'bug') self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['data']['id'], 1273439) self.assertEqual(len(bugs[1]['data']['comments']), 0) self.assertEqual(len(bugs[1]['data']['history']), 0) self.assertEqual(len(bugs[1]['data']['attachments']), 0) self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde') self.assertEqual(bugs[1]['updated_on'], 1465257715.0) self.assertEqual(bugs[1]['category'], 'bug') self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['data']['id'], 947945) self.assertEqual(len(bugs[2]['data']['comments']), 0) self.assertEqual(len(bugs[2]['data']['history']), 0) self.assertEqual(len(bugs[2]['data']['attachments']), 0) self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd') self.assertEqual(bugs[2]['updated_on'], 1465257743.0) self.assertEqual(bugs[2]['category'], 'bug') self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL) # No more requests were sent self.assertEqual(len(http_requests), 9)
def test_fetch_empty(self): """Test whether it works when no bugs are fetched""" body = read_file("data/bugzilla_rest_bugs_empty.json") httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_URL, body=body, status=200) bg = BugzillaREST(BUGZILLA_SERVER_URL) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(bugs), 0)
def test_fetch_from_cache(self): """Test whether the cache works""" http_requests = setup_http_server() # First, we fetch the topics from the server, storing them # in a cache cache = Cache(self.tmp_path) bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2, cache=cache) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(http_requests), 9) # Now, we get the topics from the cache. # The contents should be the same and there won't be # any new request to the server cached_bugs = [bug for bug in bg.fetch_from_cache()] self.assertEqual(len(cached_bugs), len(bugs)) self.assertEqual(len(cached_bugs), 3) self.assertEqual(bugs[0]['data']['id'], 1273442) self.assertEqual(len(bugs[0]['data']['comments']), 7) self.assertEqual(len(bugs[0]['data']['history']), 6) self.assertEqual(len(bugs[0]['data']['attachments']), 1) self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db') self.assertEqual(bugs[0]['updated_on'], 1465257689.0) self.assertEqual(bugs[0]['category'], 'bug') self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['data']['id'], 1273439) self.assertEqual(len(bugs[1]['data']['comments']), 0) self.assertEqual(len(bugs[1]['data']['history']), 0) self.assertEqual(len(bugs[1]['data']['attachments']), 0) self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde') self.assertEqual(bugs[1]['updated_on'], 1465257715.0) self.assertEqual(bugs[1]['category'], 'bug') self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['data']['id'], 947945) self.assertEqual(len(bugs[2]['data']['comments']), 0) self.assertEqual(len(bugs[2]['data']['history']), 0) self.assertEqual(len(bugs[2]['data']['attachments']), 0) self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd') self.assertEqual(bugs[2]['updated_on'], 1465257743.0) self.assertEqual(bugs[2]['category'], 'bug') self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL) # No more requests were sent self.assertEqual(len(http_requests), 9)
def test_fetch_empty(self): """Test whether it works when no bugs are fetched""" body = read_file('data/bugzilla_rest_bugs_empty.json') httpretty.register_uri(httpretty.GET, BUGZILLA_BUGS_URL, body=body, status=200) bg = BugzillaREST(BUGZILLA_SERVER_URL) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(bugs), 0)
def test_fetch(self): """Test whether a list of bugs is returned""" http_requests = setup_http_server() bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(bugs), 3) self.assertEqual(bugs[0]['data']['id'], 1273442) self.assertEqual(len(bugs[0]['data']['comments']), 7) self.assertEqual(len(bugs[0]['data']['history']), 6) self.assertEqual(len(bugs[0]['data']['attachments']), 1) self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db') self.assertEqual(bugs[0]['updated_on'], 1465257689.0) self.assertEqual(bugs[0]['category'], 'bug') self.assertEqual(bugs[0]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['data']['id'], 1273439) self.assertEqual(len(bugs[1]['data']['comments']), 0) self.assertEqual(len(bugs[1]['data']['history']), 0) self.assertEqual(len(bugs[1]['data']['attachments']), 0) self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde') self.assertEqual(bugs[1]['updated_on'], 1465257715.0) self.assertEqual(bugs[1]['category'], 'bug') self.assertEqual(bugs[1]['tag'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['data']['id'], 947945) self.assertEqual(len(bugs[2]['data']['comments']), 0) self.assertEqual(len(bugs[2]['data']['history']), 0) self.assertEqual(len(bugs[2]['data']['attachments']), 0) self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd') self.assertEqual(bugs[2]['updated_on'], 1465257743.0) self.assertEqual(bugs[2]['category'], 'bug') self.assertEqual(bugs[2]['tag'], BUGZILLA_SERVER_URL) # Check requests expected = [{ 'last_change_time': ['1970-01-01T00:00:00Z'], 'limit': ['2'], 'order': ['changeddate'], 'include_fields': ['_all'] }, { 'ids': ['1273442', '1273439'] }, { 'ids': ['1273442', '1273439'] }, { 'ids': ['1273442', '1273439'], 'exclude_fields': ['data'] }, { 'last_change_time': ['1970-01-01T00:00:00Z'], 'offset': ['2'], 'limit': ['2'], 'order': ['changeddate'], 'include_fields': ['_all'] }, { 'ids': ['947945'] }, { 'ids': ['947945'] }, { 'ids': ['947945'], 'exclude_fields': ['data'] }, { 'last_change_time': ['1970-01-01T00:00:00Z'], 'offset': ['4'], 'limit': ['2'], 'order': ['changeddate'], 'include_fields': ['_all'] }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): self.assertDictEqual(http_requests[i].querystring, expected[i])
def test_fetch(self): """Test whether a list of bugs is returned""" http_requests = setup_http_server() bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(bugs), 3) self.assertEqual(bugs[0]['data']['id'], 1273442) self.assertEqual(len(bugs[0]['data']['comments']), 7) self.assertEqual(len(bugs[0]['data']['history']), 6) self.assertEqual(len(bugs[0]['data']['attachments']), 1) self.assertEqual(bugs[0]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[0]['uuid'], '68494ad0072ed9e09cecb8235649a38c443326db') self.assertEqual(bugs[0]['updated_on'], 1465257689.0) self.assertEqual(bugs[1]['data']['id'], 1273439) self.assertEqual(len(bugs[1]['data']['comments']), 0) self.assertEqual(len(bugs[1]['data']['history']), 0) self.assertEqual(len(bugs[1]['data']['attachments']), 0) self.assertEqual(bugs[1]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]['uuid'], 'd306162de06bc759f9bd9227fe3fd5f08aeb0dde') self.assertEqual(bugs[1]['updated_on'], 1465257715.0) self.assertEqual(bugs[2]['data']['id'], 947945) self.assertEqual(len(bugs[2]['data']['comments']), 0) self.assertEqual(len(bugs[2]['data']['history']), 0) self.assertEqual(len(bugs[2]['data']['attachments']), 0) self.assertEqual(bugs[2]['origin'], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]['uuid'], '33edda925351c3310fc3e12d7f18a365c365f6bd') self.assertEqual(bugs[2]['updated_on'], 1465257743.0) # Check requests expected = [{ 'last_change_time' : ['1970-01-01T00:00:00Z'], 'limit' : ['2'], 'order' : ['changeddate'], 'include_fields' : ['_all'] }, { 'ids' : ['1273442', '1273439'] }, { 'ids' : ['1273442', '1273439'] }, { 'ids' : ['1273442', '1273439'], 'exclude_fields' : ['data'] }, { 'last_change_time' : ['1970-01-01T00:00:00Z'], 'offset' : ['2'], 'limit' : ['2'], 'order' : ['changeddate'], 'include_fields' : ['_all'] }, { 'ids' : ['947945'] }, { 'ids' : ['947945'] }, { 'ids' : ['947945'], 'exclude_fields' : ['data'] }, { 'last_change_time' : ['1970-01-01T00:00:00Z'], 'offset' : ['4'], 'limit' : ['2'], 'order' : ['changeddate'], 'include_fields' : ['_all'] }] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): self.assertDictEqual(http_requests[i].querystring, expected[i])
def test_fetch(self): """Test whether a list of bugs is returned""" http_requests = setup_http_server() bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2) bugs = [bug for bug in bg.fetch()] self.assertEqual(len(bugs), 3) self.assertEqual(bugs[0]["data"]["id"], 1273442) self.assertEqual(len(bugs[0]["data"]["comments"]), 7) self.assertEqual(len(bugs[0]["data"]["history"]), 6) self.assertEqual(len(bugs[0]["data"]["attachments"]), 1) self.assertEqual(bugs[0]["origin"], BUGZILLA_SERVER_URL) self.assertEqual(bugs[0]["uuid"], "68494ad0072ed9e09cecb8235649a38c443326db") self.assertEqual(bugs[0]["updated_on"], 1465257689.0) self.assertEqual(bugs[0]["category"], "bug") self.assertEqual(bugs[1]["data"]["id"], 1273439) self.assertEqual(len(bugs[1]["data"]["comments"]), 0) self.assertEqual(len(bugs[1]["data"]["history"]), 0) self.assertEqual(len(bugs[1]["data"]["attachments"]), 0) self.assertEqual(bugs[1]["origin"], BUGZILLA_SERVER_URL) self.assertEqual(bugs[1]["uuid"], "d306162de06bc759f9bd9227fe3fd5f08aeb0dde") self.assertEqual(bugs[1]["updated_on"], 1465257715.0) self.assertEqual(bugs[1]["category"], "bug") self.assertEqual(bugs[2]["data"]["id"], 947945) self.assertEqual(len(bugs[2]["data"]["comments"]), 0) self.assertEqual(len(bugs[2]["data"]["history"]), 0) self.assertEqual(len(bugs[2]["data"]["attachments"]), 0) self.assertEqual(bugs[2]["origin"], BUGZILLA_SERVER_URL) self.assertEqual(bugs[2]["uuid"], "33edda925351c3310fc3e12d7f18a365c365f6bd") self.assertEqual(bugs[2]["updated_on"], 1465257743.0) self.assertEqual(bugs[2]["category"], "bug") # Check requests expected = [ { "last_change_time": ["1970-01-01T00:00:00Z"], "limit": ["2"], "order": ["changeddate"], "include_fields": ["_all"], }, {"ids": ["1273442", "1273439"]}, {"ids": ["1273442", "1273439"]}, {"ids": ["1273442", "1273439"], "exclude_fields": ["data"]}, { "last_change_time": ["1970-01-01T00:00:00Z"], "offset": ["2"], "limit": ["2"], "order": ["changeddate"], "include_fields": ["_all"], }, {"ids": ["947945"]}, {"ids": ["947945"]}, {"ids": ["947945"], "exclude_fields": ["data"]}, { "last_change_time": ["1970-01-01T00:00:00Z"], "offset": ["4"], "limit": ["2"], "order": ["changeddate"], "include_fields": ["_all"], }, ] self.assertEqual(len(http_requests), len(expected)) for i in range(len(expected)): self.assertDictEqual(http_requests[i].querystring, expected[i])