edx-oauth2-wordpress-backend/tests/tests.py

50 lines
1.1 KiB
Python
Raw Normal View History

2022-10-06 20:45:15 +03:00
import json
2022-10-06 21:05:02 +03:00
2022-10-06 20:45:15 +03:00
# Opening JSON file
2022-10-06 21:06:51 +03:00
f = open("./data/get_user_details_extended.json")
2022-10-06 21:05:02 +03:00
# returns JSON object as
2022-10-06 20:45:15 +03:00
# a dictionary
response = json.load(f)
2022-10-06 21:05:02 +03:00
2022-10-06 20:45:15 +03:00
def is_valid_user_details(response) -> bool:
"""
validate that the object passed is a dict containing at least the keys
in qc_keys.
"""
qc_keys = [
"id",
"date_joined",
"email",
"first_name",
"fullname",
"is_staff",
"is_superuser",
"last_name",
"username",
]
if all(key in response for key in qc_keys):
return True
return False
2022-10-06 21:05:02 +03:00
2022-10-06 20:45:15 +03:00
def is_wp_oauth_refresh_token_response(response) -> bool:
"""
validate that the structure of the response contains the keys of
a refresh token dict.
"""
if not is_valid_user_details(response):
return False
qc_keys = ["access_token", "expires_in", "refresh_token", "scope", "token_type"]
if all(key in response for key in qc_keys):
return True
return False
2022-10-06 21:05:02 +03:00
print("is_valid_user_details")
2022-10-06 20:45:15 +03:00
print(is_valid_user_details(response))
2022-10-06 21:05:02 +03:00
print("is_wp_oauth_refresh_token_response")
2022-10-06 20:45:15 +03:00
print(is_wp_oauth_refresh_token_response(response))