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_from_non_set_cache(self): """Test if a error is raised when the cache was not set""" github = GitHub("zhquan_example", "repo", "aaa") with self.assertRaises(CacheError): _ = [cache_issues for cache_issues in github.fetch_from_cache()]
def test_initialization(self): """Test whether attributes are initializated""" github = GitHub('zhquan_example', 'repo', 'aaa', tag='test') self.assertEqual(github.owner, 'zhquan_example') self.assertEqual(github.repository, 'repo') self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo') self.assertEqual(github.tag, 'test') # When tag is empty or None it will be set to # the value in origin github = GitHub('zhquan_example', 'repo', 'aaa') self.assertEqual(github.owner, 'zhquan_example') self.assertEqual(github.repository, 'repo') self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo') self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo') github = GitHub('zhquan_example', 'repo', 'aaa', tag='') self.assertEqual(github.owner, 'zhquan_example') self.assertEqual(github.repository, 'repo') self.assertEqual(github.origin, 'https://github.com/zhquan_example/repo') self.assertEqual(github.tag, 'https://github.com/zhquan_example/repo')
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_from_empty_cache(self): """Test if there are not any issues returned when the cache is empty""" cache = Cache(self.tmp_path) github = GitHub("zhquan_example", "repo", "aaa", cache=cache) cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()] self.assertEqual(len(cache_issues), 0)
def test_fetch_from_empty_cache(self): """Test if there are not any issues returned when the cache is empty""" cache = Cache(self.tmp_path) github = GitHub("zhquan_example", "repo", "aaa", None, cache=cache) cache_issues = [cache_issues for cache_issues in github.fetch_from_cache()] self.assertEqual(len(cache_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.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))
def test_has_resuming(self): """Test if it returns True when has_resuming is called""" self.assertEqual(GitHub.has_resuming(), True)