-
Notifications
You must be signed in to change notification settings - Fork 1
/
tests.py
129 lines (93 loc) · 3.45 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import argparse
import unittest
from envs import env
from bunnyhop import Bunny
BUNNYCDN_API_KEY = env('BUNNYCDN_API_KEY')
BUNNYCDN_TEST_STORAGE_ZONE = env('BUNNYCDN_TEST_STORAGE_ZONE')
BUNNYCDN_TEST_STORAGE_ZONE_NAME = env('BUNNYCDN_TEST_STORAGE_ZONE_NAME')
BUNNYCDN_TEST_PULL_ZONE = env('BUNNYCDN_TEST_PULL_ZONE')
class TestBilling(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.b = Bunny(BUNNYCDN_API_KEY)
@classmethod
def tearDownClass(cls):
cls.b = None
def test_get(self):
from bunnyhop.billing import BillingSummary
response = self.b.Billing.get()
self.assertIsInstance(response, BillingSummary)
def test_apply_code(self):
response = self.b.Billing.apply_code('dummy-code')
self.assertEqual(response['ErrorKey'], 'code.invalid')
class TestStats(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.b = Bunny(BUNNYCDN_API_KEY)
@classmethod
def tearDownClass(cls):
cls.b = None
def test_get(self):
from bunnyhop.stats import Stats
response = self.b.Stats.get()
self.assertIsInstance(response, Stats)
class TestPurge(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.b = Bunny(BUNNYCDN_API_KEY)
@classmethod
def tearDownClass(cls):
cls.b = None
def test_create(self):
response = self.b.Purge.create("http://non-existentmyzone.b-cdn.net/")
self.assertEqual(response['ErrorKey'], 'purge.hostname_not_found')
class TestStorageZone(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.b = Bunny(BUNNYCDN_API_KEY)
@classmethod
def tearDownClass(cls):
cls.b = None
def test_get(self):
response = self.b.Storage.get(BUNNYCDN_TEST_STORAGE_ZONE)
self.assertEqual(BUNNYCDN_TEST_STORAGE_ZONE_NAME, response.Name)
def test_delete(self):
response = self.b.Storage.delete(1111)
self.assertEqual(response['ErrorKey'], 'storageZone.not_found')
def test_create(self):
response = self.b.Storage.create(1)
self.assertTrue(response['ErrorKey'] == 'storagezone.validation' or response['ErrorKey'] == 'user.insufficient_balance')
def test_all(self):
response = self.b.Storage.all()
self.assertIsInstance(response, list)
class TestZone(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.b = Bunny(BUNNYCDN_API_KEY)
@classmethod
def tearDownClass(cls):
cls.b = None
def test_get(self):
response = self.b.Zone.get("")
self.assertEqual(response, 'Zone not found.')
def test_list(self):
response = self.b.Zone.list()
self.assertIsInstance(response, list)
def test_delete(self):
response = self.b.Zone.delete('test')
self.assertEqual(response['Message'], 'The request is invalid.')
def test_purge(self):
response = self.b.Zone.purge('test')
self.assertEqual(response['Message'], 'The request is invalid.')
def parse_args():
parser = argparse.ArgumentParser(description='Bunnyhop Unit Test')
parser.add_argument('api_key', help='valid api_key to run the functions',
metavar="api_key", type=str)
# other arguments here ...
ns, args = parser.parse_known_args(namespace=unittest)
return ns, sys.argv[:1] + args
if __name__ == '__main__':
import sys
args, argv = parse_args()
sys.argv[:] = argv
unittest.main()