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