1010
1111
1212import SoftLayer
13+
1314from SoftLayer import fixtures
1415from SoftLayer import managers
1516from SoftLayer import testing
@@ -320,6 +321,14 @@ def test_cancel_hardware_monthly_whenever(self):
320321 self .assert_called_with ('SoftLayer_Billing_Item' , 'cancelItem' ,
321322 identifier = 6327 , args = (False , False , 'No longer needed' , '' ))
322323
324+ def test_cancel_running_transaction (self ):
325+ mock = self .set_mock ('SoftLayer_Hardware_Server' , 'getObject' )
326+ mock .return_value = {'id' : 987 , 'billingItem' : {'id' : 6327 },
327+ 'activeTransaction' : {'id' : 4567 }}
328+ self .assertRaises (SoftLayer .SoftLayerError ,
329+ self .hardware .cancel_hardware ,
330+ 12345 )
331+
323332 def test_change_port_speed_public (self ):
324333 self .hardware .change_port_speed (2 , True , 100 )
325334
@@ -410,14 +419,102 @@ def test_reflash_firmware_selective(self):
410419 'createFirmwareReflashTransaction' ,
411420 identifier = 100 , args = (1 , 0 , 0 ))
412421
422+ def test_get_tracking_id (self ):
423+ result = self .hardware .get_tracking_id (1234 )
424+ self .assert_called_with ('SoftLayer_Hardware_Server' , 'getMetricTrackingObjectId' )
425+ self .assertEqual (result , 1000 )
426+
427+ def test_get_bandwidth_data (self ):
428+ result = self .hardware .get_bandwidth_data (1234 , '2019-01-01' , '2019-02-01' , 'public' , 1000 )
429+ self .assert_called_with ('SoftLayer_Metric_Tracking_Object' , 'getBandwidthData' , args = ('2019-01-01' , '2019-02-01' ,
430+ 'public' , 1000 ), identifier = 1000 )
431+ self .assertEqual (result [0 ]['type' ], 'cpu0' )
432+
433+ def test_get_bandwidth_allocation (self ):
434+ result = self .hardware .get_bandwidth_allocation (1234 )
435+ self .assert_called_with ('SoftLayer_Hardware_Server' , 'getBandwidthAllotmentDetail' , identifier = 1234 )
436+ self .assert_called_with ('SoftLayer_Hardware_Server' , 'getBillingCycleBandwidthUsage' , identifier = 1234 )
437+ self .assertEqual (result ['allotment' ]['amount' ], '250' )
438+ self .assertEqual (result ['useage' ][0 ]['amountIn' ], '.448' )
439+
413440
414441class HardwareHelperTests (testing .TestCase ):
415442 def test_get_extra_price_id_no_items (self ):
416443 ex = self .assertRaises (SoftLayer .SoftLayerError ,
417444 managers .hardware ._get_extra_price_id ,
418445 [], 'test' , True , None )
419- self .assertEqual ("Could not find valid price for extra option, 'test'" ,
420- str (ex ))
446+ self .assertEqual ("Could not find valid price for extra option, 'test'" , str (ex ))
447+
448+ def test_get_extra_price_mismatched (self ):
449+ items = [
450+ {'keyName' : 'TEST' , 'prices' :[{'id' :1 , 'locationGroupId' : None , 'recurringFee' :99 }]},
451+ {'keyName' : 'TEST' , 'prices' :[{'id' :2 , 'locationGroupId' : 55 , 'hourlyRecurringFee' :99 }]},
452+ {'keyName' : 'TEST' , 'prices' :[{'id' :3 , 'locationGroupId' : None , 'hourlyRecurringFee' :99 }]},
453+ ]
454+ location = {
455+ 'location' : {
456+ 'location' : {
457+ 'priceGroups' : [
458+ {'id' : 50 },
459+ {'id' : 51 }
460+ ]
461+ }
462+ }
463+ }
464+ result = managers .hardware ._get_extra_price_id (items , 'TEST' , True , location )
465+ self .assertEqual (3 , result )
466+
467+ def test_get_bandwidth_price_mismatched (self ):
468+ items = [
469+ {'itemCategory' : {'categoryCode' :'bandwidth' },
470+ 'capacity' : 100 ,
471+ 'prices' :[{'id' :1 , 'locationGroupId' : None , 'hourlyRecurringFee' :99 }]
472+ },
473+ {'itemCategory' : {'categoryCode' :'bandwidth' },
474+ 'capacity' : 100 ,
475+ 'prices' :[{'id' :2 , 'locationGroupId' : 55 , 'recurringFee' :99 }]
476+ },
477+ {'itemCategory' : {'categoryCode' :'bandwidth' },
478+ 'capacity' : 100 ,
479+ 'prices' :[{'id' :3 , 'locationGroupId' : None , 'recurringFee' :99 }]
480+ },
481+ ]
482+ location = {
483+ 'location' : {
484+ 'location' : {
485+ 'priceGroups' : [
486+ {'id' : 50 },
487+ {'id' : 51 }
488+ ]
489+ }
490+ }
491+ }
492+ result = managers .hardware ._get_bandwidth_price_id (items , False , False , location )
493+ self .assertEqual (3 , result )
494+
495+ def test_get_os_price_mismatched (self ):
496+ items = [
497+ {'itemCategory' : {'categoryCode' :'os' },
498+ 'softwareDescription' : {'referenceCode' : 'TEST_OS' },
499+ 'prices' :[{'id' :2 , 'locationGroupId' : 55 , 'recurringFee' :99 }]
500+ },
501+ {'itemCategory' : {'categoryCode' :'os' },
502+ 'softwareDescription' : {'referenceCode' : 'TEST_OS' },
503+ 'prices' :[{'id' :3 , 'locationGroupId' : None , 'recurringFee' :99 }]
504+ },
505+ ]
506+ location = {
507+ 'location' : {
508+ 'location' : {
509+ 'priceGroups' : [
510+ {'id' : 50 },
511+ {'id' : 51 }
512+ ]
513+ }
514+ }
515+ }
516+ result = managers .hardware ._get_os_price_id (items , 'TEST_OS' , location )
517+ self .assertEqual (3 , result )
421518
422519 def test_get_default_price_id_item_not_first (self ):
423520 items = [{
@@ -432,33 +529,85 @@ def test_get_default_price_id_item_not_first(self):
432529 ex = self .assertRaises (SoftLayer .SoftLayerError ,
433530 managers .hardware ._get_default_price_id ,
434531 items , 'unknown' , True , None )
435- self .assertEqual ("Could not find valid price for 'unknown' option" ,
436- str (ex ))
532+ self .assertEqual ("Could not find valid price for 'unknown' option" , str (ex ))
437533
438534 def test_get_default_price_id_no_items (self ):
439535 ex = self .assertRaises (SoftLayer .SoftLayerError ,
440536 managers .hardware ._get_default_price_id ,
441537 [], 'test' , True , None )
442- self .assertEqual ("Could not find valid price for 'test' option" ,
443- str (ex ))
538+ self .assertEqual ("Could not find valid price for 'test' option" , str (ex ))
444539
445540 def test_get_bandwidth_price_id_no_items (self ):
446541 ex = self .assertRaises (SoftLayer .SoftLayerError ,
447542 managers .hardware ._get_bandwidth_price_id ,
448543 [], hourly = True , no_public = False )
449- self .assertEqual ("Could not find valid price for bandwidth option" ,
450- str (ex ))
544+ self .assertEqual ("Could not find valid price for bandwidth option" , str (ex ))
451545
452546 def test_get_os_price_id_no_items (self ):
453547 ex = self .assertRaises (SoftLayer .SoftLayerError ,
454548 managers .hardware ._get_os_price_id ,
455549 [], 'UBUNTU_14_64' , None )
456- self .assertEqual ("Could not find valid price for os: 'UBUNTU_14_64'" ,
457- str (ex ))
550+ self .assertEqual ("Could not find valid price for os: 'UBUNTU_14_64'" , str (ex ))
458551
459552 def test_get_port_speed_price_id_no_items (self ):
460553 ex = self .assertRaises (SoftLayer .SoftLayerError ,
461554 managers .hardware ._get_port_speed_price_id ,
462555 [], 10 , True , None )
463- self .assertEqual ("Could not find valid price for port speed: '10'" ,
464- str (ex ))
556+ self .assertEqual ("Could not find valid price for port speed: '10'" , str (ex ))
557+
558+ def test_get_port_speed_price_id_mismatch (self ):
559+ items = [
560+ {'itemCategory' : {'categoryCode' :'port_speed' },
561+ 'capacity' :101 ,
562+ 'attributes' :[{'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }],
563+ 'prices' :[{'id' :1 , 'locationGroupId' : None , 'recurringFee' :99 }]
564+ },
565+ {'itemCategory' : {'categoryCode' :'port_speed' },
566+ 'capacity' :100 ,
567+ 'attributes' :[{'attributeTypeKeyName' : 'IS_NOT_PRIVATE_NETWORK_ONLY' }],
568+ 'prices' :[{'id' :2 , 'locationGroupId' : 55 , 'recurringFee' :99 }]
569+ },
570+ {'itemCategory' : {'categoryCode' :'port_speed' },
571+ 'capacity' :100 ,
572+ 'attributes' :[{'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }, {'attributeTypeKeyName' : 'NON_LACP' }],
573+ 'prices' :[{'id' :3 , 'locationGroupId' : 55 , 'recurringFee' :99 }]
574+ },
575+ {'itemCategory' : {'categoryCode' :'port_speed' },
576+ 'capacity' :100 ,
577+ 'attributes' :[{'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }],
578+ 'prices' :[{'id' :4 , 'locationGroupId' : 12 , 'recurringFee' :99 }]
579+ },
580+ {'itemCategory' : {'categoryCode' :'port_speed' },
581+ 'capacity' :100 ,
582+ 'attributes' :[{'attributeTypeKeyName' : 'IS_PRIVATE_NETWORK_ONLY' }],
583+ 'prices' :[{'id' :5 , 'locationGroupId' : None , 'recurringFee' :99 }]
584+ },
585+ ]
586+ location = {
587+ 'location' : {
588+ 'location' : {
589+ 'priceGroups' : [
590+ {'id' : 50 },
591+ {'id' : 51 }
592+ ]
593+ }
594+ }
595+ }
596+ result = managers .hardware ._get_port_speed_price_id (items , 100 , True , location )
597+ self .assertEqual (5 , result )
598+
599+ def test_matches_location (self ):
600+ price = {'id' :1 , 'locationGroupId' : 51 , 'recurringFee' :99 }
601+ location = {
602+ 'location' : {
603+ 'location' : {
604+ 'priceGroups' : [
605+ {'id' : 50 },
606+ {'id' : 51 }
607+ ]
608+ }
609+ }
610+ }
611+ result = managers .hardware ._matches_location (price , location )
612+ self .assertTrue (result )
613+
0 commit comments