def test_get_issues_empty(self): """Test get when the issue is empty API call""" from_date = str_to_datetime('2015-01-01') body = '{"total": 0, "maxResults": 0, "startAt": 0}' httpretty.register_uri(httpretty.GET, JIRA_SEARCH_URL, body=body, status=200) client = JiraClient(url='http://example.com', project='perceval', user='******', password='******', verify=False, cert=None, max_issues=1) pages = [page for page in client.get_issues(from_date)] expected_req = { 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': ['project = perceval AND updated > 1420070400000 order by updated asc'], 'maxResults': ['1'], 'startAt': ['0'] } self.assertEqual(len(pages), 1) self.assertEqual(pages[0], body) self.assertDictEqual(httpretty.last_request().querystring, expected_req)
def test_get_issues_empty(self): """Test get when the issue is empty API call""" from_date = str_to_datetime('2015-01-01') body = '{"total": 0, "maxResults": 0, "startAt": 0}' httpretty.register_uri(httpretty.GET, JIRA_SEARCH_URL, body=body, status=200) client = JiraClient(url='http://example.com', project='perceval', user='******', password='******', verify=False, cert=None, max_issues=1) pages = [page for page in client.get_issues(from_date)] expected_req = { 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': [' project = perceval AND updated > 1420070400000'], 'maxResults': ['1'], 'startAt': ['0'] } self.assertEqual(len(pages), 1) self.assertEqual(pages[0], body) self.assertDictEqual(httpretty.last_request().querystring, expected_req)
def test_get_issues(self): """Test get issues API call""" from_date = str_to_datetime('2015-01-01') requests = [] bodies_json = [ read_file('data/jira/jira_issues_page_1.json'), read_file('data/jira/jira_issues_page_2.json') ] bodies = bodies_json[:] bodies = list(bodies_json) def request_callback(method, uri, headers): body = bodies.pop(0) requests.append(httpretty.last_request()) return (200, headers, body) httpretty.register_uri(httpretty.GET, JIRA_SEARCH_URL, responses=[httpretty.Response(body=request_callback) \ for _ in range(2)]) client = JiraClient(url='http://example.com', project='perceval', user='******', password='******', verify=False, cert=None, max_issues=2) pages = [page for page in client.get_issues(from_date)] expected_req = [{ 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': [' project = perceval AND updated > 1420070400000'], 'maxResults': ['2'], 'startAt': ['0'] }, { 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': [' project = perceval AND updated > 1420070400000'], 'maxResults': ['2'], 'startAt': ['2'] }] self.assertEqual(len(pages), 2) self.assertEqual(requests[0].method, 'GET') self.assertRegex(requests[0].path, '/rest/api/2/search') self.assertDictEqual(requests[0].querystring, expected_req[0]) self.assertEqual(requests[1].method, 'GET') self.assertRegex(requests[1].path, '/rest/api/2/search') self.assertDictEqual(requests[1].querystring, expected_req[1]) self.assertEqual(pages[0], bodies_json[0]) self.assertEqual(pages[1], bodies_json[1])
def test_get_issues(self): """Test get issues API call""" from_date = str_to_datetime('2015-01-01') requests = [] bodies_json = [read_file('data/jira/jira_issues_page_1.json'), read_file('data/jira/jira_issues_page_2.json')] bodies = bodies_json[:] bodies = list(bodies_json) def request_callback(method, uri, headers): body = bodies.pop(0) requests.append(httpretty.last_request()) return (200, headers, body) httpretty.register_uri(httpretty.GET, JIRA_SEARCH_URL, responses=[httpretty.Response(body=request_callback) \ for _ in range(2)]) client = JiraClient(url='http://example.com', project='perceval', user='******', password='******', verify=False, cert=None, max_issues=2) pages = [page for page in client.get_issues(from_date)] expected_req = [{ 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': ['project = perceval AND updated > 1420070400000 order by updated asc'], 'maxResults': ['2'], 'startAt': ['0'] }, { 'expand': ['renderedFields,transitions,operations,changelog'], 'jql': ['project = perceval AND updated > 1420070400000 order by updated asc'], 'maxResults': ['2'], 'startAt': ['2'] }] self.assertEqual(len(pages), 2) self.assertEqual(requests[0].method, 'GET') self.assertRegex(requests[0].path, '/rest/api/2/search') self.assertDictEqual(requests[0].querystring, expected_req[0]) self.assertEqual(requests[1].method, 'GET') self.assertRegex(requests[1].path, '/rest/api/2/search') self.assertDictEqual(requests[1].querystring, expected_req[1]) self.assertEqual(pages[0], bodies_json[0]) self.assertEqual(pages[1], bodies_json[1])
def test_get_fields(self): """Test get fields API call""" body = read_file('data/jira/jira_fields.json') httpretty.register_uri(httpretty.GET, JIRA_FIELDS_URL, body=body, status=200) client = JiraClient(url='http://example.com', project=None, user='******', password='******', verify=False, cert=None, max_issues=None) page = client.get_fields() self.assertEqual(httpretty.last_request().method, 'GET') self.assertRegex(httpretty.last_request().path, '/rest/api/2/field') self.assertEqual(page, body)
def test_init(self): """Test initialization""" client = JiraClient(url='http://example.com', project='perceval', user='******', password='******', verify=False, cert=None, max_issues=100) self.assertEqual(client.url, 'http://example.com') self.assertEqual(client.project, 'perceval') self.assertEqual(client.user, 'user') self.assertEqual(client.password, 'password') self.assertEqual(client.verify, False) self.assertEqual(client.cert, None) self.assertEqual(client.max_issues, 100)