Permalink
Browse files

Merge pull request #10 from wmatyskiewicz/api

tests, parts, and fixed models
  • Loading branch information...
2 parents 90601f3 + ae57044 commit b7760d9919e26d3aa825aa579f0e26cbe783e67d @deshipu deshipu committed May 16, 2013
Showing with 51 additions and 6 deletions.
  1. +13 −2 src/ralph_assets/api_pricing.py
  2. +1 −1 src/ralph_assets/models_assets.py
  3. +37 −3 src/ralph_assets/tests/unit/tests_models.py
@@ -9,11 +9,22 @@
def get_assets():
"""Yields dicts describing all assets"""
- for asset in Asset.objects_dc.all():
+ for asset in Asset.objects_dc.filter(part_info_id=None):
+ device_info = asset.device_info
yield {
'asset_id': asset.id,
- 'ralph_id': asset.device_info.ralph_device_id,
+ 'ralph_id': device_info.ralph_device_id if device_info else None,
'slots': asset.slots,
'price': asset.price,
'is_deprecated': asset.is_deprecated()
}
+
+def get_asset_parts():
+ for asset in Asset.objects_dc.all():
+ for part in asset.get_parts():
+ yield {
+ 'asset': asset,
+ 'model': part.model,
+ 'price': part.price,
+ 'is_deprecated': part.is_deprecated(),
+ }
@@ -333,7 +333,7 @@ class DeviceInfo(TimeTrackable, SavingUser, SoftDeletable):
def __unicode__(self):
return "{} - {}".format(
- self.ralph_device,
+ self.ralph_device_id,
self.size,
)
@@ -12,9 +12,9 @@
from ralph.business.models import Venture
from ralph.discovery.models import Device, DeviceType
from ralph.ui.tests.util import create_device
-from ralph_assets.models_assets import Asset, DeviceInfo
+from ralph_assets.models_assets import Asset, DeviceInfo, PartInfo, AssetModel
from ralph_assets.tests.util import create_asset
-from ralph_assets.api_pricing import get_assets
+from ralph_assets.api_pricing import get_assets, get_asset_parts
class TestModelAsset(TestCase):
@@ -53,6 +53,7 @@ def setUp(self):
size=6,
)
self.device_info.save()
+
self.asset = create_asset(
sn='1111-1111-1111-1111',
invoice_date='2012-11-28',
@@ -61,11 +62,44 @@ def setUp(self):
price=100,
device_info=self.device_info,
)
+ self.device2 = create_device(
+ device={
+ 'sn': 'srv-2',
+ 'model_name': 'server',
+ 'model_type': DeviceType.virtual_server,
+ 'venture': venture,
+ 'name': 'Srv 2',
+ 'purchase_date': '2012-11-28',
+ },
+ )
+ self.device_info2 = DeviceInfo(
+ ralph_device_id=self.device2.id,
+ size=6,
+ )
+ self.device_info.save()
+ self.part_info = PartInfo(device=self.asset)
+ self.part_info.save()
+ self.asset2 = create_asset(
+ sn='1111-1111-1111-11132',
+ invoice_date='2012-11-28',
+ support_period=1,
+ slots=12.0,
+ price=100,
+ device_info=self.device_info2,
+ part_info=self.part_info,
+ )
- def tests_api(self):
+ def tests_api_asset(self):
for item in get_assets():
self.assertEqual(item['asset_id'], self.asset.id)
self.assertEqual(item['ralph_id'], self.device_info.ralph_device_id)
self.assertEqual(item['slots'], self.asset.slots)
self.assertEqual(item['price'], self.asset.price)
self.assertEqual(item['is_deprecated'], self.asset.is_deprecated())
+
+ def tests_api_asset_part(self):
+ for item in get_asset_parts():
+ self.assertEqual(item['price'], 100)
+ self.assertEqual(item['is_deprecated'], True)
+ self.assertEqual(item['model'], AssetModel.objects.get(name="Model1"))
+ self.assertEqual(item['asset'], self.asset)

0 comments on commit b7760d9

Please sign in to comment.