Browse files

Merge pull request #16 from wmatyskiewicz/parts

added sync sn and barcode to pricing
  • Loading branch information...
2 parents 31a7750 + 88cb687 commit d32372ff0e6d9642d4bf6f2082df6d7985f1f27d @deshipu deshipu committed May 22, 2013
Showing with 66 additions and 50 deletions.
  1. +8 −1 src/ralph_assets/api_pricing.py
  2. +58 −49 src/ralph_assets/tests/unit/tests_models.py
View
9 src/ralph_assets/api_pricing.py
@@ -13,8 +13,12 @@ def get_assets():
device_info = asset.device_info
yield {
'asset_id': asset.id,
+ 'barcode': asset.barcode,
+ 'is_deprecated': asset.is_deprecated(),
+ 'price': asset.price,
'ralph_id': device_info.ralph_device_id if device_info else None,
'slots': asset.slots,
+ 'sn': asset.sn,
'price': asset.price,
'deprecation_rate': asset.deprecation_rate,
'is_deprecated': asset.is_deprecated()
@@ -26,9 +30,12 @@ def get_asset_parts():
device_info = asset.device_info
yield {
'asset_id': asset.id,
- 'ralph_id': device_info.ralph_device_id if device_info else None,
+ 'barcode': asset.barcode,
+ 'is_deprecated': part.is_deprecated(),
'model': part.model.name if part.model else None,
'price': part.price,
+ 'ralph_id': device_info.ralph_device_id if device_info else None,
+ 'sn': asset.sn,
'deprecation_rate': asset.deprecation_rate,
'is_deprecated': part.is_deprecated(),
}
View
107 src/ralph_assets/tests/unit/tests_models.py
@@ -36,50 +36,54 @@ def test_is_deperecation(self):
class TestApiAssets(TestCase):
- def setUp(self):
- venture = Venture(name='Infra').save()
- self.device = create_device(
- device={
- 'sn': 'srv-1',
- 'model_name': 'server',
- 'model_type': DeviceType.virtual_server,
- 'venture': venture,
- 'name': 'Srv 1',
- 'purchase_date': '2012-11-28',
- },
- )
- self.device_info = DeviceInfo(
- ralph_device_id=self.device.id,
- size=6,
- )
- self.device_info.save()
+ def setUp(self):
+ venture = Venture(name='Infra').save()
+ self.device = create_device(
+ device={
+ 'sn': 'srv-1',
+ 'model_name': 'server',
+ 'model_type': DeviceType.virtual_server,
+ 'venture': venture,
+ 'name': 'Srv 1',
+ 'purchase_date': '2012-11-28',
+ 'sn': 'aaaa-aaaa-aaaa-aaaa',
+ 'barcode': 'bbbb-bbbb-bbbb-bbbb',
+ },
+ )
+ self.device_info = DeviceInfo(
+ ralph_device_id=self.device.id,
+ size=6,
+ )
+ self.device_info.save()
- self.asset = create_asset(
+ self.asset = create_asset(
sn='1111-1111-1111-1111',
invoice_date='2012-11-28',
support_period=1,
slots=12.0,
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(
+ 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',
+ 'sn': 'cccc-cccc-cccc-cccc',
+ 'barcode': 'dddd-dddd-dddd-dddd',
+ },
+ )
+ 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,
@@ -89,17 +93,22 @@ def setUp(self):
part_info=self.part_info,
)
- 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(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())
+ self.assertEqual(item['sn'], self.asset.sn)
+ self.assertEqual(item['barcode'], self.asset.barcode)
- 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)
+ def tests_api_asset_part(self):
+ for item in get_asset_parts():
+ self.assertEqual(item['price'], 100)
+ self.assertEqual(item['is_deprecated'], True)
+ model = AssetModel.objects.get(name="Model1")
+ self.assertEqual(item['model'], model.name)
+ self.assertEqual(item['asset_id'], self.asset.id)
+ self.assertEqual(item['sn'], self.asset.sn)
+ self.assertEqual(item['barcode'], self.asset.barcode)

0 comments on commit d32372f

Please sign in to comment.