44
55 :license: MIT, see LICENSE for more details.
66"""
7+ import datetime
78import json
9+ from unittest import mock as mock
810
911from SoftLayer .CLI import exceptions
1012from SoftLayer import testing
@@ -21,27 +23,22 @@ def test_list_accounts(self):
2123 'domain' : 'test.example.com' ,
2224 'origin' : '1.1.1.1' ,
2325 'status' : 'CNAME_CONFIGURATION' ,
24- 'unique_id' : '9934111111111 ' ,
26+ 'unique_id' : '11223344 ' ,
2527 'vendor' : 'akamai' }]
2628 )
2729
28- def test_detail_account (self ):
30+ @mock .patch ('SoftLayer.utils.days_to_datetime' )
31+ def test_detail_account (self , mock_now ):
32+ mock_now .return_value = datetime .datetime (2020 , 1 , 1 )
2933 result = self .run_command (['cdn' , 'detail' , '--history=30' , '1245' ])
3034
3135 self .assert_no_fail (result )
32- self .assertEqual (json .loads (result .output ),
33- {'hit_radio' : '0.0 %' ,
34- 'hostname' : 'test.example.com' ,
35- 'origin' : '1.1.1.1' ,
36- 'origin_type' : 'HOST_SERVER' ,
37- 'path' : '/' ,
38- 'protocol' : 'HTTP' ,
39- 'provider' : 'akamai' ,
40- 'status' : 'CNAME_CONFIGURATION' ,
41- 'total_bandwidth' : '0.0 GB' ,
42- 'total_hits' : '0' ,
43- 'unique_id' : '9934111111111' }
44- )
36+ api_results = json .loads (result .output )
37+ self .assertEqual (api_results ['hit_ratio' ], '2.0 %' )
38+ self .assertEqual (api_results ['total_bandwidth' ], '1.0 GB' )
39+ self .assertEqual (api_results ['total_hits' ], 3 )
40+ self .assertEqual (api_results ['hostname' ], 'test.example.com' )
41+ self .assertEqual (api_results ['protocol' ], 'HTTP' )
4542
4643 def test_purge_content (self ):
4744 result = self .run_command (['cdn' , 'purge' , '1234' ,
@@ -122,7 +119,7 @@ def test_edit_cache(self):
122119 self .assertEqual ('include: test' , header_result ['Cache key optimization' ])
123120
124121 def test_edit_cache_by_uniqueId (self ):
125- result = self .run_command (['cdn' , 'edit' , '9934111111111 ' , '--cache' , 'include-specified' , '--cache' , 'test' ])
122+ result = self .run_command (['cdn' , 'edit' , '11223344 ' , '--cache' , 'include-specified' , '--cache' , 'test' ])
126123 self .assert_no_fail (result )
127124 header_result = json .loads (result .output )
128125 self .assertEqual ('include: test' , header_result ['Cache key optimization' ])
0 commit comments