def test_initialization(self): """Test whether attributes are initializated""" bg = BugzillaREST(BUGZILLA_SERVER_URL, tag='test', max_bugs=5) self.assertEqual(bg.url, BUGZILLA_SERVER_URL) self.assertEqual(bg.origin, BUGZILLA_SERVER_URL) self.assertEqual(bg.tag, 'test') self.assertEqual(bg.max_bugs, 5) self.assertIsNone(bg.client) self.assertTrue(bg.ssl_verify) # When tag is empty or None it will be set to # the value in URL bg = BugzillaREST(BUGZILLA_SERVER_URL) self.assertEqual(bg.url, BUGZILLA_SERVER_URL) self.assertEqual(bg.origin, BUGZILLA_SERVER_URL) self.assertEqual(bg.tag, BUGZILLA_SERVER_URL) bg = BugzillaREST(BUGZILLA_SERVER_URL, tag='', ssl_verify=False) self.assertEqual(bg.url, BUGZILLA_SERVER_URL) self.assertEqual(bg.origin, BUGZILLA_SERVER_URL) self.assertEqual(bg.tag, BUGZILLA_SERVER_URL) self.assertFalse(bg.ssl_verify)
def setUp(self): super().setUp() self.backend_write_archive = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2, archive=self.archive) self.backend_read_archive = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2, archive=self.archive)
def setUp(self): super().setUp() self.backend_write_archive = BugzillaREST(BUGZILLA_SERVER_URL, user='******', password='******', max_bugs=2, archive=self.archive) self.backend_read_archive = BugzillaREST(BUGZILLA_SERVER_URL, user='******', password='******', max_bugs=2, archive=self.archive)
def test_fetch_from_non_set_cache(self): """Test if a error is raised when the cache was not set""" bg = BugzillaREST(BUGZILLA_SERVER_URL) with self.assertRaises(CacheError): _ = [bug for bug in bg.fetch_from_cache()]
def test_fetch_from_empty_cache(self): """Test if there are not any bugs returned when the cache is empty""" cache = Cache(self.tmp_path) bg = BugzillaREST(BUGZILLA_SERVER_URL, cache=cache) cached_bugs = [bug for bug in bg.fetch_from_cache()] self.assertEqual(len(cached_bugs), 0)
def test_search_fields(self): """Test whether the search_fields is properly set""" setup_http_server() bg = BugzillaREST(BUGZILLA_SERVER_URL, max_bugs=2) bugs = [bug for bug in bg.fetch(from_date=None)] self.assertEqual(len(bugs), 3) bug = bugs[0] self.assertEqual(bg.metadata_id(bug['data']), bug['search_fields']['item_id']) self.assertEqual(bug['data']['product'], 'Connected Devices') self.assertEqual(bug['data']['product'], bug['search_fields']['product']) self.assertEqual(bug['data']['component'], 'Project Sensor Web') self.assertEqual(bug['data']['component'], bug['search_fields']['component']) bug = bugs[1] self.assertEqual(bg.metadata_id(bug['data']), bug['search_fields']['item_id']) self.assertEqual(bug['data']['product'], 'Connected Devices') self.assertEqual(bug['data']['product'], bug['search_fields']['product']) self.assertEqual(bug['data']['component'], 'Project Sensor Web') self.assertEqual(bug['data']['component'], bug['search_fields']['component']) bug = bugs[2] self.assertEqual(bg.metadata_id(bug['data']), bug['search_fields']['item_id']) self.assertEqual(bug['data']['product'], 'MailNews Core') self.assertEqual(bug['data']['product'], bug['search_fields']['product']) self.assertEqual(bug['data']['component'], 'Backend') self.assertEqual(bug['data']['component'], bug['search_fields']['component'])
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/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)
"--use-created-date", help="Use created date instead of update date", type=lambda s: s.lower() in ['true', 't', 'yes', 'y', '1']) parser.add_argument("-D", "--updated-diff", help="If >=0 skip objects where created + diff > updated", type=int, default=-1) args = parser.parse_args() # print(args) # print ((args.date_from, args.date_to)) bugzilla = BugzillaREST(args.url, user=args.user, password=args.password, api_token=args.token, max_bugs=500, tag=None, archive=None) # print(bugzilla) oids = set() for bug in bugzilla.fetch(category=args.category, from_date=args.date_from): # print(bug) # print(bug.keys()) # print(bug['data'].keys()) product = bug['data']['product'] if args.product and args.product != product: continue # dtu = dateutil.parser.parse(bug['data']['last_change_time']) dtu = utc.localize(
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])