Permalink
Browse files

Merge pull request #6 from wmatyskiewicz/api

test api, fixed model type
  • Loading branch information...
2 parents ecd3cf1 + 6f6d84a commit 8a422d6adbc5b4e00914f793ea70d99c650798d2 @deshipu deshipu committed May 9, 2013
@@ -13,7 +13,7 @@ def get_assets():
yield {
'name': asset.sn,
'asset_id': asset.id,
- 'ralph_id': device_info.ralph_device.id,
+ 'ralph_id': asset.device_info.ralph_device.id,
'slots': asset.slots,
'price': asset.price,
'is_deprecated': asset.is_deprecated()
@@ -10,7 +10,7 @@ class Migration(SchemaMigration):
def forwards(self, orm):
# Adding field 'Asset.slots'
db.add_column('ralph_assets_asset', 'slots',
- self.gf('django.db.models.fields.FloatField')(default=0, max_length=64),
+ self.gf('django.db.models.fields.CharField')(default='', max_length=50, blank=True),
keep_default=False)
@@ -372,7 +372,7 @@ def backwards(self, orm):
'provider_order_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
'remarks': ('django.db.models.fields.CharField', [], {'max_length': '1024', 'blank': 'True'}),
'request_date': ('django.db.models.fields.DateField', [], {'null': 'True', 'blank': 'True'}),
- 'slots': ('django.db.models.fields.FloatField', [], {'default': '0', 'max_length': '64'}),
+ 'slots': ('django.db.models.fields.CharField', [], {'max_length': '50', 'blank': 'True'}),
'sn': ('django.db.models.fields.CharField', [], {'max_length': '200', 'unique': 'True', 'null': 'True', 'blank': 'True'}),
'source': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),
'status': ('django.db.models.fields.PositiveSmallIntegerField', [], {'default': '1'}),
@@ -502,4 +502,4 @@ def backwards(self, orm):
}
}
- complete_apps = ['ralph_assets']
+ complete_apps = ['ralph_assets']
@@ -10,7 +10,7 @@
import os
-from datetime import datetime
+import datetime
from dateutil.relativedelta import relativedelta
from django.db import models
from django.utils.translation import ugettext_lazy as _
@@ -276,12 +276,15 @@ def is_deprecated(self):
if not self.support_period or not self.invoice_date:
return False
if isinstance(self.invoice_date, basestring):
- self.invoice_date = datetime.strptime(self.invoice_date,'%Y-%m-%d')
+ self.invoice_date = datetime.datetime.strptime(
+ self.invoice_date, '%Y-%m-%d'
+ )
deprecation_date = self.invoice_date + relativedelta(
months=self.support_period
)
- return deprecation_date < datetime.today()
-
+ if isinstance(deprecation_date, datetime.datetime):
+ deprecation_date = deprecation_date.date()
+ return deprecation_date < datetime.date.today()
class DeviceInfo(TimeTrackable, SavingUser, SoftDeletable):
ralph_device = models.ForeignKey(
@@ -5,16 +5,16 @@
from __future__ import print_function
from __future__ import unicode_literals
+import datetime
+
from django.test import TestCase
-from ralph_assets.models_assets import Asset
-from ralph_assets.tests.util import (
- create_asset,
- create_category,
- create_model,
- create_warehouse,
- create_manufacturer,
-)
+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.tests.util import create_asset
+from ralph_assets.api_pricing import get_assets
class TestModelAsset(TestCase):
@@ -30,9 +30,43 @@ def setUp(self):
support_period=120,
)
-
def test_is_deperecation(self):
self.assertEqual(self.asset.is_deprecated(), True)
self.assertEqual(self.asset2.is_deprecated(), False)
+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=self.device,
+ size=6,
+ )
+ self.device_info.save()
+ 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,
+ )
+
+ def tests_api(self):
+ for item in get_assets():
+ self.assertEqual(item['name'], self.asset.sn)
+ 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())
@@ -73,7 +73,7 @@ def create_asset(sn, **kwargs):
kwargs.update(type=DEFAULT_ASSET_DATA['type'])
if not kwargs.get('model'):
kwargs.update(model=create_model())
- if not kwargs.get('device'):
+ if not kwargs.get('device_info'):
kwargs.update(device_info=create_device())
if not kwargs.get('status'):
kwargs.update(status=DEFAULT_ASSET_DATA['status'])

0 comments on commit 8a422d6

Please sign in to comment.