black
This commit is contained in:
parent
a2a17ac04a
commit
f1748276e3
@ -13,6 +13,7 @@ def _load_fixture(name: str):
|
||||
with open(f"./tests/fixtures/{name}.json", "r") as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
def test_except(httpx_mock: HTTPXMock):
|
||||
httpx_mock.add_response(method="GET", status_code=403)
|
||||
with pytest.raises(httpx.HTTPStatusError):
|
||||
@ -46,4 +47,4 @@ def test_get_with_pagination(httpx_mock: HTTPXMock):
|
||||
# test exit on dict
|
||||
httpx_mock.add_response(method="GET", json=_load_fixture("user"))
|
||||
user = api.get_with_pagination("user")
|
||||
assert user['login'] == 'tyrelsouza'
|
||||
assert user["login"] == "tyrelsouza"
|
||||
|
2
cli.py
2
cli.py
@ -4,6 +4,7 @@ from rich import print
|
||||
import httpx
|
||||
import os
|
||||
|
||||
|
||||
def main():
|
||||
if not os.environ.get("GITHUB_TOKEN"):
|
||||
raise Exception("Please set GITHUB_TOKEN")
|
||||
@ -15,5 +16,6 @@ def main():
|
||||
except httpx.HTTPStatusError as e:
|
||||
print(e)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
2
ghub.py
2
ghub.py
@ -9,7 +9,7 @@ class GHub:
|
||||
user = None
|
||||
repos = None
|
||||
|
||||
def load_user(self, user_name: str)-> None:
|
||||
def load_user(self, user_name: str) -> None:
|
||||
self.user_name = user_name
|
||||
self.api = API()
|
||||
self.user = self.api.get(f"/users/{user_name}")
|
||||
|
@ -3,10 +3,12 @@ import pytest
|
||||
from ghub import GHub
|
||||
from pytest_httpx import HTTPXMock
|
||||
|
||||
|
||||
def _load_fixture(name: str):
|
||||
with open(f"./tests/fixtures/{name}.json", "r") as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
|
||||
def _fake_tyrel() -> GHub:
|
||||
gh = GHub()
|
||||
gh.user = _load_fixture("user")
|
||||
@ -18,27 +20,28 @@ def test_load_repos():
|
||||
gh = _fake_tyrel()
|
||||
assert gh.repos[0]["git_url"] == "git://github.com/tyrelsouza/genealogy.git"
|
||||
|
||||
|
||||
def test_repos_trimmed():
|
||||
gh = _fake_tyrel()
|
||||
repos = list(gh.repos_trimmed())
|
||||
assert repos[0] == ['genealogy', 'None', '0','0','0', '0']
|
||||
assert repos[0] == ["genealogy", "None", "0", "0", "0", "0"]
|
||||
|
||||
|
||||
def test_get(httpx_mock: HTTPXMock):
|
||||
httpx_mock.add_response(method="GET", json=_load_fixture("user"))
|
||||
httpx_mock.add_response(method="GET", json=_load_fixture("repos_1"))
|
||||
gh = GHub()
|
||||
gh.load_user('tyrelsouza')
|
||||
gh.load_user("tyrelsouza")
|
||||
assert gh.user["login"] == "tyrelsouza"
|
||||
assert len(gh.repos) == 1
|
||||
|
||||
|
||||
def test_table():
|
||||
gh = _fake_tyrel()
|
||||
table = gh.repos_table()
|
||||
assert table.row_count == 1
|
||||
assert table.columns[0]._cells[0] == 'genealogy'
|
||||
assert table.columns[1]._cells[0] == 'None'
|
||||
assert table.columns[2]._cells[0] == '0'
|
||||
assert table.columns[3]._cells[0] == '0'
|
||||
assert table.columns[4]._cells[0] == '0'
|
||||
|
||||
assert table.columns[0]._cells[0] == "genealogy"
|
||||
assert table.columns[1]._cells[0] == "None"
|
||||
assert table.columns[2]._cells[0] == "0"
|
||||
assert table.columns[3]._cells[0] == "0"
|
||||
assert table.columns[4]._cells[0] == "0"
|
||||
|
Loading…
Reference in New Issue
Block a user