initial commit

This commit is contained in:
Tyrel Souza 2021-11-03 22:26:39 -04:00
commit 92a5620abf
8 changed files with 182 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
env/
__pycache__/

48
cli.py Normal file
View File

@ -0,0 +1,48 @@
import httpx
from pprint import pprint
class GHub:
headers = {"Accept": "application/vnd.github.v3+json"}
def __init__(self, user_name: str, repo_name: str):
self.user_name = user_name
self.repo_name = repo_name
def get(self, url: str) -> dict:
"""Uses httpx.Client().get to send the appropriate github headers, and return the url"""
with httpx.Client(headers=self.headers) as client:
return client.get(url).json()
def schema(self) -> dict:
"""Show all the schema that are available"""
return self.get("https://api.github.com")
def set_user(self):
self.user = self.get_user()
def get_user(self) -> dict:
"""Get the user object"""
return self.get(f"https://api.github.com/users/{self.user_name}")
def set_repo(self):
self.repo = self.get_repo()
def get_repo(self) -> dict:
"""Get the repo object"""
return self.get(f"https://api.github.com/repos/{self.user_name}/{self.repo_name}")
def main():
gh = GHub(user_name="mkb79", repo_name="audible-cli")
# pprint(gh.schema())
pprint(
(
gh.get_user(),
gh.get_repo(),
)
)
if __name__ == "__main__":
main()

6
requirements.in Normal file
View File

@ -0,0 +1,6 @@
httpx
pip-tools
black
invoke
pytest
pytest-httpx

83
requirements.txt Normal file
View File

@ -0,0 +1,83 @@
#
# This file is autogenerated by pip-compile with python 3.9
# To update, run:
#
# pip-compile
#
anyio==3.3.4
# via httpcore
attrs==21.2.0
# via pytest
black==21.10b0
# via -r requirements.in
certifi==2021.10.8
# via httpx
charset-normalizer==2.0.7
# via httpx
click==8.0.3
# via
# black
# pip-tools
h11==0.12.0
# via httpcore
httpcore==0.13.7
# via httpx
httpx==0.20.0
# via
# -r requirements.in
# pytest-httpx
idna==3.3
# via
# anyio
# rfc3986
iniconfig==1.1.1
# via pytest
invoke==1.6.0
# via -r requirements.in
mypy-extensions==0.4.3
# via black
packaging==21.2
# via pytest
pathspec==0.9.0
# via black
pep517==0.12.0
# via pip-tools
pip-tools==6.4.0
# via -r requirements.in
platformdirs==2.4.0
# via black
pluggy==1.0.0
# via pytest
py==1.10.0
# via pytest
pyparsing==2.4.7
# via packaging
pytest==6.2.5
# via
# -r requirements.in
# pytest-httpx
pytest-httpx==0.14.0
# via -r requirements.in
regex==2021.11.2
# via black
rfc3986[idna2008]==1.5.0
# via httpx
sniffio==1.2.0
# via
# anyio
# httpcore
# httpx
toml==0.10.2
# via pytest
tomli==1.2.2
# via
# black
# pep517
typing-extensions==3.10.0.2
# via black
wheel==0.37.0
# via pip-tools
# The following packages are considered to be unsafe in a requirements file:
# pip
# setuptools

12
tasks.py Normal file
View File

@ -0,0 +1,12 @@
from invoke import task
@task
def test(c):
c.run("pytest tests.py --pdb")
@task
def black(c):
"""
Runs The uncompromising Python code formatter on specific python files.
"""
c.run("black *.py")

29
tests.py Normal file
View File

@ -0,0 +1,29 @@
import json
import pytest
from cli import GHub
from pytest_httpx import HTTPXMock
def _load_user():
with open("tests/user.json", "r") as f:
return json.loads(f.read())
def _load_repo():
with open("tests/repo.json", "r") as f:
return json.loads(f.read())
def test_user(httpx_mock: HTTPXMock):
httpx_mock.add_response(method="GET", json=_load_user())
gh = GHub(user_name="tyrelsouza", repo_name="work_sample")
gh.set_user()
assert(gh.user["login"] == "tyrelsouza")
def test_repo(httpx_mock: HTTPXMock):
httpx_mock.add_response(method="GET", json=_load_repo())
gh = GHub(user_name="tyrelsouza", repo_name="work_sample")
gh.set_repo()
breakpoint()
assert(gh.repo["login"] == "tyrelsouza2")

1
tests/repo.json Normal file

File diff suppressed because one or more lines are too long

1
tests/user.json Normal file
View File

@ -0,0 +1 @@
{"login": "tyrelsouza", "id": 923113, "node_id": "MDQ6VXNlcjkyMzExMw==", "avatar_url": "https://avatars.githubusercontent.com/u/923113?v=4", "gravatar_id": "", "url": "https://api.github.com/users/tyrelsouza", "html_url": "https://github.com/tyrelsouza", "followers_url": "https://api.github.com/users/tyrelsouza/followers", "following_url": "https://api.github.com/users/tyrelsouza/following{/other_user}", "gists_url": "https://api.github.com/users/tyrelsouza/gists{/gist_id}", "starred_url": "https://api.github.com/users/tyrelsouza/starred{/owner}{/repo}", "subscriptions_url": "https://api.github.com/users/tyrelsouza/subscriptions", "organizations_url": "https://api.github.com/users/tyrelsouza/orgs", "repos_url": "https://api.github.com/users/tyrelsouza/repos", "events_url": "https://api.github.com/users/tyrelsouza/events{/privacy}", "received_events_url": "https://api.github.com/users/tyrelsouza/received_events", "type": "User", "site_admin": false, "name": "Tyrel Souza", "company": "@tidelift @librariesio", "blog": "https://tidelift.com", "location": "Chapel Hill, NC", "email": null, "hireable": null, "bio": "I have a job. I write code for it. Any sponsorships are my own, and not endorsed by my employer. I disagree with Badges and Achievements.", "twitter_username": "tyrelsouza", "public_repos": 10, "public_gists": 34, "followers": 43, "following": 30, "created_at": "2011-07-18T15:04:40Z", "updated_at": "2021-10-12T05:33:35Z"}