22
33import os
44import sys
5+ import re
56
67sys .path .insert (0 , os .path .abspath ('.' ))
78sys .path .insert (0 , os .path .abspath ('..' ))
@@ -18,17 +19,49 @@ def test_cloudflare(debug=False):
1819 cf = CloudFlare .CloudFlare (debug = debug )
1920 assert isinstance (cf , CloudFlare .CloudFlare )
2021
21- def test_dump_commands ():
22+ verb_only = re .compile ('^[a-zA-Z0-9][a-zA-Z0-9_\-]*[a-zA-Z0-9]$' )
23+
24+ def check_cmd_syntax (cmd ):
25+ assert '/' == cmd [0 ]
26+ for verb in cmd [1 :].split ('/' ):
27+ if verb [0 ] == '@' :
28+ # don't want to check the rest of the api - it's an AI one
29+ break
30+ if verb [0 ] == ':' :
31+ # :id or equiv
32+ assert bool (verb_only .match (verb [1 :]))
33+ else :
34+ # just a verb
35+ assert bool (verb_only .match (verb ))
36+
37+ def check_method_syntax (method ):
38+ assert method in ['GET' , 'POST' , 'PATCH' , 'PUT' , 'DELETE' ]
39+
40+ def test_api_list ():
2241 """dump a tree of all the known API commands"""
23- w = cf .api_list ()
24- assert len (w ) > 0
42+ api_list = cf .api_list ()
43+ assert len (api_list ) > 0
44+ for api in api_list :
45+ check_cmd_syntax (api )
46+
47+ def test_api_from_openapi ():
48+ """dump a tree of all the known API commands - from web"""
49+ api_list = cf .api_from_openapi ()
50+ assert len (api_list ) > 0
51+ for api in api_list :
52+ # {'action': 'GET', 'cmd': '/accounts', 'deprecated': ...
53+ assert 'action' in api
54+ assert 'cmd' in api
55+ check_method_syntax (api ['action' ])
56+ check_cmd_syntax (api ['cmd' ])
2557
26- def test_dump_commands_from_web ():
58+ def test_api_from_openapi_with_url ():
2759 """dump a tree of all the known API commands - from web"""
28- w = cf .api_from_openapi (OPENAPI_URL )
29- assert len (w ) > 0
60+ api_list = cf .api_from_openapi (OPENAPI_URL )
61+ assert len (api_list ) > 0
3062
3163if __name__ == '__main__' :
3264 test_cloudflare (debug = True )
33- test_dump_commands ()
34- test_dump_commands_from_web ()
65+ test_api_list ()
66+ test_api_from_openapi ()
67+ test_api_from_openapi_with_url ()
0 commit comments