mirror of
https://github.com/thegeneralist01/twitter-openapi
synced 2026-01-11 07:30:37 +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
99
.github/workflows/test-python.yaml
vendored
Normal file
99
.github/workflows/test-python.yaml
vendored
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
name: test-python
|
||||
|
||||
on:
|
||||
# auto review
|
||||
pull_request:
|
||||
paths-ignore:
|
||||
- "test/**"
|
||||
- ".github/**"
|
||||
branches:
|
||||
- master
|
||||
|
||||
env:
|
||||
TWITTER_SESSION: ${{secrets.TWITTER_SESSION}}
|
||||
|
||||
jobs:
|
||||
test:
|
||||
name: Test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
# Openapi Generator Setup
|
||||
- name: Get OpenJDK 11
|
||||
uses: actions/setup-java@v2
|
||||
with:
|
||||
distribution: "temurin"
|
||||
java-version: 11
|
||||
|
||||
- name: Get Java version
|
||||
run: java -version
|
||||
|
||||
- name: Get Openapi Generator cache file
|
||||
id: openapi-generator-cache
|
||||
run: echo "file=openapi-generator-cli.jar" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Openapi Generator cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ steps.openapi-generator-cache.outputs.file }}
|
||||
key: ${{ runner.os }}-openapi-generator-${{ hashFiles('openapi-generator-cli.jar') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-openapi-generator-
|
||||
|
||||
- name: Get Openapi Generator
|
||||
run: |
|
||||
wget https://github.com/fa0311/openapi-generator/releases/download/twitter_openapi_python_1.2.0/openapi-generator-cli.jar -O openapi-generator-cli.jar --no-verbose --show-progress --no-clobber
|
||||
|
||||
# Python Setup
|
||||
- name: Set up Python 3.8
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.8
|
||||
architecture: "x64"
|
||||
|
||||
- name: Get Python version
|
||||
run: python -V
|
||||
|
||||
- name: Get pip cache dir
|
||||
id: pip-cache
|
||||
run: echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: pip cache
|
||||
uses: actions/cache@v3
|
||||
with:
|
||||
path: ${{ steps.pip-cache.outputs.dir }}
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('requirements.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
|
||||
# generate
|
||||
- name: Build twitter-openapi
|
||||
run: |
|
||||
python tools/build.py
|
||||
|
||||
# clean up dependencies
|
||||
- name: Clean up dependencies
|
||||
run: |
|
||||
pip uninstall -y -r requirements.txt
|
||||
|
||||
# generate
|
||||
- name: Generate Python client
|
||||
run: |
|
||||
java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python
|
||||
|
||||
# test
|
||||
- name: Test Python client
|
||||
run: |
|
||||
pip install ./python_generated
|
||||
|
||||
- name: Run Python client test
|
||||
run: |
|
||||
python test/python/test_serialize.py
|
||||
env:
|
||||
TWITTER_SESSION: ${{secrets.TWITTER_SESSION}}
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -1,2 +1,5 @@
|
|||
.venv
|
||||
__pycache__/
|
||||
cookie.json
|
||||
*_generated
|
||||
*.jar
|
||||
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
|
@ -4,6 +4,6 @@
|
|||
"yaml.validate": true,
|
||||
"yaml.hover": true,
|
||||
"yaml.schemas": {
|
||||
"https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json": "twitter-openapi/**/*.yaml"
|
||||
"https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/schemas/v3.0/schema.json": "src/**/*.yaml"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
1
dist/compatible/paths/profile.yaml
vendored
1
dist/compatible/paths/profile.yaml
vendored
|
|
@ -15,7 +15,6 @@ components:
|
|||
UserResultByScreenName:
|
||||
properties:
|
||||
id:
|
||||
pattern: ^[0-9a-zA-Z]+$
|
||||
type: string
|
||||
result:
|
||||
$ref: '#/components/schemas/UserResultByScreenNameResult'
|
||||
|
|
|
|||
4
dist/compatible/paths/tweet.yaml
vendored
4
dist/compatible/paths/tweet.yaml
vendored
|
|
@ -44,7 +44,7 @@ paths:
|
|||
/graphql/{pathQueryId}/Favoriters:
|
||||
get:
|
||||
description: get tweet favoriters
|
||||
operationId: getTweetFavoriters
|
||||
operationId: getFavoriters
|
||||
parameters:
|
||||
- in: path
|
||||
name: pathQueryId
|
||||
|
|
@ -128,7 +128,7 @@ paths:
|
|||
/graphql/{pathQueryId}/Retweeters:
|
||||
get:
|
||||
description: get tweet retweeters
|
||||
operationId: getTweetRetweeters
|
||||
operationId: getRetweeters
|
||||
parameters:
|
||||
- in: path
|
||||
name: pathQueryId
|
||||
|
|
|
|||
1
dist/compatible/schemas/content.yaml
vendored
1
dist/compatible/schemas/content.yaml
vendored
|
|
@ -60,7 +60,6 @@ components:
|
|||
ModuleItem:
|
||||
properties:
|
||||
entryId:
|
||||
pattern: ^[a-z\-]+[0-9]+$
|
||||
type: string
|
||||
item:
|
||||
$ref: '#/components/schemas/ModuleEntry'
|
||||
|
|
|
|||
1
dist/docs/paths/profile.yaml
vendored
1
dist/docs/paths/profile.yaml
vendored
|
|
@ -15,7 +15,6 @@ components:
|
|||
UserResultByScreenName:
|
||||
properties:
|
||||
id:
|
||||
pattern: ^[0-9a-zA-Z]+$
|
||||
type: string
|
||||
result:
|
||||
$ref: '#/components/schemas/UserResultByScreenNameResult'
|
||||
|
|
|
|||
4
dist/docs/paths/tweet.yaml
vendored
4
dist/docs/paths/tweet.yaml
vendored
|
|
@ -44,7 +44,7 @@ paths:
|
|||
/graphql/{pathQueryId}/Favoriters:
|
||||
get:
|
||||
description: get tweet favoriters
|
||||
operationId: getTweetFavoriters
|
||||
operationId: getFavoriters
|
||||
parameters:
|
||||
- in: path
|
||||
name: pathQueryId
|
||||
|
|
@ -223,7 +223,7 @@ paths:
|
|||
/graphql/{pathQueryId}/Retweeters:
|
||||
get:
|
||||
description: get tweet retweeters
|
||||
operationId: getTweetRetweeters
|
||||
operationId: getRetweeters
|
||||
parameters:
|
||||
- in: path
|
||||
name: pathQueryId
|
||||
|
|
|
|||
1
dist/docs/schemas/content.yaml
vendored
1
dist/docs/schemas/content.yaml
vendored
|
|
@ -60,7 +60,6 @@ components:
|
|||
ModuleItem:
|
||||
properties:
|
||||
entryId:
|
||||
pattern: ^[a-z\-]+[0-9]+$
|
||||
type: string
|
||||
item:
|
||||
$ref: '#/components/schemas/ModuleEntry'
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ components:
|
|||
properties:
|
||||
id:
|
||||
type: string
|
||||
pattern: "^[0-9a-zA-Z]+$"
|
||||
# pattern: "^[0-9a-zA-Z]+$"
|
||||
result:
|
||||
$ref: "#/components/schemas/UserResultByScreenNameResult"
|
||||
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ paths:
|
|||
|
||||
/graphql/{pathQueryId}/Favoriters:
|
||||
get:
|
||||
operationId: getTweetFavoriters
|
||||
operationId: getFavoriters
|
||||
description: get tweet favoriters
|
||||
responses:
|
||||
"200":
|
||||
|
|
@ -34,7 +34,7 @@ paths:
|
|||
|
||||
/graphql/{pathQueryId}/Retweeters:
|
||||
get:
|
||||
operationId: getTweetRetweeters
|
||||
operationId: getRetweeters
|
||||
description: get tweet retweeters
|
||||
responses:
|
||||
"200":
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ components:
|
|||
properties:
|
||||
entryId:
|
||||
type: string
|
||||
pattern: '^[a-z\-]+[0-9]+$'
|
||||
# pattern: '^[a-z\-]+[0-9]+$'
|
||||
item:
|
||||
$ref: "#/components/schemas/ModuleEntry"
|
||||
|
||||
|
|
|
|||
6
test/local.sh
Normal file
6
test/local.sh
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
|
||||
|
||||
python3 tools/build.py
|
||||
java -jar openapi-generator-cli.jar generate -c test/python/openapi-generator-config.yaml -g python
|
||||
python3 -m pip install ./python_generated
|
||||
python3 test/python/test_serialize.py
|
||||
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