@@ -283,32 +283,49 @@ def test_get_preset_by_key_preset_not_found(self):
283283 self .assertEqual ('Preset {} does not exist in package {}' .format (keyname , 'PACKAGE_KEYNAME' ), str (exc ))
284284
285285 def test_get_price_id_list (self ):
286- price1 = {'id' : 1234 , 'locationGroupId' : None }
287- item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'prices' : [price1 ]}
288- price2 = {'id' : 5678 , 'locationGroupId' : None }
289- item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'prices' : [price2 ]}
286+ category1 = {'categoryCode' : 'cat1' }
287+ price1 = {'id' : 1234 , 'locationGroupId' : None , 'itemCategory' : [category1 ]}
288+ item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'itemCategory' : category1 , 'prices' : [price1 ]}
289+ category2 = {'categoryCode' : 'cat2' }
290+ price2 = {'id' : 5678 , 'locationGroupId' : None , 'categories' : [category2 ]}
291+ item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'itemCategory' : category2 , 'prices' : [price2 ]}
290292
291293 with mock .patch .object (self .ordering , 'list_items' ) as list_mock :
292294 list_mock .return_value = [item1 , item2 ]
293295
294296 prices = self .ordering .get_price_id_list ('PACKAGE_KEYNAME' , ['ITEM1' , 'ITEM2' ])
295297
296- list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, keyName, prices' )
298+ list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, itemCategory, keyName, prices[categories] ' )
297299 self .assertEqual ([price1 ['id' ], price2 ['id' ]], prices )
298300
299301 def test_get_price_id_list_item_not_found (self ):
300- price1 = {'id' : 1234 , 'locationGroupId' : '' }
301- item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'prices' : [price1 ]}
302+ category1 = {'categoryCode' : 'cat1' }
303+ price1 = {'id' : 1234 , 'locationGroupId' : '' , 'categories' : [category1 ]}
304+ item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'itemCategory' : category1 , 'prices' : [price1 ]}
302305
303306 with mock .patch .object (self .ordering , 'list_items' ) as list_mock :
304307 list_mock .return_value = [item1 ]
305308
306309 exc = self .assertRaises (exceptions .SoftLayerError ,
307310 self .ordering .get_price_id_list ,
308311 'PACKAGE_KEYNAME' , ['ITEM2' ])
309- list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, keyName, prices' )
312+ list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, itemCategory, keyName, prices[categories] ' )
310313 self .assertEqual ("Item ITEM2 does not exist for package PACKAGE_KEYNAME" , str (exc ))
311314
315+ def test_get_price_id_list_gpu_items_with_two_categories (self ):
316+ # Specific for GPU prices which are differentiated by their category (gpu0, gpu1)
317+ price1 = {'id' : 1234 , 'locationGroupId' : None , 'categories' : [{'categoryCode' : 'gpu1' }]}
318+ price2 = {'id' : 5678 , 'locationGroupId' : None , 'categories' : [{'categoryCode' : 'gpu0' }]}
319+ item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'itemCategory' : {'categoryCode' : 'gpu0' }, 'prices' : [price1 , price2 ]}
320+
321+ with mock .patch .object (self .ordering , 'list_items' ) as list_mock :
322+ list_mock .return_value = [item1 , item1 ]
323+
324+ prices = self .ordering .get_price_id_list ('PACKAGE_KEYNAME' , ['ITEM1' , 'ITEM1' ])
325+
326+ list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, itemCategory, keyName, prices[categories]' )
327+ self .assertEqual ([price2 ['id' ], price1 ['id' ]], prices )
328+
312329 def test_generate_no_complex_type (self ):
313330 pkg = 'PACKAGE_KEYNAME'
314331 items = ['ITEM1' , 'ITEM2' ]
@@ -460,30 +477,34 @@ def test_get_location_id_int(self):
460477
461478 def test_location_group_id_none (self ):
462479 # RestTransport uses None for empty locationGroupId
463- price1 = {'id' : 1234 , 'locationGroupId' : None }
464- item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'prices' : [price1 ]}
465- price2 = {'id' : 5678 , 'locationGroupId' : None }
466- item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'prices' : [price2 ]}
480+ category1 = {'categoryCode' : 'cat1' }
481+ price1 = {'id' : 1234 , 'locationGroupId' : None , 'categories' : [category1 ]}
482+ item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'itemCategory' : category1 , 'prices' : [price1 ]}
483+ category2 = {'categoryCode' : 'cat2' }
484+ price2 = {'id' : 5678 , 'locationGroupId' : None , 'categories' : [category2 ]}
485+ item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'itemCategory' : category2 , 'prices' : [price2 ]}
467486
468487 with mock .patch .object (self .ordering , 'list_items' ) as list_mock :
469488 list_mock .return_value = [item1 , item2 ]
470489
471490 prices = self .ordering .get_price_id_list ('PACKAGE_KEYNAME' , ['ITEM1' , 'ITEM2' ])
472491
473- list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, keyName, prices' )
492+ list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, itemCategory, keyName, prices[categories] ' )
474493 self .assertEqual ([price1 ['id' ], price2 ['id' ]], prices )
475494
476495 def test_location_groud_id_empty (self ):
477496 # XMLRPCtransport uses '' for empty locationGroupId
478- price1 = {'id' : 1234 , 'locationGroupId' : '' }
479- item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'prices' : [price1 ]}
480- price2 = {'id' : 5678 , 'locationGroupId' : "" }
481- item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'prices' : [price2 ]}
497+ category1 = {'categoryCode' : 'cat1' }
498+ price1 = {'id' : 1234 , 'locationGroupId' : '' , 'categories' : [category1 ]}
499+ item1 = {'id' : 1111 , 'keyName' : 'ITEM1' , 'itemCategory' : category1 , 'prices' : [price1 ]}
500+ category2 = {'categoryCode' : 'cat2' }
501+ price2 = {'id' : 5678 , 'locationGroupId' : "" , 'categories' : [category2 ]}
502+ item2 = {'id' : 2222 , 'keyName' : 'ITEM2' , 'itemCategory' : category2 , 'prices' : [price2 ]}
482503
483504 with mock .patch .object (self .ordering , 'list_items' ) as list_mock :
484505 list_mock .return_value = [item1 , item2 ]
485506
486507 prices = self .ordering .get_price_id_list ('PACKAGE_KEYNAME' , ['ITEM1' , 'ITEM2' ])
487508
488- list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, keyName, prices' )
509+ list_mock .assert_called_once_with ('PACKAGE_KEYNAME' , mask = 'id, itemCategory, keyName, prices[categories] ' )
489510 self .assertEqual ([price1 ['id' ], price2 ['id' ]], prices )
0 commit comments