Skip to content

Commit 65af93f

Browse files
author
Fernando Ojeda
committed
fixed vs create flavor test
1 parent 37ec7ab commit 65af93f

File tree

4 files changed

+208
-2
lines changed

4 files changed

+208
-2
lines changed

SoftLayer/CLI/virt/create.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,11 +273,13 @@ def cli(env, **args):
273273

274274
if result['presetId']:
275275
ordering_mgr = SoftLayer.OrderingManager(env.client)
276+
item_prices = ordering_mgr.get_item_prices(result['packageId'])
276277
preset_prices = ordering_mgr.get_preset_prices(result['presetId'])
277278
search_keys = ["guest_core", "ram"]
278279
for price in preset_prices['prices']:
279280
if price['item']['itemCategory']['categoryCode'] in search_keys:
280-
result['prices'].append(price)
281+
item_key_name = price['item']['keyName']
282+
_add_item_prices(item_key_name, item_prices, result)
281283

282284
table = _build_receipt_table(result['prices'], args.get('billing'))
283285

@@ -318,6 +320,16 @@ def cli(env, **args):
318320
env.fout(output)
319321

320322

323+
def _add_item_prices(item_key_name, item_prices, result):
324+
"""Add the flavor item prices to the rest o the items prices"""
325+
for item in item_prices:
326+
if item_key_name == item['item']['keyName']:
327+
if 'pricingLocationGroup' in item:
328+
for location in item['pricingLocationGroup']['locations']:
329+
if result['location'] == str(location['id']):
330+
result['prices'].append(item)
331+
332+
321333
def _build_receipt_table(prices, billing="hourly"):
322334
"""Retrieve the total recurring fee of the items prices"""
323335
total = 0.000

SoftLayer/fixtures/SoftLayer_Product_Package.py

Lines changed: 175 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@
916916
'prices': [{'id': 611}],
917917
}]
918918

