mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 15:40:26 +01:00
add test
Signed-off-by: ふぁ <yuki@yuki0311.com>
This commit is contained in:
parent
976f6ffb14
commit
86315f25a0
16 changed files with 209 additions and 14 deletions
12
test/python/login.py
Normal file
12
test/python/login.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
import json
|
||||
from tweepy_authlib import CookieSessionUserHandler
|
||||
|
||||
auth_handler = CookieSessionUserHandler(
|
||||
screen_name=input("screen_name: "),
|
||||
password=input("password: "),
|
||||
)
|
||||
|
||||
|
||||
cookies = auth_handler.get_cookies()
|
||||
|
||||
print(json.dumps(cookies.get_dict()))
|
||||
8
test/python/openapi-generator-config.yaml
Normal file
8
test/python/openapi-generator-config.yaml
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
inputSpec: dist/compatible/openapi-3.0.yaml
|
||||
outputDir: python_generated
|
||||
|
||||
packageName: python_generated
|
||||
packageVersion: 0.0.1
|
||||
projectName: python_generated
|
||||
|
||||
useOneOfDiscriminatorLookup: true
|
||||
71
test/python/test_serialize.py
Normal file
71
test/python/test_serialize.py
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
import json
|
||||
import os
|
||||
import logging
|
||||
import python_generated as pt
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s")
|
||||
logger = logging.getLogger("test_serialize")
|
||||
|
||||
if Path("cookie.json").exists():
|
||||
with open("cookie.json", "r") as f:
|
||||
cookies = json.load(f)
|
||||
else:
|
||||
cookies = json.loads(os.environ["TWITTER_SESSION"])
|
||||
|
||||
cookies_str = "; ".join([f"{k}={v}" for k, v in cookies.items()])
|
||||
|
||||
|
||||
with open("src/config/placeholder.json", "r") as f:
|
||||
placeholder = json.load(f)
|
||||
|
||||
|
||||
def getKey(snake_str):
|
||||
components = snake_str.split("_")
|
||||
return "".join(x.title() for x in components[1:])
|
||||
|
||||
|
||||
api_conf = pt.Configuration(
|
||||
api_key={
|
||||
"ClientLanguage": "en",
|
||||
"ActiveUser": "yes",
|
||||
"AuthType": "OAuth2Session",
|
||||
"CsrfToken": cookies["ct0"],
|
||||
},
|
||||
)
|
||||
|
||||
api_conf.access_token = "AAAAAAAAAAAAAAAAAAAAANRILgAAAAAAnNwIzUejRCOuH5E6I8xnZz4puTs%3D1Zv7ttfk8LF81IUq16cHjhLTvJu4FA33AGWWjCpTnA"
|
||||
|
||||
api_client = pt.ApiClient(configuration=api_conf, cookie=cookies_str)
|
||||
api_client.user_agent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36"
|
||||
|
||||
error_count = 0
|
||||
|
||||
for x in [pt.DefaultApi, pt.TweetApi, pt.UserApi, pt.UserListApi]:
|
||||
for props, fn in x.__dict__.items():
|
||||
if not callable(fn):
|
||||
continue
|
||||
if props.startswith("__") or props.endswith("_with_http_info"):
|
||||
continue
|
||||
|
||||
key = getKey(props)
|
||||
logger.info(f"Try: {key}")
|
||||
|
||||
kwargs = {"path_query_id": placeholder[key]["queryId"]}
|
||||
if placeholder[key].get("variables") is not None:
|
||||
kwargs["variables"] = json.dumps(placeholder[key]["variables"])
|
||||
if placeholder[key].get("features") is not None:
|
||||
kwargs["features"] = json.dumps(placeholder[key]["features"])
|
||||
if placeholder[key].get("fieldToggles") is not None:
|
||||
kwargs["field_toggles"] = json.dumps(placeholder[key]["fieldToggles"])
|
||||
|
||||
try:
|
||||
res = getattr(x(api_client), props)(**kwargs)
|
||||
except Exception as e:
|
||||
logger.error(f"{key}")
|
||||
logger.error(e)
|
||||
error_count += 1
|
||||
|
||||
if error_count > 0:
|
||||
exit(1)
|
||||
Loading…
Add table
Add a link
Reference in a new issue