Ejemplo n.º 1
0
 def test_assigning_when_no_hostname(self):
     """
     Generate hostname when it's none.
     """
     no_hostname_asset = BOAssetFactory(**{'hostname': None})
     self.assertEqual(no_hostname_asset.hostname, None)
     no_hostname_asset._try_assign_hostname(True)
     self.assertNotEqual(no_hostname_asset.hostname, None)
Ejemplo n.º 2
0
 def test_assigning_when_different_country(self):
     """
     Generate hostname when user has diffrent country than country from
     hostname.
     """
     asset = BOAssetFactory(**{'owner': self.owner})
     old_hostname = asset.hostname
     self.assertNotIn(self.owner_country_name, asset.hostname)
     asset._try_assign_hostname(True)
     self.assertNotEqual(asset.hostname, old_hostname)
     self.assertIn(self.owner_country_name, asset.hostname)
Ejemplo n.º 3
0
 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')
Ejemplo n.º 4
0
 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')
Ejemplo n.º 5
0
 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')
Ejemplo n.º 6
0
 def _asset_from_country(iso3_country):
     asset = BOAssetFactory()
     hostname = asset.hostname.replace('XXX', iso3_country)
     asset.hostname = hostname
     asset.save()
     return asset
Ejemplo n.º 7
0
 def test_cant_generate_hostname_for_model_without_user(self):
     model = AssetModelFactory()
     asset = BOAssetFactory(model=model, owner=None, hostname='')
     self._check_hostname_not_generated(asset)
Ejemplo n.º 8
0
 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)
Ejemplo n.º 9
0
 def _create_assets(self, custom_values={}):
     [BOAssetFactory(**custom_values) for _ in xrange(4)]
Ejemplo n.º 10
0
 def _prepare_assets(self, custom_values={}):
     self.assets = [BOAssetFactory(**custom_values) for _ in xrange(2)]