Skip to content

API/client

API modules

For example framework will test GitHub API.

Clients

This module defines the class to test API GitHub.

GitHub

Class provides several methods to use GitHub API.

Source code in modules/api/clients/github.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class GitHub:
    """Class provides several methods to use GitHub API."""

    def __init__(self) -> None:
        """Set conf. values for API."""
        self.conf = config_dict["API"]

    def get_user(self, username: str) -> dict:
        """Provides publicly available information about \
        someone with a GitHub account.

        Args:
            username: A username of a GitHub account.

        Returns:
            A dictionary with several public information.
            """
        # r = requests.get(f'https://api.github.com/users/{username}')
        r = requests.get(self.conf["users"] + username)
        body = r.json()

        return body

    def search_repo(self, name: str) -> dict:
        """Provides publicly available information about \
        someone with a GitHub account.

        Args:
            name: The query contains one or more search keywords and \
                qualifiers. Qualifiers allow you to limit your search to \
                specific areas of GitHub.
        Returns:
            A dictionary with several pieces of information.
        """
        r = requests.get(self.conf["repositories"], params={"q": name})
        body = r.json()

        return body

__init__()

Set conf. values for API.

Source code in modules/api/clients/github.py
10
11
12
def __init__(self) -> None:
    """Set conf. values for API."""
    self.conf = config_dict["API"]

get_user(username)

Provides publicly available information about someone with a GitHub account.

Parameters:

Name Type Description Default
username str

A username of a GitHub account.

required

Returns:

Type Description
dict

A dictionary with several public information.

Source code in modules/api/clients/github.py
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
def get_user(self, username: str) -> dict:
    """Provides publicly available information about \
    someone with a GitHub account.

    Args:
        username: A username of a GitHub account.

    Returns:
        A dictionary with several public information.
        """
    # r = requests.get(f'https://api.github.com/users/{username}')
    r = requests.get(self.conf["users"] + username)
    body = r.json()

    return body

search_repo(name)

Provides publicly available information about someone with a GitHub account.

Parameters:

Name Type Description Default
name str

The query contains one or more search keywords and qualifiers. Qualifiers allow you to limit your search to specific areas of GitHub.

required

Returns:

Type Description
dict

A dictionary with several pieces of information.

Source code in modules/api/clients/github.py
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def search_repo(self, name: str) -> dict:
    """Provides publicly available information about \
    someone with a GitHub account.

    Args:
        name: The query contains one or more search keywords and \
            qualifiers. Qualifiers allow you to limit your search to \
            specific areas of GitHub.
    Returns:
        A dictionary with several pieces of information.
    """
    r = requests.get(self.conf["repositories"], params={"q": name})
    body = r.json()

    return body

API Tests

This module provides several tests for GitHub API