-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tests): ✅ Add tests for threads api
- Loading branch information
1 parent
49f781e
commit bce7cee
Showing
3 changed files
with
61 additions
and
0 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"access_token": "THQVJ...","token_type": "bearer", "expires_in": 5183944} |
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 @@ | ||
{"access_token": "THQVJ...","user_id": 12345678} |
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,59 @@ | ||
""" | ||
tests for threads graph api | ||
""" | ||
|
||
import responses | ||
|
||
from pyfacebook import ThreadsGraphAPI | ||
|
||
|
||
def test_threads_get_authorization_url(): | ||
api = ThreadsGraphAPI(app_id="id", app_secret="secret", oauth_flow=True) | ||
|
||
url, state = api.get_authorization_url() | ||
assert ( | ||
url | ||
== "https://threads.net/oauth/authorize?response_type=code&client_id=id&redirect_uri=https%3A%2F%2Flocalhost%2F&scope=threads_basic&state=PyFacebook" | ||
) | ||
|
||
|
||
def test_threads_exchange_user_access_token(helpers): | ||
api = ThreadsGraphAPI(app_id="id", app_secret="secret", oauth_flow=True) | ||
|
||
resp = "https://localhost/?code=code&state=PyFacebook#_" | ||
|
||
with responses.RequestsMock() as m: | ||
m.add( | ||
method=responses.POST, | ||
url=api.EXCHANGE_ACCESS_TOKEN_URL, | ||
json=helpers.load_json("testdata/base/threads_user_token.json"), | ||
) | ||
|
||
r = api.exchange_user_access_token(response=resp) | ||
assert r["access_token"] == "THQVJ..." | ||
|
||
|
||
def test_threads_exchange_long_lived_user_access_token(helpers): | ||
api = ThreadsGraphAPI(app_id="id", app_secret="secret", access_token="token") | ||
with responses.RequestsMock() as m: | ||
m.add( | ||
method=responses.GET, | ||
url=f"https://graph.threads.net/oauth/access_token", | ||
json=helpers.load_json("testdata/base/threads_user_long_lived_token.json"), | ||
) | ||
|
||
r = api.exchange_long_lived_user_access_token() | ||
assert r["access_token"] == "THQVJ..." | ||
|
||
|
||
def test_threads_refresh_access_token(helpers): | ||
api = ThreadsGraphAPI(app_id="id", app_secret="secret", access_token="token") | ||
with responses.RequestsMock() as m: | ||
m.add( | ||
method=responses.GET, | ||
url=f"https://graph.threads.net/refresh_access_token", | ||
json=helpers.load_json("testdata/base/threads_user_long_lived_token.json"), | ||
) | ||
|
||
r = api.refresh_access_token(access_token=api.access_token) | ||
assert r["access_token"] == "THQVJ..." |