|
| 1 | +""" dump api tests """ |
| 2 | + |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | +sys.path.insert(0, os.path.abspath('.')) |
| 7 | +sys.path.insert(0, os.path.abspath('..')) |
| 8 | +import CloudFlare |
| 9 | + |
| 10 | +# test API list fetches from Cloudflare website |
| 11 | + |
| 12 | +cf = None |
| 13 | + |
| 14 | +def test_cloudflare(): |
| 15 | + global cf |
| 16 | + cf = CloudFlare.CloudFlare() |
| 17 | + assert isinstance(cf, CloudFlare.CloudFlare) |
| 18 | + |
| 19 | +def test_app_invalid(): |
| 20 | + """add API commands""" |
| 21 | + cf.add('OPEN', 'invalid') |
| 22 | + try: |
| 23 | + results = cf.invalid() |
| 24 | + print('error - should not reach here') |
| 25 | + assert False |
| 26 | + except CloudFlare.exceptions.CloudFlareAPIError as e: |
| 27 | + # error 7000 No route for that URI |
| 28 | + assert int(e) == 7000 |
| 29 | + assert str(e) == 'No route for that URI' |
| 30 | + print(int(e), str(e)) |
| 31 | + |
| 32 | +def test_app_invalid_with_underscore(): |
| 33 | + """add API commands""" |
| 34 | + cf.add('OPEN', 'in_valid') |
| 35 | + try: |
| 36 | + results = cf.in_valid() |
| 37 | + print('error - should not reach here') |
| 38 | + assert False |
| 39 | + except CloudFlare.exceptions.CloudFlareAPIError as e: |
| 40 | + # error 7000 No route for that URI |
| 41 | + assert int(e) == 7000 |
| 42 | + assert str(e) == 'No route for that URI' |
| 43 | + print(int(e), str(e)) |
| 44 | + |
| 45 | +def test_app_invalid_with_dash(): |
| 46 | + """add API commands""" |
| 47 | + cf.add('OPEN', 'in-val-id') |
| 48 | + try: |
| 49 | + results = cf.in_val_id() |
| 50 | + print('error - should not reach here') |
| 51 | + assert False |
| 52 | + except CloudFlare.exceptions.CloudFlareAPIError as e: |
| 53 | + # error 7000 No route for that URI |
| 54 | + assert int(e) == 7000 |
| 55 | + assert str(e) == 'No route for that URI' |
| 56 | + print(int(e), str(e)) |
| 57 | + |
| 58 | +if __name__ == '__main__': |
| 59 | + test_cloudflare() |
| 60 | + test_app_invalid() |
| 61 | + test_app_invalid_with_underscore() |
| 62 | + test_app_invalid_with_dash() |
| 63 | + |
0 commit comments