88
99import json
1010
11+ from pprint import pprint as pp
1112
1213class ReportTests (testing .TestCase ):
1314
@@ -76,8 +77,7 @@ def test_bandwidth_report(self):
7677 'hostname' : 'host3' ,
7778 'virtualRack' : {'id' : 2 , 'bandwidthAllotmentTypeId' : 2 },
7879 }]
79- summary_data = self .set_mock ('SoftLayer_Metric_Tracking_Object' ,
80- 'getSummaryData' )
80+ summary_data = self .set_mock ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' )
8181 summary_data .return_value = [
8282 {'type' : 'publicIn_net_octet' , 'counter' : 10 },
8383 {'type' : 'publicOut_net_octet' , 'counter' : 20 },
@@ -93,86 +93,23 @@ def test_bandwidth_report(self):
9393 ])
9494
9595 self .assert_no_fail (result )
96+
9697 stripped_output = '[' + result .output .split ('[' , 1 )[1 ]
97- self .assertEqual ([
98- {
99- 'hostname' : 'pool1' ,
100- 'pool' : None ,
101- 'private_in' : 30 ,
102- 'private_out' : 40 ,
103- 'public_in' : 10 ,
104- 'public_out' : 20 ,
105- 'type' : 'pool'
106- }, {
107- 'hostname' : 'pool3' ,
108- 'pool' : None ,
109- 'private_in' : 30 ,
110- 'private_out' : 40 ,
111- 'public_in' : 10 ,
112- 'public_out' : 20 ,
113- 'type' : 'pool'
114- }, {
115- 'hostname' : 'host1' ,
116- 'pool' : None ,
117- 'private_in' : 30 ,
118- 'private_out' : 40 ,
119- 'public_in' : 10 ,
120- 'public_out' : 20 ,
121- 'type' : 'hardware'
122- }, {
123- 'hostname' : 'host3' ,
124- 'pool' : None ,
125- 'private_in' : 30 ,
126- 'private_out' : 40 ,
127- 'public_in' : 10 ,
128- 'public_out' : 20 ,
129- 'type' : 'hardware'
130- }, {
131- 'hostname' : 'host1' ,
132- 'pool' : None ,
133- 'private_in' : 30 ,
134- 'private_out' : 40 ,
135- 'public_in' : 10 ,
136- 'public_out' : 20 ,
137- 'type' : 'virtual'
138- }, {
139- 'hostname' : 'host3' ,
140- 'pool' : 2 ,
141- 'private_in' : 30 ,
142- 'private_out' : 40 ,
143- 'public_in' : 10 ,
144- 'public_out' : 20 ,
145- 'type' : 'virtual' }],
146- json .loads (stripped_output ),
147- )
148- self .assertEqual (
149- 6 ,
150- len (self .calls ('SoftLayer_Metric_Tracking_Object' ,
151- 'getSummaryData' )),
152- )
153- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
154- 'getSummaryData' ,
155- identifier = 1 )
156- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
157- 'getSummaryData' ,
158- identifier = 3 )
159- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
160- 'getSummaryData' ,
161- identifier = 101 )
162- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
163- 'getSummaryData' ,
164- identifier = 103 )
165- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
166- 'getSummaryData' ,
167- identifier = 201 )
168- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
169- 'getSummaryData' ,
170- identifier = 203 )
171- call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' ,
172- identifier = 1 )[0 ]
173- expected_args = (
174- '2016-02-04 00:00:00 ' ,
175- '2016-03-04 12:34:56 ' ,
98+ json_output = json .loads (stripped_output )
99+ pp (json .loads (stripped_output ))
100+ print ("======= ^^^^^^^^^ ==============" )
101+ self .assertEqual (json_output [0 ]['hostname' ], 'pool1' )
102+ self .assertEqual (json_output [0 ]['private_in' ], 30 )
103+
104+ self .assertEqual (6 , len (self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' )))
105+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 1 )
106+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 3 )
107+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 101 )
108+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 103 )
109+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 201 )
110+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 203 )
111+ call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 1 )[0 ]
112+ expected_args = ('2016-02-04 00:00:00 ' , '2016-03-04 12:34:56 ' ,
176113 [{
177114 'keyName' : 'PUBLICIN' ,
178115 'name' : 'publicIn' ,
@@ -242,64 +179,19 @@ def test_virtual_bandwidth_report(self):
242179
243180 self .assert_no_fail (result )
244181 stripped_output = '[' + result .output .split ('[' , 1 )[1 ]
245- self .assertEqual ([
246- {
247- 'hostname' : 'pool1' ,
248- 'pool' : None ,
249- 'private_in' : 30 ,
250- 'private_out' : 40 ,
251- 'public_in' : 10 ,
252- 'public_out' : 20 ,
253- 'type' : 'pool' ,
254- }, {
255- 'hostname' : 'pool3' ,
256- 'pool' : None ,
257- 'private_in' : 30 ,
258- 'private_out' : 40 ,
259- 'public_in' : 10 ,
260- 'public_out' : 20 ,
261- 'type' : 'pool' ,
262- }, {
263- 'hostname' : 'host1' ,
264- 'pool' : None ,
265- 'private_in' : 30 ,
266- 'private_out' : 40 ,
267- 'public_in' : 10 ,
268- 'public_out' : 20 ,
269- 'type' : 'virtual' ,
270- }, {
271- 'hostname' : 'host3' ,
272- 'pool' : 2 ,
273- 'private_in' : 30 ,
274- 'private_out' : 40 ,
275- 'public_in' : 10 ,
276- 'public_out' : 20 ,
277- 'type' : 'virtual' ,
278- }],
279- json .loads (stripped_output ),
280- )
281- self .assertEqual (
282- 4 ,
283- len (self .calls ('SoftLayer_Metric_Tracking_Object' ,
284- 'getSummaryData' )),
285- )
286- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
287- 'getSummaryData' ,
288- identifier = 1 )
289- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
290- 'getSummaryData' ,
291- identifier = 3 )
292- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
293- 'getSummaryData' ,
294- identifier = 201 )
295- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
296- 'getSummaryData' ,
297- identifier = 203 )
298- call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' ,
299- identifier = 1 )[0 ]
300- expected_args = (
301- '2016-02-04 00:00:00 ' ,
302- '2016-03-04 12:34:56 ' ,
182+ json_output = json .loads (stripped_output )
183+ self .assertEqual (json_output [0 ]['hostname' ], 'pool1' )
184+ self .assertEqual (json_output [1 ]['private_in' ], 0 )
185+ self .assertEqual (json_output [2 ]['private_in' ], 30 )
186+ self .assertEqual (json_output [3 ]['type' ], 'virtual' )
187+
188+ self .assertEqual (4 , len (self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' )))
189+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 1 )
190+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 3 )
191+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 201 )
192+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 203 )
193+ call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 1 )[0 ]
194+ expected_args = ('2016-02-04 00:00:00 ' , '2016-03-04 12:34:56 ' ,
303195 [{
304196 'keyName' : 'PUBLICIN' ,
305197 'name' : 'publicIn' ,
@@ -370,59 +262,18 @@ def test_server_bandwidth_report(self):
370262
371263 self .assert_no_fail (result )
372264 stripped_output = '[' + result .output .split ('[' , 1 )[1 ]
373- self .assertEqual ([
374- {
375- 'hostname' : 'pool1' ,
376- 'pool' : None ,
377- 'private_in' : 30 ,
378- 'private_out' : 40 ,
379- 'public_in' : 10 ,
380- 'public_out' : 20 ,
381- 'type' : 'pool' ,
382- }, {
383- 'hostname' : 'pool3' ,
384- 'pool' : None ,
385- 'private_in' : 30 ,
386- 'private_out' : 40 ,
387- 'public_in' : 10 ,
388- 'public_out' : 20 ,
389- 'type' : 'pool' ,
390- }, {
391- 'hostname' : 'host1' ,
392- 'pool' : None ,
393- 'private_in' : 30 ,
394- 'private_out' : 40 ,
395- 'public_in' : 10 ,
396- 'public_out' : 20 ,
397- 'type' : 'hardware' ,
398- }, {
399- 'hostname' : 'host3' ,
400- 'pool' : None ,
401- 'private_in' : 30 ,
402- 'private_out' : 40 ,
403- 'public_in' : 10 ,
404- 'public_out' : 20 ,
405- 'type' : 'hardware' ,
406- }, ],
407- json .loads (stripped_output ),
408- )
409- self .assertEqual (
410- 4 ,
411- len (self .calls ('SoftLayer_Metric_Tracking_Object' ,
412- 'getSummaryData' )),
413- )
414- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
415- 'getSummaryData' ,
416- identifier = 101 )
417- self .assert_called_with ('SoftLayer_Metric_Tracking_Object' ,
418- 'getSummaryData' ,
419- identifier = 103 )
265+ json_output = json .loads (stripped_output )
266+ self .assertEqual (json_output [0 ]['hostname' ], 'pool1' )
267+ self .assertEqual (json_output [1 ]['private_in' ], 0 )
268+ self .assertEqual (json_output [2 ]['private_in' ], 30 )
269+ self .assertEqual (json_output [3 ]['type' ], 'hardware' )
270+
271+ self .assertEqual (4 , len (self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' )))
272+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 101 )
273+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 103 )
420274
421- call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' ,
422- identifier = 1 )[0 ]
423- expected_args = (
424- '2016-02-04 00:00:00 ' ,
425- '2016-03-04 12:34:56 ' ,
275+ call = self .calls ('SoftLayer_Metric_Tracking_Object' , 'getSummaryData' , identifier = 1 )[0 ]
276+ expected_args = ('2016-02-04 00:00:00 ' , '2016-03-04 12:34:56 ' ,
426277 [{
427278 'keyName' : 'PUBLICIN' ,
428279 'name' : 'publicIn' ,
0 commit comments