-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from MerleLiuKun/feat-revoke-token
feat(access token): ✨ add api for revoke token
- Loading branch information
Showing
12 changed files
with
134 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
addopts = --cov=pytiktok --cov-report xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
""" | ||
Tests for the access token API | ||
""" | ||
|
||
import pytest | ||
import responses | ||
|
||
from pytiktok import BusinessAccountApi, PyTiktokError | ||
|
||
|
||
@responses.activate | ||
def test_generate_access_token(bus_api, helpers): | ||
with pytest.raises(PyTiktokError): | ||
BusinessAccountApi().generate_access_token(code="test_code") | ||
|
||
data = helpers.load_json("testsdata/business/access_token/token_resp.json") | ||
responses.add( | ||
responses.POST, | ||
"https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/token/", | ||
json=data, | ||
) | ||
resp = bus_api.generate_access_token(code="test_code") | ||
assert resp.access_token == "act.token" | ||
|
||
|
||
@responses.activate | ||
def test_refresh_access_token(bus_api, helpers): | ||
with pytest.raises(PyTiktokError): | ||
BusinessAccountApi().refresh_access_token(refresh_token="test_refresh_token") | ||
|
||
data = helpers.load_json("testsdata/business/access_token/refresh_resp.json") | ||
responses.add( | ||
responses.POST, | ||
"https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/refresh_token/", | ||
json=data, | ||
) | ||
resp = bus_api.refresh_access_token(refresh_token="test_refresh_token") | ||
assert resp.access_token == "act.token" | ||
|
||
|
||
@responses.activate | ||
def test_revoke_access_token(bus_api, helpers): | ||
with pytest.raises(PyTiktokError): | ||
BusinessAccountApi().revoke_access_token(access_token="test_access_token") | ||
|
||
data = helpers.load_json("testsdata/business/access_token/revoke_resp.json") | ||
responses.add( | ||
responses.POST, | ||
"https://business-api.tiktok.com/open_api/v1.3/tt_user/oauth2/revoke/", | ||
json=data, | ||
) | ||
resp = bus_api.revoke_access_token(access_token="test_access_token") | ||
assert resp.code == 0 | ||
|
||
|
||
@responses.activate | ||
def test_get_token_info(bus_api, helpers): | ||
with pytest.raises(PyTiktokError): | ||
BusinessAccountApi().get_token_info(access_token="test_access_token") | ||
|
||
data = helpers.load_json("testsdata/business/access_token/token_info_resp.json") | ||
responses.add( | ||
responses.POST, | ||
"https://business-api.tiktok.com/open_api/v1.3/tt_user/token_info/get/", | ||
json=data, | ||
) | ||
resp = bus_api.get_token_info(access_token="test_access_token") | ||
assert resp.app_id == "app_id" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import json | ||
|
||
import pytest | ||
|
||
from pytiktok import BusinessAccountApi | ||
|
||
|
||
class Helpers: | ||
@staticmethod | ||
def load_json(file_path): | ||
with open(file_path, "rb") as f: | ||
return json.loads(f.read().decode("utf-8")) | ||
|
||
|
||
@pytest.fixture | ||
def helpers(): | ||
return Helpers | ||
|
||
|
||
@pytest.fixture | ||
def bus_api(): | ||
return BusinessAccountApi( | ||
app_id="test_app_id", | ||
app_secret="test_app_secret", | ||
access_token="test_access_token", | ||
oauth_redirect_uri="https://example.com", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code":0,"message":"OK","request_id":"20240304062229F5CE92334051531529123","data":{"access_token":"act.token","expires_in":86400,"open_id":"openid","refresh_token":"rft.token","refresh_token_expires_in":31527314,"scope":"video.publish,comment.list.manage,video.insights,video.list,user.insights,user.info.basic,user.info.username,comment.list,user.account.type,user.info.stats","token_type":"Bearer"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code":0,"message":"OK","request_id":"{{request_id}}","data":{}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code":0,"message":"OK","request_id":"202403040625134BC8B6513D5E1A194123","data":{"app_id":"app_id","creator_id":"openid","scope":"comment.list.manage,video.list,user.insights,user.info.basic,user.account.type,video.publish,video.insights,user.info.stats,user.info.username,comment.list"}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"code":0,"message":"OK","request_id":"202403040357439E497F7E6668D60F2700","data":{"access_token":"act.token","expires_in":86400,"open_id":"openid","refresh_token":"rft.token","refresh_token_expires_in":31536000,"scope":"video.publish,comment.list.manage,video.insights,video.list,user.insights,user.info.basic,user.info.username,comment.list,user.account.type,user.info.stats","token_type":"Bearer"}} |