Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pytest with demo.py #226

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ jobs:
run: |
mypy
- name: Run demo.py
run: python demo.py
run: pytest --cov -v demo.py
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

49 changes: 21 additions & 28 deletions demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
# 'verify': False, # PAPI use https, an easy way is disable requests SSL verify
}

aapi = AppPixivAPI(**_REQUESTS_KWARGS)
aapi.auth(refresh_token=_REFRESH_TOKEN)

# AppAPI start


def appapi_illust(aapi):
def test_appapi_illust():
json_result = aapi.illust_detail(59580629)
print(json_result)
illust = json_result.illust
Expand All @@ -41,7 +44,7 @@ def appapi_illust(aapi):
# print(">>> frames=%d %s" % (len(metadata.frames), metadata.zip_urls.medium))


def appapi_recommend(aapi):
def test_appapi_recommend():
json_result = aapi.illust_recommended(bookmark_illust_ids=[59580629])
print(json_result)
illust = json_result.illusts[0]
Expand Down Expand Up @@ -69,7 +72,7 @@ def appapi_recommend(aapi):
print(" > %s, origin url: %s" % (illust.title, illust.image_urls["large"]))


def appapi_users(aapi):
def test_appapi_users():
json_result = aapi.user_detail(275527)
print(json_result)
user = json_result.user
Expand Down Expand Up @@ -115,7 +118,7 @@ def appapi_users(aapi):
print(json_result)


def appapi_search(aapi):
def test_appapi_search():
first_tag = None
response = aapi.trending_tags_illust()
for trend_tag in response.trend_tags[:10]:
Expand Down Expand Up @@ -154,7 +157,7 @@ def appapi_search(aapi):
print(">>> %s, origin url: %s" % (novel.title, novel.image_urls["large"]))


def appapi_user_search(aapi):
def test_appapi_user_search():
json_result = aapi.illust_ranking("day_male")
name = json_result.illusts[0].user.name
print(">>> %s" % name)
Expand All @@ -173,7 +176,7 @@ def appapi_user_search(aapi):
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"]))


def appapi_ranking(aapi):
def test_appapi_ranking():
json_result = aapi.illust_ranking("day_male")
print(json_result)
illust = json_result.illusts[0]
Expand All @@ -194,7 +197,7 @@ def appapi_ranking(aapi):
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"]))


def appapi_auth_api(aapi):
def test_appapi_auth_api():
json_result = aapi.illust_follow(req_auth=True)
print(json_result)
illust = json_result.illusts[0]
Expand All @@ -214,7 +217,7 @@ def appapi_auth_api(aapi):
print(">>> %s, origin url: %s" % (illust.title, illust.image_urls["large"]))


def appapi_bookmark_add(aapi):
def test_appapi_bookmark_add():
illust_id = 74187223
tags = ["Fate/GO", "50000users入り", "私服"]
json_result = aapi.illust_bookmark_add(illust_id, tags=tags)
Expand All @@ -229,7 +232,7 @@ def appapi_bookmark_add(aapi):
)


def appapi_novel(aapi):
def test_appapi_novel():
json_result = aapi.user_novels(59216290)
print(json_result)
novel = json_result.novels[0]
Expand Down Expand Up @@ -280,23 +283,13 @@ def appapi_novel(aapi):
print(">>> %s, novel_text: %s" % (novel.title, json_result.novel_text))


def main():
# app-api
aapi = AppPixivAPI(**_REQUESTS_KWARGS)

aapi.auth(refresh_token=_REFRESH_TOKEN)

appapi_illust(aapi)
appapi_recommend(aapi)
appapi_users(aapi)
appapi_search(aapi)
appapi_user_search(aapi)
appapi_ranking(aapi)
appapi_bookmark_add(aapi)
appapi_novel(aapi)

appapi_auth_api(aapi)


if __name__ == "__main__":
main()
test_appapi_illust()
test_appapi_recommend()
test_appapi_users()
test_appapi_search()
test_appapi_user_search()
test_appapi_ranking()
test_appapi_bookmark_add()
test_appapi_novel()
test_appapi_auth_api()
2 changes: 2 additions & 0 deletions requirements.development.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ setuptools>=59.6.0
mypy>=0.931
flake8>=4.0.1
types-requests>=2.27.10
pytest>=7.0.1
pytest-cov>=3.0.0
flake8-black>=0.3.0
black[jupyter]>=22.1.0
isort>=5.10.1
Expand Down
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ dev =
mypy>=0.931
flake8>=4.0.1
types-requests>=2.27.10
pytest>=7.0.1
pytest-cov>=3.0.0
flake8-black>=0.3.0
black[jupyter]>=22.1.0
isort>=5.10.1
Expand Down