def test_feth_empty(self): """ Test when return empty """ body = "" login = read_file('data/github_login') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=body, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) from_date = datetime.datetime(2016, 1, 1) github = GitHub("zhquan_example", "repo", "aaa") issues = [issues for issues in github.fetch(from_date=from_date)] self.assertEqual(len(issues), 0)
def test_fetch_more_issues(self): """ Test when return two issues """ login = read_file('data/github_login') issue_1 = read_file('data/github_issue_1') issue_2 = read_file('data/github_issue_2') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=issue_1, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5', 'Link': '<'+GITHUB_ISSUES_URL+'/?&page=2>; rel="next", <'+GITHUB_ISSUES_URL+'/?&page=3>; rel="last"' }) httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL+'/?&page=2', body=issue_2, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) github = GitHub("zhquan_example", "repo", "aaa") issues = [issues for issues in github.fetch()] self.assertEqual(len(issues), 2) expected_1 = json.loads(read_file('data/github_issue_expected_1')) self.assertEqual(issues[0]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[0]['uuid'], '58c073fd2a388c44043b9cc197c73c5c540270ac') self.assertEqual(issues[0]['updated_on'], 1458035782.0) self.assertEqual(issues[0]['category'], 'issue') self.assertEqual(issues[0]['tag'], 'https://github.com/zhquan_example/repo') self.assertDictEqual(issues[0]['data'], expected_1) expected_2 = json.loads(read_file('data/github_issue_expected_2')) self.assertEqual(issues[1]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[1]['uuid'], '4236619ac2073491640f1698b5c4e169895aaf69') self.assertEqual(issues[1]['updated_on'], 1458054569.0) self.assertEqual(issues[1]['category'], 'issue') self.assertEqual(issues[1]['tag'], 'https://github.com/zhquan_example/repo') self.assertDictEqual(issues[1]['data'], expected_2)
def test_fetch_more_issues(self): """ Test when return two issues """ login = read_file('data/github_login') issue_1 = read_file('data/github_issue_1') issue_2 = read_file('data/github_issue_2') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=issue_1, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5', 'Link': '<'+GITHUB_ISSUES_URL+'/?&page=2>; rel="next", <'+GITHUB_ISSUES_URL+'/?&page=3>; rel="last"' }) httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL+'/?&page=2', body=issue_2, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '5' }) github = GitHub("zhquan_example", "repo", "aaa") issues = [issues for issues in github.fetch()] self.assertEqual(len(issues), 2) expected_1 = json.loads(read_file('data/github_issue_expected_1')) self.assertEqual(issues[0]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[0]['uuid'], '58c073fd2a388c44043b9cc197c73c5c540270ac') self.assertEqual(issues[0]['updated_on'], 1458035782.0) self.assertDictEqual(issues[0]['data'], expected_1) expected_2 = json.loads(read_file('data/github_issue_expected_2')) self.assertEqual(issues[1]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[1]['uuid'], '4236619ac2073491640f1698b5c4e169895aaf69') self.assertEqual(issues[1]['updated_on'], 1458054569.0) self.assertDictEqual(issues[1]['data'], expected_2)
def test_fetch_from_cache(self): """ Test whether a list of issues is returned from cache """ body = read_file('data/github_request') login = read_file('data/github_login') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=body, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) # First, we fetch the bugs from the server, storing them # in a cache cache = Cache(self.tmp_path) github = GitHub("zhquan_example", "repo", "aaa", cache=cache) issues = [issues for issues in github.fetch()] # Now, we get the bugs from the cache. # The contents should be the same and there won't be # any new request to the server cache_issues = [ cache_issues for cache_issues in github.fetch_from_cache() ] del issues[0]['timestamp'] del cache_issues[0]['timestamp'] self.assertDictEqual(issues[0], cache_issues[0]) self.assertEqual(len(issues), len(cache_issues))
def test_fetch(self): """ Test whether a list of issues is returned """ body = read_file('data/github_request') login = read_file('data/github_login') orgs = read_file('data/github_orgs') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=body, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body=orgs, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) github = GitHub("zhquan_example", "repo", "aaa") issues = [issues for issues in github.fetch()] self.assertEqual(len(issues), 1) expected = json.loads(read_file('data/github_request_expected')) self.assertEqual(issues[0]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[0]['uuid'], '58c073fd2a388c44043b9cc197c73c5c540270ac') self.assertEqual(issues[0]['updated_on'], 1454328801.0) self.assertEqual(issues[0]['category'], 'issue') self.assertEqual(issues[0]['tag'], 'https://github.com/zhquan_example/repo') self.assertDictEqual(issues[0]['data'], expected)
def test_fetch_from_date(self): """ Test when return from date """ login = read_file('data/github_login') body = read_file('data/github_issue_2') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=body, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) from_date = datetime.datetime(2016, 3, 1) github = GitHub("zhquan_example", "repo", "aaa") issues = [issues for issues in github.fetch(from_date=from_date)] self.assertEqual(len(issues), 1) expected = json.loads(read_file('data/github_issue_expected_2')) self.assertEqual(issues[0]['origin'], 'https://github.com/zhquan_example/repo') self.assertEqual(issues[0]['uuid'], '4236619ac2073491640f1698b5c4e169895aaf69') self.assertEqual(issues[0]['updated_on'], 1458054569.0) self.assertEqual(issues[0]['category'], 'issue') self.assertEqual(issues[0]['tag'], 'https://github.com/zhquan_example/repo') self.assertDictEqual(issues[0]['data'], expected)
def test_fetch_from_cache(self): """ Test whether a list of issues is returned from cache """ body = read_file('data/github_request') login = read_file('data/github_login') httpretty.register_uri(httpretty.GET, GITHUB_ISSUES_URL, body=body, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_USER_URL, body=login, status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) httpretty.register_uri(httpretty.GET, GITHUB_ORGS_URL, body="[]", status=200, forcing_headers={ 'X-RateLimit-Remaining': '20', 'X-RateLimit-Reset': '15' }) # First, we fetch the bugs from the server, storing them # in a cache cache = Cache(self.tmp_path) github = GitHub("zhquan_example", "repo", "aaa", cache=cache) issues = [issues for issues in github.fetch()] # Now, we get the bugs from the cache. # The contents should be the same and there won't be # any new request to the server cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()] del issues[0]['timestamp'] del cache_issues[0]['timestamp'] self.assertDictEqual(issues[0], cache_issues[0]) self.assertEqual(len(issues), len(cache_issues))