Skip to content

Commit

Permalink
#1764 lowered a value in the unit tests below max 32bit int
Browse files Browse the repository at this point in the history
  • Loading branch information
allmightyspiff committed Oct 6, 2022
1 parent 4bad4e6 commit 7c414fd
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 25 deletions.
2 changes: 1 addition & 1 deletion SoftLayer/CLI/cdn/detail.py
Expand Up @@ -41,6 +41,6 @@ def cli(env, unique_id, history):
table.add_row(['status', cdn_mapping['status']])
table.add_row(['total_bandwidth', total_bandwidth])
table.add_row(['total_hits', total_hits])
table.add_row(['hit_radio', hit_ratio])
table.add_row(['hit_ratio', hit_ratio])

env.fout(table)
Expand Up @@ -11,7 +11,7 @@
"path": "/",
"protocol": "HTTP",
"status": "CNAME_CONFIGURATION",
"uniqueId": "9934111111111",
"uniqueId": "11223344",
"vendorName": "akamai"
}
]
Expand All @@ -28,7 +28,7 @@
"path": "/",
"protocol": "HTTP",
"status": "CNAME_CONFIGURATION",
"uniqueId": "9934111111111",
"uniqueId": "11223344",
"vendorName": "akamai"
}
]
Expand All @@ -41,7 +41,7 @@
"performanceConfiguration": "Large file optimization",
"protocol": "HTTP",
"respectHeaders": True,
"uniqueId": "424406419091111",
"uniqueId": "11223344",
"vendorName": "akamai",
"header": "www.test.com",
"httpPort": 83,
Expand Down
Expand Up @@ -6,9 +6,9 @@
"HitRatio"
],
"totals": [
"0.0",
"0",
"0.0"
1.0,
3,
2.0
],
"type": "TOTALS"
}
Expand Down
23 changes: 8 additions & 15 deletions tests/CLI/modules/cdn_tests.py
Expand Up @@ -21,27 +21,20 @@ def test_list_accounts(self):
'domain': 'test.example.com',
'origin': '1.1.1.1',
'status': 'CNAME_CONFIGURATION',
'unique_id': '9934111111111',
'unique_id': '11223344',
'vendor': 'akamai'}]
)

def test_detail_account(self):
result = self.run_command(['cdn', 'detail', '--history=30', '1245'])

self.assert_no_fail(result)
self.assertEqual(json.loads(result.output),
{'hit_radio': '0.0 %',
'hostname': 'test.example.com',
'origin': '1.1.1.1',
'origin_type': 'HOST_SERVER',
'path': '/',
'protocol': 'HTTP',
'provider': 'akamai',
'status': 'CNAME_CONFIGURATION',
'total_bandwidth': '0.0 GB',
'total_hits': '0',
'unique_id': '9934111111111'}
)
api_results = json.loads(result.output)
self.assertEqual(api_results['hit_ratio'], '2.0 %')
self.assertEqual(api_results['total_bandwidth'], '1.0 GB')
self.assertEqual(api_results['total_hits'], 3)
self.assertEqual(api_results['hostname'], 'test.example.com')
self.assertEqual(api_results['protocol'], 'HTTP')

def test_purge_content(self):
result = self.run_command(['cdn', 'purge', '1234',
Expand Down Expand Up @@ -122,7 +115,7 @@ def test_edit_cache(self):
self.assertEqual('include: test', header_result['Cache key optimization'])

def test_edit_cache_by_uniqueId(self):
result = self.run_command(['cdn', 'edit', '9934111111111', '--cache', 'include-specified', '--cache', 'test'])
result = self.run_command(['cdn', 'edit', '11223344', '--cache', 'include-specified', '--cache', 'test'])
self.assert_no_fail(result)
header_result = json.loads(result.output)
self.assertEqual('include: test', header_result['Cache key optimization'])
20 changes: 17 additions & 3 deletions tests/managers/cdn_tests.py
Expand Up @@ -8,6 +8,8 @@
from SoftLayer import fixtures
from SoftLayer.managers import cdn
from SoftLayer import testing
from unittest import mock as mock
import datetime


class CDNTests(testing.TestCase):
Expand All @@ -28,7 +30,9 @@ def test_detail_cdn(self):
'listDomainMappingByUniqueId',
args=args)

def test_detail_usage_metric(self):
@mock.patch('SoftLayer.utils.days_to_datetime')
def test_detail_usage_metric(self, mock_now):
mock_now.return_value = datetime.datetime(2020, 1, 1)
self.cdn_client.get_usage_metrics(12345, history=30, frequency="aggregate")

args = (12345,
Expand All @@ -39,6 +43,16 @@ def test_detail_usage_metric(self):
'getMappingUsageMetrics',
args=args)

# Does this still work in 2038 ? https://github.com/softlayer/softlayer-python/issues/1764 for context
@mock.patch('SoftLayer.utils.days_to_datetime')
def test_detail_usage_metric_future(self, mock_now):
mock_now.return_value = datetime.datetime(2040, 1, 1)
self.assertRaises(
OverflowError,
self.cdn_client.get_usage_metrics, 12345, history=30, frequency="aggregate"
)


def test_get_origins(self):
self.cdn_client.get_origins("12345")
self.assert_called_with('SoftLayer_Network_CdnMarketplace_Configuration_Mapping_Path',
Expand Down Expand Up @@ -105,7 +119,7 @@ def test_purge_content(self):
args=args)

def test_cdn_edit(self):
identifier = '9934111111111'
identifier = '11223344'
header = 'www.test.com'
result = self.cdn_client.edit(identifier, header=header)

Expand All @@ -116,7 +130,7 @@ def test_cdn_edit(self):
'SoftLayer_Network_CdnMarketplace_Configuration_Mapping',
'updateDomainMapping',
args=({
'uniqueId': '9934111111111',
'uniqueId': '11223344',
'originType': 'HOST_SERVER',
'protocol': 'HTTP',
'path': '/',
Expand Down

0 comments on commit 7c414fd

Please sign in to comment.