def test_get_models(self): model1 = AssetModelFactory(type=models.AssetType.data_center) model2 = AssetModelFactory( type=models.AssetType.data_center, manufacturer=None, ) model3 = AssetModelFactory(type=models.AssetType.data_center, category=None) AssetModelFactory(type=models.AssetType.back_office) result = [m for m in api_scrooge.get_models()] self.assertEquals(result, [ { 'model_id': model1.id, 'name': model1.name, 'manufacturer': model1.manufacturer.name, 'category': model1.category.name, }, { 'model_id': model2.id, 'name': model2.name, 'manufacturer': None, 'category': model2.category.name, }, { 'model_id': model3.id, 'name': model3.name, 'manufacturer': model3.manufacturer.name, 'category': None, }, ])
def setUp(self): self.client = login_as_su() self.category = AssetCategoryFactory() self.asset = AssetFactory() self.asset1 = AssetFactory() self.model = AssetModelFactory(category=self.category) self.model1 = AssetModelFactory(category=self.category) self.user = UserFactory() self.warehouse = WarehouseFactory() self.assetOwner = AssetOwnerFactory() self.asset_service = ServiceFactory() self.common_asset_data = { # DC & BO common data 'barcode': 'barcode', 'deprecation_rate': '25', 'invoice_date': '2011-11-14', 'invoice_no': 'invoice_no', 'model': self.model, 'order_no': 'order_no', 'owner': self.user, 'price': '100', 'property_of': self.assetOwner, 'service_name': self.asset_service, 'source': models_assets.AssetSource.shipment, 'status': models_assets.AssetStatus.in_progress, 'task_url': 'www.test.com', 'user': self.user, 'warehouse': self.warehouse, }
def setUp(self): self.client = login_as_su(is_superuser=True) self.category_blade = AssetCategory.objects.get(name='Server Blade') self.category_non_blade = AssetCategory.objects.get(name='Server Rack') self.model_blade = AssetModelFactory(category=self.category_blade) self.model_none_blade = AssetModelFactory( category=self.category_non_blade, ) self.warehouse = WarehouseFactory() self.ci_relation = CIRelationFactory()
def test_get_asset_with_empty_asset_source(self): """Getting an asset with empty 'source' field should also succeed.""" category = AssetCategoryFactory() model = AssetModelFactory(category=category) asset = DCAssetFactory(model=model, source=None) asset_data = get_asset(asset.device_info.ralph_device_id) self.assertEqual(asset_data['source'], None)
def setUp(self): self.client = login_as_su() self.category = AssetCategoryFactory() self.model = AssetModelFactory(category=self.category) self.warehouse = WarehouseFactory() self.first_asset = AssetFactory(model=self.model, ) self.second_asset = AssetFactory(model=self.model, ) self.asset_with_duplicated_sn = AssetFactory(model=self.model, ) # Prepare required fields (formset_name, field_name) self.required_fields = [ ('asset_form', 'model'), ('asset_form', 'warehouse'), ] self.model1 = AssetModelFactory()
def test_generate_next_hostname_out_of_range(self): category = AssetCategoryFactory(code='PC') model = AssetModelFactory(category=category) asset = BOAssetFactory(model=model, owner=self.user_pl, hostname='') models_assets.AssetLastHostname.objects.create(prefix='POLPC', counter=99999) template_vars = { 'code': asset.model.category.code, 'country_code': asset.country_code, } asset.generate_hostname(template_vars=template_vars) self.assertEqual(asset.hostname, 'POLPC100000')
def test_generate_next_hostname(self): category = AssetCategoryFactory(code='PC') model = AssetModelFactory(category=category) asset = BOAssetFactory(model=model, owner=self.user_pl, hostname='') BOAssetFactory(owner=self.user_pl, hostname='POLSW00003') models_assets.AssetLastHostname.increment_hostname(prefix='POLPC') models_assets.AssetLastHostname.increment_hostname(prefix='POLPC') template_vars = { 'code': asset.model.category.code, 'country_code': asset.country_code, } asset.generate_hostname(template_vars=template_vars) self.assertEqual(asset.hostname, 'POLPC00003')
def test_generate_first_hostname(self): """Scenario: - none of assets has hostname - after generate first of asset have XXXYY00001 in hostname field """ category = AssetCategoryFactory(code='PC') model = AssetModelFactory(category=category) asset = BOAssetFactory(model=model, owner=self.user_pl, hostname='') template_vars = { 'code': asset.model.category.code, 'country_code': asset.country_code, } asset.generate_hostname(template_vars=template_vars) self.assertEqual(asset.hostname, 'POLPC00001')
def test_get_asset_by_sn_or_barcode(self): category = AssetCategoryFactory() model = AssetModelFactory(category=category) asset = DCAssetFactory(model=model, ) # by sn asset_data = get_asset_by_sn_or_barcode(asset.sn) self.assertEqual(asset_data['sn'], asset.sn) self.assertEqual(asset_data['barcode'], asset.barcode) # by barcode asset_data = get_asset_by_sn_or_barcode(asset.barcode) self.assertEqual(asset_data['sn'], asset.sn) self.assertEqual(asset_data['barcode'], asset.barcode) # not exists self.assertEqual(get_asset_by_sn_or_barcode('foo_ziew_123'), None)
def _create_models(self): self.keyboard_model = AssetModelFactory( category=AssetCategory.objects.get(name="Keyboard")) self.mouse_model = AssetModelFactory( category=AssetCategory.objects.get(name="Mouse")) self.pendrive_model = AssetModelFactory( category=AssetCategory.objects.get(name="Pendrive")) self.model_monitor = AssetModelFactory( category=AssetCategory.objects.get(name="Monitor")) self.navigation_model = AssetModelFactory( category=AssetCategory.objects.get(name="Navigation")) self.scanner_model = AssetModelFactory( category=AssetCategory.objects.get(name="Scanner")) self.shredder_model = AssetModelFactory( category=AssetCategory.objects.get(name="Shredder"))
def generate_data(self, data): return { 'rack_server': AssetModelFactory( name=SAMPLES['models']['rack-server'][0], manufacturer=data['assets_manufacturers']['hp'], category=data['assets_categories']['rack_server'], power_consumption=500, ), 'blade_chassis': AssetModelFactory( name=SAMPLES['models']['blade-chassis'][0], manufacturer=data['assets_manufacturers']['hp'], category=data['assets_categories']['blade_chassis'], height_of_device=10, visualization_layout_front=ModelVisualizationLayout.layout_2x8, power_consumption=10, ), 'blade_chassis_ab': AssetModelFactory( name=SAMPLES['models']['blade-chassis'][0], manufacturer=data['assets_manufacturers']['hp'], category=data['assets_categories']['blade_chassis'], height_of_device=10, visualization_layout_front=ModelVisualizationLayout. layout_2x8AB, # noqa power_consumption=150, ), 'blade_server': AssetModelFactory( name=SAMPLES['models']['blade-servers'][0], manufacturer=data['assets_manufacturers']['hp'], category=data['assets_categories']['blade_server'], power_consumption=380, ), 'pdu_model': AssetModelFactory( name=SAMPLES['models']['pdu'][0], manufacturer=data['assets_manufacturers']['hp'], category=data['assets_categories']['pdu'], ), 'load_balancer': AssetModelFactory( name=SAMPLES['models']['load_balancer'][0], manufacturer=data['assets_manufacturers']['f5'], category=data['assets_categories']['load_balancer'], ) }
def test_get_asset(self): """Test get asset information by ralph_device_id.""" support1 = DCSupportFactory() support2 = DCSupportFactory() category = AssetCategoryFactory() model = AssetModelFactory(category=category) asset = DCAssetFactory( model=model, supports=[support1, support2], ) asset_data = get_asset(asset.device_info.ralph_device_id) self.assertEqual(asset_data['sn'], asset.sn) self.assertEqual(asset_data['barcode'], asset.barcode) self.assertEqual(asset_data['supports'][0]['name'], support1.name) self.assertEqual(asset_data['supports'][0]['url'], support1.url) self.assertEqual(asset_data['supports'][1]['name'], support2.name) self.assertEqual(asset_data['supports'][1]['url'], support2.url) self.assertEqual( asset_data['required_support'], asset.required_support, )
def setUp(self): self.category = AssetSubCategoryFactory(is_blade=True) self.model = AssetModelFactory(category=self.category) self.asset = AssetFactory( invoice_date=datetime.date(2012, 11, 28), support_period=1, slots=12.0, price=100, deprecation_rate=100, model=self.model, ) part_info = PartInfo(device=self.asset) part_info.save() self.asset2 = AssetFactory( invoice_date=datetime.date(2012, 11, 28), support_period=1, slots=12.0, price=100, part_info=part_info, deprecation_rate=50, model=self.model, ) self.stock_venture = Venture.objects.get(name='Stock')
def setUp(self): self.client = login_as_su() self.warehouse = WarehouseFactory() self.category = AssetCategoryFactory() self.model = AssetModelFactory(category=self.category) self.addform = '/assets/dc/add/device/' ci_relation = CIRelationFactory() self.common_test_data = dict( asset=True, deprecation_rate=0, device_environment=ci_relation.child.id, invoice_date='2001-01-02', model=self.model.id, price='10', production_year=2011, ralph_device_id='', service=ci_relation.parent.id, size=1, slots=1, source=1, status=AssetStatus.new.id, type=AssetType.data_center.id, warehouse=self.warehouse.id, )
def test_cant_generate_hostname_for_model_without_user_and_category(self): model = AssetModelFactory(category=None) asset = BOAssetFactory(model=model, owner=None, hostname='') self._check_hostname_not_generated(asset)
def test_can_generate_hostname_for_model_with_hostname(self): category = AssetCategoryFactory(code='PC') model = AssetModelFactory(category=category) asset = BOAssetFactory(model=model, owner=self.user_pl) self._check_hostname_is_generated(asset)