919-
getItemPrices = [
919+
getItemPricesISCSI = [
920920
{
921921
'currentPriceFlag': '',
922922
'id': 2152,
@@ -1340,3 +1340,177 @@
13401340
}]
13411341
}]
13421342
}]
1343+
1344+
getItemPrices = [
1345+
{
1346+
"hourlyRecurringFee": ".093",
1347+
"id": 204015,
1348+
"recurringFee": "62",
1349+
"item": {
1350+
"description": "4 x 2.0 GHz or higher Cores",
1351+
"id": 859,
1352+
"keyName": "GUEST_CORES_4",
1353+
},
1354+
"pricingLocationGroup": {
1355+
"id": 503,
1356+
"locations": [
1357+
{
1358+
"id": 449610,
1359+
"longName": "Montreal 1",
1360+
"name": "mon01",
1361+
"statusId": 2
1362+
},
1363+
{
1364+
"id": 449618,
1365+
"longName": "Montreal 2",
1366+
"name": "mon02",
1367+
"statusId": 2
1368+
},
1369+
{
1370+
"id": 448994,
1371+
"longName": "Toronto 1",
1372+
"name": "tor01",
1373+
"statusId": 2
1374+
},
1375+
{
1376+
"id": 350993,
1377+
"longName": "Toronto 2",
1378+
"name": "tor02",
1379+
"statusId": 2
1380+
},
1381+
{
1382+
"id": 221894,
1383+
"longName": "Amsterdam 2",
1384+
"name": "ams02",
1385+
"statusId": 2
1386+
},
1387+
{
1388+
"id": 265592,
1389+
"longName": "Amsterdam 1",
1390+
"name": "ams01",
1391+
"statusId": 2
1392+
},
1393+
{
1394+
"id": 814994,
1395+
"longName": "Amsterdam 3",
1396+
"name": "ams03",
1397+
"statusId": 2
1398+
}
1399+
]
1400+
}
1401+
},
1402+
{
1403+
"hourlyRecurringFee": ".006",
1404+
"id": 204663,
1405+
"recurringFee": "4.1",
1406+
"item": {
1407+
"description": "100 GB (LOCAL)",
1408+
"id": 3899,
1409+
"keyName": "GUEST_DISK_100_GB_LOCAL_3",
1410+
},
1411+
"pricingLocationGroup": {
1412+
"id": 503,
1413+
"locations": [
1414+
{
1415+
"id": 449610,
1416+
"longName": "Montreal 1",
1417+
"name": "mon01",
1418+
"statusId": 2
1419+
},
1420+
{
1421+
"id": 449618,
1422+
"longName": "Montreal 2",
1423+
"name": "mon02",
1424+
"statusId": 2
1425+
},
1426+
{
1427+
"id": 448994,
1428+
"longName": "Toronto 1",
1429+
"name": "tor01",
1430+
"statusId": 2
1431+
},
1432+
{
1433+
"id": 350993,
1434+
"longName": "Toronto 2",
1435+
"name": "tor02",
1436+
"statusId": 2
1437+
},
1438+
{
1439+
"id": 221894,
1440+
"longName": "Amsterdam 2",
1441+
"name": "ams02",
1442+
"statusId": 2
1443+
},
1444+
{
1445+
"id": 265592,
1446+
"longName": "Amsterdam 1",
1447+
"name": "ams01",
1448+
"statusId": 2
1449+
},
1450+
{
1451+
"id": 814994,
1452+
"longName": "Amsterdam 3",
1453+
"name": "ams03",
1454+
"statusId": 2
1455+
}
1456+
]
1457+
}
1458+
},
1459+
{
1460+
"hourlyRecurringFee": ".217",
1461+
"id": 204255,
1462+
"recurringFee": "144",
1463+
"item": {
1464+
"description": "16 GB ",
1465+
"id": 1017,
1466+
"keyName": "RAM_16_GB",
1467+
},
1468+
"pricingLocationGroup": {
1469+
"id": 503,
1470+
"locations": [
1471+
{
1472+
"id": 449610,
1473+
"longName": "Montreal 1",
1474+
"name": "mon01",
1475+
"statusId": 2
1476+
},
1477+
{
1478+
"id": 449618,
1479+
"longName": "Montreal 2",
1480+
"name": "mon02",
1481+
"statusId": 2
1482+
},
1483+
{
1484+
"id": 448994,
1485+
"longName": "Toronto 1",
1486+
"name": "tor01",
1487+
"statusId": 2
1488+
},
1489+
{
1490+
"id": 350993,
1491+
"longName": "Toronto 2",
1492+
"name": "tor02",
1493+
"statusId": 2
1494+
},
1495+
{
1496+
"id": 221894,
1497+
"longName": "Amsterdam 2",
1498+
"name": "ams02",
1499+
"statusId": 2
1500+
},
1501+
{
1502+
"id": 265592,
1503+
"longName": "Amsterdam 1",
1504+
"name": "ams01",
1505+
"statusId": 2
1506+
},
1507+
{
1508+
"id": 814994,
1509+
"longName": "Amsterdam 3",
1510+
"name": "ams03",
1511+
"statusId": 2
1512+
}
1513+
]
1514+
}
1515+
}
1516+
]

SoftLayer/managers/ordering.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,20 @@ def get_preset_prices(self, preset):
384384
prices = self.package_preset.getObject(id=preset, mask=mask)
385385
return prices
386386

387+
def get_item_prices(self, package_id):
388+
"""Get item prices.
389+
390+
Retrieve a SoftLayer_Product_Package item prices record.
391+
392+
:param int package_id: package identifier.
393+
:returns: A list of price IDs associated with the given package.
394+
395+
"""
396+
mask = 'mask[pricingLocationGroup[locations]]'
397+
398+
prices = self.package_svc.getItemPrices(id=package_id, mask=mask)
399+
return prices
400+
387401
def verify_order(self, package_keyname, location, item_keynames, complex_type=None,
388402
hourly=True, preset_keyname=None, extras=None, quantity=1):
389403
"""Verifies an order with the given package and prices.

tests/managers/ordering_tests.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ def test_get_preset_prices(self):
7474
self.assertEqual(result, fixtures.SoftLayer_Product_Package_Preset.getObject)
7575
self.assert_called_with('SoftLayer_Product_Package_Preset', 'getObject')
7676

77+
def test_get_item_prices(self):
78+
result = self.ordering.get_item_prices(835)
79+
80+
self.assertEqual(result, fixtures.SoftLayer_Product_Package.getItemPrices)
81+
self.assert_called_with('SoftLayer_Product_Package', 'getItemPrices')
82+
7783
def test_get_package_id_by_type_fails_for_nonexistent_package_type(self):
7884
p_mock = self.set_mock('SoftLayer_Product_Package', 'getAllObjects')
7985
p_mock.return_value = []

0 commit comments

Comments
 (0)