|
| 1 | +""" get/post/delete/etc dns based tests """ |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | +import uuid |
| 6 | + |
| 7 | +sys.path.insert(0, os.path.abspath('..')) |
| 8 | +import CloudFlare |
| 9 | + |
| 10 | +# test GET POST PUT PATCH & DELETE - but not in that order |
| 11 | + |
| 12 | +cf = None |
| 13 | +zone_name = None |
| 14 | +zone_id = None |
| 15 | + |
| 16 | +def test_cloudflare(): |
| 17 | + global cf |
| 18 | + cf = CloudFlare.CloudFlare() |
| 19 | + assert isinstance(cf, CloudFlare.CloudFlare) |
| 20 | + |
| 21 | +def test_find_zone(): |
| 22 | + global zone_name, zone_id |
| 23 | + # grab the first zone identifier |
| 24 | + params = {'per_page':1} |
| 25 | + zones = cf.zones.get(params=params) |
| 26 | + assert len(zones) == 1 |
| 27 | + zone_name = zones[0]['name'] |
| 28 | + zone_id = zones[0]['id'] |
| 29 | + assert len(zone_id) == 32 |
| 30 | + print('zone: %s %s' % (zone_id, zone_name)) |
| 31 | + |
| 32 | +dns_name = None |
| 33 | +dns_type = None |
| 34 | +dns_content1 = None |
| 35 | +dns_content2 = None |
| 36 | +dns_content3 = None |
| 37 | + |
| 38 | +def test_dns_records(): |
| 39 | + global dns_name, dns_type, dns_content1, dns_content2, dns_content3 |
| 40 | + dns_name = str(uuid.uuid1()) |
| 41 | + dns_type = 'TXT' |
| 42 | + dns_content1 = 'temp pytest element 1' |
| 43 | + dns_content2 = 'temp pytest element 2' |
| 44 | + dns_content3 = 'temp pytest element 3' |
| 45 | + print('dns_record: %s' % (dns_name)) |
| 46 | + |
| 47 | +def test_dns_records_get(): |
| 48 | + # GET |
| 49 | + params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type} |
| 50 | + dns_results = cf.zones.dns_records.get(zone_id, params=params) |
| 51 | + assert len(dns_results) == 0 |
| 52 | + |
| 53 | +dns_id = None |
| 54 | + |
| 55 | +def test_dns_records_post(): |
| 56 | + global dns_id |
| 57 | + # POST |
| 58 | + dns_record = {'name':dns_name, 'type':dns_type, 'content':dns_content1} |
| 59 | + dns_result = cf.zones.dns_records.post(zone_id, data=dns_record) |
| 60 | + assert dns_result['name'] == dns_name + '.' + zone_name |
| 61 | + assert dns_result['type'] == dns_type |
| 62 | + assert dns_result['content'] == dns_content1 |
| 63 | + |
| 64 | + dns_id = dns_result['id'] |
| 65 | + assert len(dns_id) == 32 |
| 66 | + print('dns_record: %s %s' % (dns_name, dns_id)) |
| 67 | + |
| 68 | +def test_dns_records_get(): |
| 69 | + # GET |
| 70 | + params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type} |
| 71 | + dns_results = cf.zones.dns_records.get(zone_id, params=params) |
| 72 | + assert len(dns_results) == 1 |
| 73 | + assert dns_results[0]['name'] == dns_name + '.' + zone_name |
| 74 | + assert dns_results[0]['type'] == dns_type |
| 75 | + assert dns_results[0]['content'] == dns_content1 |
| 76 | + |
| 77 | +def test_dns_records_get(): |
| 78 | + # GET |
| 79 | + dns_result = cf.zones.dns_records.get(zone_id, dns_id) |
| 80 | + assert dns_result['name'] == dns_name + '.' + zone_name |
| 81 | + assert dns_result['type'] == dns_type |
| 82 | + assert dns_result['content'] == dns_content1 |
| 83 | + |
| 84 | +def test_dns_records_patch(): |
| 85 | + # PATCH |
| 86 | + dns_record = {'content':dns_content2} |
| 87 | + dns_result = cf.zones.dns_records.patch(zone_id, dns_id, data=dns_record) |
| 88 | + assert dns_result['name'] == dns_name + '.' + zone_name |
| 89 | + assert dns_result['type'] == dns_type |
| 90 | + assert dns_result['content'] == dns_content2 |
| 91 | + |
| 92 | +def test_dns_records_put(): |
| 93 | + # PUT |
| 94 | + dns_record = {'name':dns_name, 'type':dns_type, 'content':dns_content3} |
| 95 | + dns_result = cf.zones.dns_records.put(zone_id, dns_id, data=dns_record) |
| 96 | + assert dns_result['name'] == dns_name + '.' + zone_name |
| 97 | + assert dns_result['type'] == dns_type |
| 98 | + assert dns_result['content'] == dns_content3 |
| 99 | + |
| 100 | +def test_dns_records_get(): |
| 101 | + # GET |
| 102 | + dns_result = cf.zones.dns_records.get(zone_id, dns_id) |
| 103 | + assert dns_result['name'] == dns_name + '.' + zone_name |
| 104 | + assert dns_result['type'] == dns_type |
| 105 | + assert dns_result['content'] == dns_content3 |
| 106 | + |
| 107 | +def test_dns_records_delete(): |
| 108 | + # DELETE |
| 109 | + dns_result = cf.zones.dns_records.delete(zone_id, dns_id) |
| 110 | + assert dns_result['id'] == dns_id |
| 111 | + |
| 112 | +def test_dns_records_get(): |
| 113 | + # GET |
| 114 | + params = {'name':dns_name + '.' + zone_name, 'match':'all', 'type':dns_type} |
| 115 | + dns_results = cf.zones.dns_records.get(zone_id, params=params) |
| 116 | + assert len(dns_results) == 0 |
0 commit comments