Пример #1
0
 def test_get_query_gitlab():
     token = GitLabOAuthToken(os.environ.get('GITLAB_TEST_TOKEN', ''))
     _fetch(GITLAB_BASE_URL,
            'get',
            token,
            '/projects',
            query_params={'owned': True})
Пример #2
0
 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'})
Пример #3
0
 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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)
Пример #7
0
 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')