55import uuid
66import random
77
8+ sys .path .insert (0 , os .path .abspath ('.' ))
89sys .path .insert (0 , os .path .abspath ('..' ))
910import CloudFlare
1011
1112# test GET POST PUT PATCH & DELETE - but not in that order
1213
1314cf = None
1415
15- def test_cloudflare ():
16+ def test_cloudflare (debug = False ):
1617 global cf
17- cf = CloudFlare .CloudFlare ()
18+ cf = CloudFlare .CloudFlare (debug = debug )
1819 assert isinstance (cf , CloudFlare .CloudFlare )
1920
2021zone_name = None
2122zone_id = None
2223
23- def test_find_zone ():
24+ def test_find_zone (domain_name = None ):
2425 global zone_name , zone_id
2526 # grab a random zone identifier from the first 10 zones
26- params = {'per_page' :10 }
27- zones = cf .zones .get (params = params )
27+ if domain_name :
28+ params = {'per_page' :1 , 'name' :domain_name }
29+ else :
30+ params = {'per_page' :10 }
31+ try :
32+ zones = cf .zones .get (params = params )
33+ except CloudFlare .exceptions .CloudFlareAPIError as e :
34+ print ('%s: Error %d=%s' % (domain_name , int (e ), str (e )), file = sys .stderr )
35+ exit (0 )
2836 assert len (zones ) > 0 and len (zones ) <= 10
2937 n = random .randrange (len (zones ))
3038 zone_name = zones [n ]['name' ]
@@ -38,7 +46,7 @@ def test_find_zone():
3846dns_content2 = None
3947dns_content3 = None
4048
41- def test_dns_records ():
49+ def test_dns_records_create_values ():
4250 global dns_name , dns_type , dns_content1 , dns_content2 , dns_content3
4351 dns_name = str (uuid .uuid1 ())
4452 dns_type = 'TXT'
@@ -117,3 +125,20 @@ def test_dns_records_get5():
117125 params = {'name' :dns_name + '.' + zone_name , 'match' :'all' , 'type' :dns_type }
118126 dns_results = cf .zones .dns_records .get (zone_id , params = params )
119127 assert len (dns_results ) == 0
128+
129+ if __name__ == '__main__' :
130+ test_cloudflare (debug = True )
131+ if len (sys .argv ) > 1 :
132+ test_find_zone (sys .argv [1 ])
133+ else :
134+ test_find_zone ()
135+ test_dns_records_create_values ()
136+ test_dns_records_get1 ()
137+ test_dns_records_post ()
138+ test_dns_records_get2 ()
139+ test_dns_records_get3 ()
140+ test_dns_records_patch ()
141+ test_dns_records_put ()
142+ test_dns_records_get4 ()
143+ test_dns_records_delete ()
144+ test_dns_records_get5 ()
0 commit comments