refactor tests folder
This commit is contained in:
12
tests/data/get_user_details.json
Normal file
12
tests/data/get_user_details.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"date_joined": "2022-10-04 00:46:37",
|
||||
"email": "lpm0073@gmail.com",
|
||||
"first_name": "Lawrence",
|
||||
"fullname": "Lawrence McDaniel",
|
||||
"id": 6,
|
||||
"is_staff": true,
|
||||
"is_superuser": true,
|
||||
"last_name": "McDaniel",
|
||||
"user_status": "0",
|
||||
"username": "mcdaniel"
|
||||
}
|
17
tests/data/get_user_details_extended.json
Normal file
17
tests/data/get_user_details_extended.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"access_token": "bftc1ostvp3fucj9sxzkdgonnhcoi9uuqq2da93m",
|
||||
"date_joined": "2022-10-04 00:46:37",
|
||||
"email": "lpm0073@gmail.com",
|
||||
"expires_in": 3600,
|
||||
"first_name": "Lawrence",
|
||||
"fullname": "Lawrence McDaniel",
|
||||
"id": 6,
|
||||
"is_staff": true,
|
||||
"is_superuser": true,
|
||||
"last_name": "McDaniel",
|
||||
"refresh_token": "",
|
||||
"scope": "",
|
||||
"token_type": "",
|
||||
"user_status": "0",
|
||||
"username": "mcdaniel"
|
||||
}
|
7
tests/data/wp-oauth-me.json
Normal file
7
tests/data/wp-oauth-me.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"access_token": "x39tb1rws4gcpsyvahkofrj7xwnrefxuk3jonrjn",
|
||||
"expires_in": 3600,
|
||||
"refresh_token": "bo85pscgut9nqy56snnzgw6ixljzspac3f74eemy",
|
||||
"scope": "basic profile email",
|
||||
"token_type": "Bearer"
|
||||
}
|
4
tests/data/wp-oauth-response-expired-token.json
Normal file
4
tests/data/wp-oauth-response-expired-token.json
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"error": "expired_token",
|
||||
"error_description": "The access token provided has expired"
|
||||
}
|
98
tests/data/wp-oauth-response.json
Normal file
98
tests/data/wp-oauth-response.json
Normal file
@ -0,0 +1,98 @@
|
||||
{
|
||||
"ID": "6",
|
||||
"capabilities": {
|
||||
"access_white_label_branding": true,
|
||||
"activate_plugins": true,
|
||||
"administrator": true,
|
||||
"copy_posts": true,
|
||||
"create_roles": true,
|
||||
"create_users": true,
|
||||
"delete_others_pages": true,
|
||||
"delete_others_posts": true,
|
||||
"delete_pages": true,
|
||||
"delete_plugins": true,
|
||||
"delete_posts": true,
|
||||
"delete_private_pages": true,
|
||||
"delete_private_posts": true,
|
||||
"delete_published_pages": true,
|
||||
"delete_published_posts": true,
|
||||
"delete_roles": true,
|
||||
"delete_themes": true,
|
||||
"delete_users": true,
|
||||
"edit_dashboard": true,
|
||||
"edit_files": true,
|
||||
"edit_others_pages": true,
|
||||
"edit_others_posts": true,
|
||||
"edit_pages": true,
|
||||
"edit_plugins": true,
|
||||
"edit_posts": true,
|
||||
"edit_private_pages": true,
|
||||
"edit_private_posts": true,
|
||||
"edit_published_pages": true,
|
||||
"edit_published_posts": true,
|
||||
"edit_roles": true,
|
||||
"edit_theme_options": true,
|
||||
"edit_themes": true,
|
||||
"edit_users": true,
|
||||
"export": true,
|
||||
"import": true,
|
||||
"install_plugins": true,
|
||||
"install_themes": true,
|
||||
"level_0": true,
|
||||
"level_1": true,
|
||||
"level_10": true,
|
||||
"level_2": true,
|
||||
"level_3": true,
|
||||
"level_4": true,
|
||||
"level_5": true,
|
||||
"level_6": true,
|
||||
"level_7": true,
|
||||
"level_8": true,
|
||||
"level_9": true,
|
||||
"list_roles": true,
|
||||
"list_users": true,
|
||||
"manage_categories": true,
|
||||
"manage_links": true,
|
||||
"manage_options": true,
|
||||
"moderate_comments": true,
|
||||
"promote_users": true,
|
||||
"publish_pages": true,
|
||||
"publish_posts": true,
|
||||
"read": true,
|
||||
"read_private_pages": true,
|
||||
"read_private_posts": true,
|
||||
"remove_users": true,
|
||||
"restrict_content": true,
|
||||
"rocket_manage_options": true,
|
||||
"rocket_preload_cache": true,
|
||||
"rocket_purge_cache": true,
|
||||
"rocket_purge_cloudflare_cache": true,
|
||||
"rocket_purge_opcache": true,
|
||||
"rocket_purge_posts": true,
|
||||
"rocket_purge_sucuri_cache": true,
|
||||
"rocket_purge_terms": true,
|
||||
"rocket_purge_users": true,
|
||||
"rocket_regenerate_critical_css": true,
|
||||
"rocket_remove_unused_css": true,
|
||||
"switch_themes": true,
|
||||
"unfiltered_html": true,
|
||||
"unfiltered_upload": true,
|
||||
"update_core": true,
|
||||
"update_plugins": true,
|
||||
"update_themes": true,
|
||||
"upload_files": true,
|
||||
"wf2fa_activate_2fa_others": true,
|
||||
"wf2fa_activate_2fa_self": true,
|
||||
"wf2fa_manage_settings": true,
|
||||
"wpseo_manage_options": true
|
||||
},
|
||||
"display_name": "Lawrence McDaniel",
|
||||
"user_email": "lpm0073@gmail.com",
|
||||
"user_login": "mcdaniel",
|
||||
"user_nicename": "mcdaniel",
|
||||
"user_registered": "2022-10-04 00:46:37",
|
||||
"user_roles": [
|
||||
"administrator"
|
||||
],
|
||||
"user_status": "0"
|
||||
}
|
49
tests/tests.py
Normal file
49
tests/tests.py
Normal file
@ -0,0 +1,49 @@
|
||||
import json
|
||||
|
||||
# Opening JSON file
|
||||
f = open("./data/get_user_details_extended.json")
|
||||
|
||||
# returns JSON object as
|
||||
# a dictionary
|
||||
response = json.load(f)
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
print("is_valid_user_details")
|
||||
print(is_valid_user_details(response))
|
||||
|
||||
print("is_wp_oauth_refresh_token_response")
|
||||
print(is_wp_oauth_refresh_token_response(response))
|
Reference in New Issue
Block a user