def test_get_query_gitlab(): token = GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', '')) _fetch(GITLAB_BASE_URL, 'get', token, '/projects', query_params={'owned': True})
def test_github_search_pagination(): # this is to cover the pagination format from github search API token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/search/issues', query_params={'q': ' repo:coala/corobo'})
def test_raises_runtime_error(self): try: token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/repos/gitmate-test-user/wontexist') except RuntimeError as ex: self.assertEqual( ex.args[0], '{"message":"Not Found",' '"documentation_url":"https://developer.github.com/v3"}') self.assertEqual(ex.args[1], 404)
def delete(token: Token, url: str, params: Optional[dict] = None, headers: Optional[dict] = None): """ Sends a delete request to the given URL on GitHub. :param token: An OAuth token. :param url: The URL to access, e.g. ``/repo``. :param params: The query params to be sent. :param headers: The request headers to be sent. :raises RuntimeError: If the response indicates any problem. """ _fetch(BASE_URL, 'delete', token, url, params, headers=headers)
def get(token: Union[GitLabOAuthToken, GitLabPrivateToken], url: str, params: Optional[dict] = None, headers: Optional[dict] = None): """ Queries GitLab on the given URL for data. :param token: An OAuth token. :param url: E.g. ``/repo`` :param params: The query params to be sent. :param headers: The request headers to be sent. :return: A dictionary or a list of dictionary if the response contains multiple items (usually in case of pagination) and the HTTP status code. :raises RunTimeError: If the response indicates any problem. """ return _fetch(BASE_URL, 'get', token, url, query_params={ **dict(params or {}), 'per_page': 100 }, headers=headers)
def put(token: Token, url: str, data: dict, headers: Optional[dict] = None): """ Puts the given data onto GitHub. :param token: An OAuth token. :param url: The URL to access, e.g. ``/repo``. :param data: The data to post. :param headers: The request headers to be sent. :return: A dictionary or a list of dictionary if the response contains multiple items (usually in case of pagination) and the HTTP status code. :raises RunTimeError: If the response indicates any problem. """ return _fetch(BASE_URL, 'put', token, url, data, headers=headers)
def test_pagination(): # this is to cover the branch where it handles the pagination token = GitHubToken(os.environ.get('GITHUB_TEST_TOKEN', '')) _fetch(GITHUB_BASE_URL, 'get', token, '/repos/coala/corobo/issues')