forked from softlayer/softlayer-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcdn_tests.py
More file actions
134 lines (109 loc) · 4.94 KB
/
cdn_tests.py
File metadata and controls
134 lines (109 loc) · 4.94 KB
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
130
131
132
133
134
"""
SoftLayer.tests.managers.cdn_tests
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
:license: MIT, see LICENSE for more details.
"""
import math
from SoftLayer import fixtures
from SoftLayer.managers import cdn
from SoftLayer import testing
class CDNTests(testing.TestCase):
def set_up(self):
self.cdn_client = cdn.CDNManager(self.client)
def test_list_accounts(self):
accounts = self.cdn_client.list_accounts()
self.assertEqual(accounts, fixtures.SoftLayer_Account.getCdnAccounts)
def test_get_account(self):
account = self.cdn_client.get_account(12345)
self.assertEqual(
account,
fixtures.SoftLayer_Network_ContentDelivery_Account.getObject)
def test_get_origins(self):
origins = self.cdn_client.get_origins(12345)
self.assertEqual(
origins,
fixtures.SoftLayer_Network_ContentDelivery_Account.
getOriginPullMappingInformation)
def test_add_origin(self):
self.cdn_client.add_origin(12345,
'http',
'http://localhost/',
'self.local',
False)
args = ({
'mediaType': 'http',
'originUrl': 'http://localhost/',
'cname': 'self.local',
'isSecureContent': False
},)
self.assert_called_with('SoftLayer_Network_ContentDelivery_Account',
'createOriginPullMapping',
args=args,
identifier=12345)
def test_remove_origin(self):
self.cdn_client.remove_origin(12345, 12345)
self.assert_called_with('SoftLayer_Network_ContentDelivery_Account',
'deleteOriginPullRule',
args=(12345,),
identifier=12345)
def test_load_content(self):
urls = ['http://a/img/0x001.png',
'http://b/img/0x002.png',
'http://c/img/0x004.png',
'http://d/img/0x008.png',
'http://e/img/0x010.png',
'http://e/img/0x020.png']
self.cdn_client.load_content(12345, urls)
calls = self.calls('SoftLayer_Network_ContentDelivery_Account',
'loadContent')
self.assertEqual(len(calls),
math.ceil(len(urls) / float(cdn.MAX_URLS_PER_LOAD)))
def test_load_content_single(self):
url = 'http://geocities.com/Area51/Meteor/12345/under_construction.gif'
self.cdn_client.load_content(12345, url)
self.assert_called_with('SoftLayer_Network_ContentDelivery_Account',
'loadContent',
args=([url],),
identifier=12345)
def test_load_content_failure(self):
urls = ['http://z/img/0x004.png',
'http://y/img/0x002.png',
'http://x/img/0x001.png']
service = self.client['SoftLayer_Network_ContentDelivery_Account']
service.loadContent.return_value = False
self.cdn_client.load_content(12345, urls)
calls = self.calls('SoftLayer_Network_ContentDelivery_Account',
'loadContent')
self.assertEqual(len(calls),
math.ceil(len(urls) / float(cdn.MAX_URLS_PER_LOAD)))
def test_purge_content(self):
urls = ['http://z/img/0x020.png',
'http://y/img/0x010.png',
'http://x/img/0x008.png',
'http://w/img/0x004.png',
'http://v/img/0x002.png',
'http://u/img/0x001.png']
self.cdn_client.purge_content(12345, urls)
calls = self.calls('SoftLayer_Network_ContentDelivery_Account',
'purgeCache')
self.assertEqual(len(calls),
math.ceil(len(urls) / float(cdn.MAX_URLS_PER_PURGE)))
def test_purge_content_failure(self):
urls = ['http://z/img/0x004.png',
'http://y/img/0x002.png',
'http://x/img/0x001.png']
mock = self.set_mock('SoftLayer_Network_ContentDelivery_Account',
'purgeCache')
mock.return_value = False
self.cdn_client.purge_content(12345, urls)
calls = self.calls('SoftLayer_Network_ContentDelivery_Account',
'purgeCache')
self.assertEqual(len(calls),
math.ceil(len(urls) / float(cdn.MAX_URLS_PER_PURGE)))
def test_purge_content_single(self):
url = 'http://geocities.com/Area51/Meteor/12345/under_construction.gif'
self.cdn_client.purge_content(12345, url)
self.assert_called_with('SoftLayer_Network_ContentDelivery_Account',
'purgeCache',
args=([url],),
identifier=12345)