Skip to content
This repository has been archived by the owner on Nov 22, 2024. It is now read-only.

Commit

Permalink
tests more return values
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Dec 31, 2023
1 parent fb245ee commit 5622686
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions CloudFlare/tests/test_api_dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import os
import sys
import re

sys.path.insert(0, os.path.abspath('.'))
sys.path.insert(0, os.path.abspath('..'))
Expand All @@ -18,17 +19,49 @@ def test_cloudflare(debug=False):
cf = CloudFlare.CloudFlare(debug=debug)
assert isinstance(cf, CloudFlare.CloudFlare)

def test_dump_commands():
verb_only = re.compile('^[a-zA-Z0-9][a-zA-Z0-9_\-]*[a-zA-Z0-9]$')

def check_cmd_syntax(cmd):
assert '/' == cmd[0]
for verb in cmd[1:].split('/'):
if verb[0] == '@':
# don't want to check the rest of the api - it's an AI one
break
if verb[0] == ':':
# :id or equiv
assert bool(verb_only.match(verb[1:]))
else:
# just a verb
assert bool(verb_only.match(verb))

def check_method_syntax(method):
assert method in ['GET', 'POST', 'PATCH', 'PUT', 'DELETE']

def test_api_list():
"""dump a tree of all the known API commands"""
w = cf.api_list()
assert len(w) > 0
api_list = cf.api_list()
assert len(api_list) > 0
for api in api_list:
check_cmd_syntax(api)

def test_api_from_openapi():
"""dump a tree of all the known API commands - from web"""
api_list = cf.api_from_openapi()
assert len(api_list) > 0
for api in api_list:
# {'action': 'GET', 'cmd': '/accounts', 'deprecated': ...
assert 'action' in api
assert 'cmd' in api
check_method_syntax(api['action'])
check_cmd_syntax(api['cmd'])

def test_dump_commands_from_web():
def test_api_from_openapi_with_url():
"""dump a tree of all the known API commands - from web"""
w = cf.api_from_openapi(OPENAPI_URL)
assert len(w) > 0
api_list = cf.api_from_openapi(OPENAPI_URL)
assert len(api_list) > 0

if __name__ == '__main__':
test_cloudflare(debug=True)
test_dump_commands()
test_dump_commands_from_web()
test_api_list()
test_api_from_openapi()
test_api_from_openapi_with_url()

0 comments on commit 5622686

Please sign in to comment.