def setUp(self): self.client = Client() # users self.accountant = User.objects.create_user(username='******', password='******') self.accountant.profile.boundperm_set.create( perm=Perm.has_scrooge_access) self.owner = User.objects.create_user(username='******', password='******') self.team_manager = User.objects.create_user(username='******', password='******') self.superuser = User.objects.create_user( username='******', password='******', ) self.superuser.is_superuser = True self.superuser.save() # create services (and assign one of them to owner) self.se1 = ServiceEnvironmentFactory() self.service1 = self.se1.service scrooge_owner = OwnerFactory(profile=self.owner.profile) ServiceOwnership.objects.create(service=self.service1, owner=scrooge_owner) self.se2 = ServiceEnvironmentFactory() self.service2 = self.se2.service # create teams self.team1 = TeamFactory() team_manager = OwnerFactory(profile=self.team_manager.profile) TeamManager.objects.create(team=self.team1, manager=team_manager) self.team2 = TeamFactory()
def _init(self): self.ps1, self.ps2, self.ps3 = PricingServiceFactory.create_batch(3) self.se1, self.se2 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps1, ) self.se3, self.se4 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps2, ) self.se5 = ServiceEnvironmentFactory(service__pricing_service=self.ps3) self.other_se = ServiceEnvironmentFactory.create_batch(5) self.service_usage_types = UsageTypeFactory.create_batch( 4, usage_type='SU', ) self.ps1.excluded_services.add(self.other_se[0].service) self.ps1.save() self.ps2.excluded_services.add(self.other_se[1].service) self.ps2.save() self.service_usage_types[0].excluded_services.add( self.other_se[2].service) self.service_usage_types[0].save() self.service_usage_types[3].excluded_services.add( self.other_se[4].service) self.service_usage_types[3].save() models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.ps1, start=self.start, end=self.end, percent=100, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.ps2, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[2], pricing_service=self.ps2, start=self.start, end=self.end, percent=30, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[3], pricing_service=self.ps3, start=self.start, end=self.end, percent=100, )
def setUp(self): self.components = ComponentsContent() self.se1 = ServiceEnvironmentFactory() self.se2 = ServiceEnvironmentFactory(service=self.se1.service, ) self.se3 = ServiceEnvironmentFactory() self.today = datetime.date(2014, 10, 11) self.tomorrow = datetime.date(2014, 10, 12) self.today_accepted = CostDateStatusFactory(date=self.today, accepted=True) self.ut1 = UsageTypeFactory() self.ut2 = PricingServiceFactory() self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch( 2, service_environment=self.se1, pricing_object__service_environment=self.se1, date=self.today, ) self.dpo3 = DailyAssetInfoFactory( service_environment=self.se2, pricing_object__service_environment=self.se2, date=self.today, ) self.dpo3 = DailyAssetInfoFactory( service_environment=self.se3, pricing_object__service_environment=self.se3, date=self.today, ) self.dpo4 = DailyAssetInfoFactory( service_environment=self.se1, pricing_object__service_environment=self.se1, date=self.tomorrow, ) self.dc1 = DailyCostFactory( type=self.ut1, pricing_object=self.dpo1.pricing_object, service_environment=self.se1, date=self.today, value=10, cost=20, ) self.dc2 = DailyCostFactory( type=self.ut1, pricing_object=self.dpo1.pricing_object, service_environment=self.se1, date=self.today, value=20, cost=30, ) self.dc3 = DailyCostFactory( type=self.ut2, pricing_object=self.dpo1.pricing_object, service_environment=self.se1, date=self.today, value=25, cost=35, ) self.maxDiff = None
def test_network(self): ServiceEnvironmentFactory.create(service__ci_uid=1, environment__name='env1') self.assertEqual( netflow.netflow(today=date(year=2014, month=1, day=1))[1], '1 new, 0 updated, 1 total', ) self.assertEqual(DailyUsage.objects.get().value, 30)
def _init_one(self): """ Creates pricing service with 2 service usages. Pricing service has se4 in excluded services, its usage type has se3 in excluded services. There are 3 daily pricing objects - one of them belongs to se1 (and should not be considered to calculate usages). """ self.ps1 = PricingServiceFactory() self.se1, self.se2 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps1, ) self.se3, self.se4 = ServiceEnvironmentFactory.create_batch(2) self.service_usage_types = UsageTypeFactory.create_batch( 2, usage_type='SU', ) self.service_usage_types[0].excluded_services.add(self.se3.service) self.service_usage_types[0].save() self.ps1.excluded_services.add(self.se4.service) self.ps1.save() models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.ps1, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.ps1, start=self.start, end=self.end, percent=30, ) self.dpo1 = DailyPricingObjectFactory() self.dpo2 = DailyPricingObjectFactory() self.dpo3 = DailyPricingObjectFactory( service_environment=self.se1 ) for dpo in models.DailyPricingObject.objects.all(): for su, value in zip(self.service_usage_types, [10, 20]): models.DailyUsage.objects.create( daily_pricing_object=dpo, service_environment=dpo.service_environment, date=self.today, value=value, type=su, )
def test_network(self): ServiceEnvironmentFactory.create( service__ci_uid=1, environment__name='env1' ) self.assertEqual( netflow.netflow(today=date(year=2014, month=1, day=1))[1], '1 new, 0 updated, 1 total', ) self.assertEqual(DailyUsage.objects.get().value, 30)
def setUp(self): self.service_environment = ServiceEnvironmentFactory() self.unknown_service_environment = ServiceEnvironmentFactory( service__name=UNKNOWN_SERVICE_ENVIRONMENT[0], environment__name=UNKNOWN_SERVICE_ENVIRONMENT[0], ) self.today = datetime.date(2014, 7, 1) self.model = PricingObjectModelFactory( type_id=PRICING_OBJECT_TYPES.TENANT, name=OPENSTACK_TENANTS_MODELS[0], )
def _init_one(self): """ Creates pricing service with 2 service usages. Pricing service has se4 in excluded services, its usage type has se3 in excluded services. There are 3 daily pricing objects - one of them belongs to se1 (and should not be considered to calculate usages). """ self.ps1 = PricingServiceFactory() self.se1, self.se2 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps1, ) self.se3, self.se4 = ServiceEnvironmentFactory.create_batch(2) self.service_usage_types = UsageTypeFactory.create_batch( 2, usage_type='SU', ) self.service_usage_types[0].excluded_services.add(self.se3.service) self.service_usage_types[0].save() self.ps1.excluded_services.add(self.se4.service) self.ps1.save() models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.ps1, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.ps1, start=self.start, end=self.end, percent=30, ) self.dpo1 = DailyPricingObjectFactory() self.dpo2 = DailyPricingObjectFactory() self.dpo3 = DailyPricingObjectFactory(service_environment=self.se1) for dpo in models.DailyPricingObject.objects.all(): for su, value in zip(self.service_usage_types, [10, 20]): models.DailyUsage.objects.create( daily_pricing_object=dpo, service_environment=dpo.service_environment, date=self.today, value=value, type=su, )
def setUp(self): self.service_environment = ServiceEnvironmentFactory() self.unknown_service_environment = ServiceEnvironmentFactory( service__name=UNKNOWN_SERVICE_ENVIRONMENT[0], environment__name=UNKNOWN_SERVICE_ENVIRONMENT[0], ) self.asset_info = AssetInfoFactory() self.today = datetime.date(2014, 7, 1) self.model = PricingObjectModelFactory( type_id=PRICING_OBJECT_TYPES.DATABASE, name=DATABASE_TYPES[0], )
def test_get_vip_unknown_service_environment(self): service_environment = ServiceEnvironmentFactory( service__ci_uid=UNKNOWN_SERVICE_ENVIRONMENT[0], environment__name=UNKNOWN_SERVICE_ENVIRONMENT[1], ) self.assertEquals(service_environment, get_unknown_service_environment(VIP_TYPES[0]))
def setUp(self): # self.service = ServiceFactory.create() # self.environment = EnvironmentFactory.create() self.service_environment = ServiceEnvironmentFactory() self.date = datetime.date.today() self.warehouse = WarehouseFactory.create() self.model = PricingObjectModelFactory() self.value = 100 self.data = { 'asset_id': 1, 'sn': 'SerialNumber', 'barcode': 'Barcode', 'device_id': 1, 'asset_name': 'AssetName', 'depreciation_rate': 25, 'is_depreciated': True, 'price': 100, 'service_id': self.service_environment.service.ci_id, 'warehouse_id': self.warehouse.id_from_assets, 'environment_id': self.service_environment.environment.ci_id, # noqa 'cores_count': 4, 'power_consumption': 200, 'collocation': 2, 'model_id': self.model.model_id, }
def test_update_virtual_virtual_info_with_hypervisor(self): service_env = ServiceEnvironmentFactory.create() hypervisor = DailyAssetInfoFactory(date=self.today) data = AttributeDict( device_id=1, name='sample', service_id=service_env.service.ci_id, environment_id=service_env.environment.ci_id, model_id=1, hypervisor_id=hypervisor.asset_info.device_id, model_name='sample model', ) daily_virtual_info = virtual.update_virtual_info( 'virtual_group', data, self.today, service_env, ) self._compare_daily_virtual_info( daily_virtual_info, data, service_env, 'virtual_group', ) self.assertEqual(hypervisor.asset_info.device_id, daily_virtual_info.hypervisor.asset_info.device_id)
def test_update_virtual_virtual_info_with_hypervisor(self): service_env = ServiceEnvironmentFactory.create() hypervisor = DailyAssetInfoFactory(date=self.today) data = AttributeDict( device_id=1, name='sample', service_id=service_env.service.ci_id, environment_id=service_env.environment.ci_id, model_id=1, hypervisor_id=hypervisor.asset_info.device_id, model_name='sample model', ) daily_virtual_info = virtual.update_virtual_info( 'virtual_group', data, self.today, service_env, ) self._compare_daily_virtual_info( daily_virtual_info, data, service_env, 'virtual_group', ) self.assertEqual( hypervisor.asset_info.device_id, daily_virtual_info.hypervisor.asset_info.device_id )
def test_get_tenant_unknown_service_environment(self): service_environment = ServiceEnvironmentFactory( service__ci_uid=UNKNOWN_SERVICE_ENVIRONMENT[0], environment__name=UNKNOWN_SERVICE_ENVIRONMENT[1], ) self.assertEquals( service_environment, get_unknown_service_environment(OPENSTACK_TENANTS_MODELS[0]))
def setUp(self): self.pc1 = ProfitCenterFactory() self.pc2 = ProfitCenterFactory() self.report_start = date.today() self.report_end = self.report_start + timedelta(days=1) self.service_environment1 = ServiceEnvironmentFactory( service__profit_center=self.pc1 ) self.service_environment2 = ServiceEnvironmentFactory( service__profit_center=self.pc2 ) self.service_environments = models.ServiceEnvironment.objects.all() self.service_environment1.service.profit_center = self.pc2 self.service_environment1.service.save() self.maxDiff = None
def test_virtual(self): service_environment = ServiceEnvironmentFactory.create() asset_info = AssetInfoFactory.create(device_id=1) DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today) virtual.ServiceEnvironment.objects.get = ( lambda *args, **kwargs: service_environment) self.assertEqual( virtual.virtual(today=self.today), (True, 'Virtual: None new, 1 updated, 1 total'), )
def test_save_database_info_invalid_service_environment(self): service_environment = ServiceEnvironmentFactory.build() sample_db = self._get_sample_database() sample_db['service_id'] = service_environment.service.ci_id sample_db['environment_id'] = service_environment.environment.ci_id created, database_info = save_database_info( sample_db, self.unknown_service_environment) self.assertTrue(created) self._compare_databases(sample_db, database_info) self.assertEquals(database_info.service_environment, self.unknown_service_environment)
def test_virtual(self): service_environment = ServiceEnvironmentFactory.create() asset_info = AssetInfoFactory.create(device_id=1) DailyAssetInfoFactory.create(asset_info=asset_info, date=self.today) virtual.ServiceEnvironment.objects.get = ( lambda *args, **kwargs: service_environment ) self.assertEqual( virtual.virtual(today=self.today), (True, 'Virtual: None new, 1 updated, 1 total'), )
def setUp(self): self.se1, self.se2 = ServiceEnvironmentFactory.create_batch(2) self.po1 = PricingObjectFactory(service_environment=self.se1) self.po2 = PricingObjectFactory(service_environment=self.se2) self.bu1 = ExtraCostTypeFactory() self.bu2 = UsageTypeFactory() self.bu3 = PricingServiceFactory() self.bu4 = PricingServiceFactory() self.wh1 = WarehouseFactory() self.wh2 = WarehouseFactory()
def setUp(self): self.today = date(2013, 10, 11) self.checkpoint = date(2013, 10, 15) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) self.service_environments = ServiceEnvironmentFactory.create_batch(2) self.collector = Collector() self.dates1 = self._dates_between(self.start, self.checkpoint) self.dates2 = self._dates_between(self.checkpoint + timedelta(days=1), self.end) self.dates = self._dates_between(self.start, self.end)
def setUp(self): super(TestPricingServiceUsagesApi, self).setUp() self.maxDiff = None self.resource = 'pricingserviceusages' self.user = User.objects.create_user('ralph', '*****@*****.**', 'ralph') self.date = datetime.date(2013, 10, 10) self.today = datetime.date.today() self.pricing_service = PricingServiceFactory() self.service_environment1 = ServiceEnvironmentFactory() self.service_environment2 = ServiceEnvironmentFactory() self.service_environment3 = ServiceEnvironmentFactory() self.pricing_object1 = PricingObjectFactory() self.pricing_object2 = PricingObjectFactory() self.usage_type1 = UsageTypeFactory() self.usage_type2 = UsageTypeFactory() ServiceUsageTypes.objects.create( usage_type=self.usage_type1, pricing_service=self.pricing_service, start=datetime.date.min, end=datetime.date.max, percent=50, ) ServiceUsageTypes.objects.create( usage_type=self.usage_type2, pricing_service=self.pricing_service, start=datetime.date.min, end=datetime.date.max, percent=50, ) self.api_key = self.create_apikey( self.user.username, self.user.api_key.key, )
def test_save_vip_info_invalid_service_environment(self): service_environment = ServiceEnvironmentFactory.build() sample_vip = self._get_sample_vip() sample_vip['service_id'] = service_environment.service.ci_id sample_vip['environment_id'] = service_environment.environment.ci_id created, vip_info = save_vip_info(sample_vip, self.unknown_service_environment) self.assertTrue(created) self._compare_vips(sample_vip, vip_info) self.assertEquals(vip_info.service_environment, self.unknown_service_environment) self.assertEquals(vip_info.ip_info.service_environment, self.unknown_service_environment)
def setUp(self): self.today = date(2013, 10, 11) self.checkpoint = date(2013, 10, 15) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) self.service_environments = ServiceEnvironmentFactory.create_batch(2) self.collector = Collector() self.dates1 = self._dates_between(self.start, self.checkpoint) self.dates2 = self._dates_between( self.checkpoint + timedelta(days=1), self.end ) self.dates = self._dates_between(self.start, self.end)
def test_save_database_info_invalid_service_environment(self): service_environment = ServiceEnvironmentFactory.build() sample_db = self._get_sample_database() sample_db['service_id'] = service_environment.service.ci_id sample_db['environment_id'] = service_environment.environment.ci_id created, database_info = save_database_info( sample_db, self.unknown_service_environment ) self.assertTrue(created) self._compare_databases(sample_db, database_info) self.assertEquals( database_info.service_environment, self.unknown_service_environment )
def setUp(self): self.today = date(2014, 11, 10) self.service_environments = ServiceEnvironmentFactory.create_batch(5) self.pricing_service1 = PricingServiceFactory() fixed_price = ( models.PricingServicePlugin.pricing_service_fixed_price_plugin) self.pricing_service2 = PricingServiceFactory(plugin_type=fixed_price) self.pricing_service2.charge_diff_to_real_costs = self.pricing_service1 self.pricing_service2.save() self.pricing_service3 = PricingServiceFactory(plugin_type=fixed_price) self.pricing_service3.charge_diff_to_real_costs = self.pricing_service1 self.pricing_service3.save()
def setUp(self): self.components = ComponentsContent() self.se1 = ServiceEnvironmentFactory() self.se2 = ServiceEnvironmentFactory(service=self.se1.service, ) self.se3 = ServiceEnvironmentFactory() self.today = datetime.date(2014, 10, 11) self.dpo1, self.dpo2 = DailyAssetInfoFactory.create_batch( 2, service_environment=self.se1, pricing_object__service_environment=self.se1, date=self.today, ) self.dpo3 = DailyAssetInfoFactory( service_environment=self.se2, pricing_object__service_environment=self.se2, date=self.today, ) self.dpo3 = DailyAssetInfoFactory( service_environment=self.se3, pricing_object__service_environment=self.se3, date=self.today, ) self.maxDiff = None
def test_vip_plugin(self, update_vip_mock, get_vips_mock): unknown_service_environment = ServiceEnvironmentFactory( service__ci_uid=UNKNOWN_SERVICE_ENVIRONMENT[0], environment__name=UNKNOWN_SERVICE_ENVIRONMENT[1], ) update_vip_mock.return_value = True vips_list = [self._get_sample_vip()] * 5 get_vips_mock.return_value = vips_list result = vip_plugin(self.today) self.assertEquals(result, (True, 'VIPs: 5 new, 0 updated, 5 total')) self.assertEquals(update_vip_mock.call_count, 5) update_vip_mock.assert_any_call( vips_list[0], self.today, unknown_service_environment, )
def setUp(self): self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) self.extra_cost_type = ExtraCostTypeFactory() self.service_environments = ServiceEnvironmentFactory.create_batch(5) for se in self.service_environments[:5]: models.ExtraCost( extra_cost_type=self.extra_cost_type, start=self.start, end=self.end, service_environment=se, cost=3000, # daily cost: 100 forecast_cost=6000, # daily cost: 200 ).save()
def setUp(self): self.today = date(2014, 11, 10) self.service_environments = ServiceEnvironmentFactory.create_batch(5) self.pricing_service1 = PricingServiceFactory() fixed_price = ( models.PricingServicePlugin.pricing_service_fixed_price_plugin ) self.pricing_service2 = PricingServiceFactory(plugin_type=fixed_price) self.pricing_service2.charge_diff_to_real_costs = self.pricing_service1 self.pricing_service2.save() self.pricing_service3 = PricingServiceFactory(plugin_type=fixed_price) self.pricing_service3.charge_diff_to_real_costs = self.pricing_service1 self.pricing_service3.save()
def test_update(self): service_environment = ServiceEnvironmentFactory.create() virtual.update( 'virtual_group', AttributeDict( device_id=1, service_id=service_environment.service.ci_id, environment_id=service_environment.environment.ci_id, model_id=1, model_name='sample model', ), {'key': 'value', 'key2': 'value2'}, self.today, ) self.assertEqual(virtual.update_virtual_usage.call_count, 2) self.assertEqual(virtual.update_virtual_info.call_count, 1)
def test_update_virtual_usage(self): service_env = ServiceEnvironmentFactory.create() daily_virtual_info = DailyVirtualInfoFactory() usage_type = UsageTypeFactory.create() daily_usage = virtual.update_virtual_usage( daily_virtual_info, service_env, usage_type, self.today, 100, ) self.assertEqual(models.VirtualInfo.objects.all().count(), 1) self.assertEqual(daily_usage.service_environment, service_env) self.assertEqual(daily_usage.type, usage_type) self.assertEqual(daily_usage.date, self.today) self.assertEqual(daily_usage.value, 100) self.assertEqual(daily_usage.daily_pricing_object, daily_virtual_info)
def _create_usages(self): self.service_environments = ServiceEnvironmentFactory.create_batch(2) for usage_type in self.usage_types: for se, value in zip(self.service_environments, [30, 70]): dpo = se.dummy_pricing_object for day in rrule.rrule( rrule.DAILY, dtstart=self.start, until=self.end ): models.DailyUsage.objects.create( date=day, service_environment=se, daily_pricing_object=dpo.get_daily_pricing_object(day), type=usage_type, value=value, )
def test_update(self): service_environment = ServiceEnvironmentFactory() pricing_object = PricingObjectFactory.create( name='8.8.8.8', type_id=PRICING_OBJECT_TYPES.IP_ADDRESS, service_environment=service_environment, ) DailyPricingObjectFactory.create( pricing_object=pricing_object, service_environment=service_environment, ) self.assertEqual( netflow.update( {('8.8.8.8', '80'): 30}, netflow.get_usage_type(), service_environment, date(year=2014, month=1, day=1), ), (0, 1, 1))
def test_save_vip_info_invalid_service_environment(self): service_environment = ServiceEnvironmentFactory.build() sample_vip = self._get_sample_vip() sample_vip['service_id'] = service_environment.service.ci_id sample_vip['environment_id'] = service_environment.environment.ci_id created, vip_info = save_vip_info( sample_vip, self.unknown_service_environment ) self.assertTrue(created) self._compare_vips(sample_vip, vip_info) self.assertEquals( vip_info.service_environment, self.unknown_service_environment ) self.assertEquals( vip_info.ip_info.service_environment, self.unknown_service_environment )
def test_update(self): service_environment = ServiceEnvironmentFactory.create() virtual.update( 'virtual_group', AttributeDict( device_id=1, service_id=service_environment.service.ci_id, environment_id=service_environment.environment.ci_id, model_id=1, model_name='sample model', ), { 'key': 'value', 'key2': 'value2' }, self.today, ) self.assertEqual(virtual.update_virtual_usage.call_count, 2) self.assertEqual(virtual.update_virtual_info.call_count, 1)
def test_update_virtual_virtual_info(self): service_env = ServiceEnvironmentFactory.create() data = AttributeDict( device_id=1, name='sample', service_id=service_env.service.ci_id, environment_id=service_env.environment.ci_id, model_id=1, model_name='sample model', ) daily_virtual_info = virtual.update_virtual_info( 'virtual_group', data, self.today, service_env, ) self._compare_daily_virtual_info( daily_virtual_info, data, service_env, 'virtual_group', ) self.assertIsNone(daily_virtual_info.hypervisor)
def setUp(self): self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) self.pricing_service = PricingServiceFactory() self.service_usage_types = UsageTypeFactory.create_batch( 2, usage_type='SU', ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.pricing_service, start=self.start, end=self.end, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.pricing_service, start=self.start, end=self.end, ) self.service_environments = ServiceEnvironmentFactory.create_batch(2) self.maxDiff = None
def setUp(self): self.maxDiff = None self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) # TODO: unify with usages generator # base usages self.base_usage_type = UsageTypeFactory( usage_type='BU', by_cost=True, ) # regular usage self.regular_usage_type = UsageTypeFactory( usage_type='RU', by_cost=False, ) # team self.team = TeamFactory() # extra cost self.extra_cost_type = ExtraCostTypeFactory() # pricing services self.pricing_service1 = PricingServiceFactory() self.pricing_service1.regular_usage_types.add(self.regular_usage_type) self.pricing_service1.save() # NOTICE THAT PRICING SERVICE 2 IS NOT CHARGED FOR REGULAR USAGE self.pricing_service2 = PricingServiceFactory() # services self.service_environments = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.pricing_service1, ) self.service_environments.append(ServiceEnvironmentFactory.create( service__pricing_service=self.pricing_service2, )) self.service_environments.extend( ServiceEnvironmentFactory.create_batch(3) ) # pricing service usages self.service_usage_types = UsageTypeFactory.create_batch( 3, usage_type='SU', ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=30, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[2], pricing_service=self.pricing_service2, start=self.start, end=self.end, percent=100, ) # daily pricing objects # in pricing service 1 (& use pricing service 2) self.se1_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[0] ) self.se2_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[1] ) # in pricing service 2 self.se3_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[2] ) # use pricing service 1 self.se4_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[3] ) self.se5_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[4] ) # use pricing service 2 (besides se1_dpo and se2_dpo) self.se6_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[5] ) # other self.se7_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[5] ) # SO FAR SUMMARY: # there are 2 pricing services: # pricing service 1: collect costs from 2 services (4 pricing objects: # se1_dpo and se2_dpo); is distributed according to usages of 2 service # usage types: sut[0] (30%) and sut[1] (70%) # pricing service 2: collect costs from 1 service (2 pricing objects: # se3_dpo); is distributed according to usages of 1 service usage type # (sut[2] - 100%) # there are also another 2 service environments (each has 2 pricing # objects) # TOTAL DAILY PRICING OBJECTS: 14 # USAGES # base usage type models.UsagePrice( type=self.base_usage_type, # cost per unit: 1, daily cost (usages are the same for each date): # 140, cost per daily pricing object: 10 cost=4200, forecast_cost=8400, # cost per unit: 2 start=self.start, end=self.end, ).save() # regular usage type models.UsagePrice( type=self.regular_usage_type, price=10, forecast_price=20, start=self.start, end=self.end, ).save() days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: # TODO: fix assigning DPO with wrong date to DailyUsage for dpo in models.DailyPricingObject.objects.all(): DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10, type=self.base_usage_type, ) DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=5, type=self.regular_usage_type, ) # team team_cost = models.TeamCost( team=self.team, cost=300, # daily cost: 10 forecast_cost=600, # daily cost: 20 start=self.start, end=self.end, ) team_cost.save() for se in self.service_environments[:5]: models.TeamServiceEnvironmentPercent( team_cost=team_cost, service_environment=se, percent=20, # 2 per day per se ).save() # extra cost for se in self.service_environments[:5]: models.ExtraCost( extra_cost_type=self.extra_cost_type, start=self.start, end=self.end, service_environment=se, cost=3000, # daily cost: 100 forecast_cost=6000, # daily cost: 200 ).save() # pricing service 1 service usage types usages for dpo, multiplier in zip(self.se4_dpo + self.se5_dpo, [1, 1, 3, 3]): days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: DailyUsageFactory( type=self.service_usage_types[0], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10 * multiplier, date=day, ) DailyUsageFactory( type=self.service_usage_types[1], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=50 * multiplier, date=day, ) # pricing service 2 service usage types usages for dpo in self.se1_dpo + self.se6_dpo: days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: DailyUsageFactory( type=self.service_usage_types[2], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=100, date=day, )
def _init(self): self.ps1, self.ps2, self.ps3 = PricingServiceFactory.create_batch(3) self.se1, self.se2 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps1, ) self.se3, self.se4 = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.ps2, ) self.se5 = ServiceEnvironmentFactory( service__pricing_service=self.ps3 ) self.other_se = ServiceEnvironmentFactory.create_batch(5) self.service_usage_types = UsageTypeFactory.create_batch( 4, usage_type='SU', ) self.ps1.excluded_services.add(self.other_se[0].service) self.ps1.save() self.ps2.excluded_services.add(self.other_se[1].service) self.ps2.save() self.service_usage_types[0].excluded_services.add( self.other_se[2].service ) self.service_usage_types[0].save() self.service_usage_types[3].excluded_services.add( self.other_se[4].service ) self.service_usage_types[3].save() models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.ps1, start=self.start, end=self.end, percent=100, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.ps2, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[2], pricing_service=self.ps2, start=self.start, end=self.end, percent=30, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[3], pricing_service=self.ps3, start=self.start, end=self.end, percent=100, )
def setUp(self): self.maxDiff = None self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) fixed_price = ( models.PricingServicePlugin.pricing_service_fixed_price_plugin) self.pricing_service1 = PricingServiceFactory(plugin_type=fixed_price) self.service_environments = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.pricing_service1, ) self.service_environments.append(ServiceEnvironmentFactory()) self.service_usage_types = UsageTypeFactory.create_batch( 2, usage_type='SU', ) self.sut1 = models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=100, ) self.sut2 = models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=100, ) self.se1_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[0]) self.se2_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[1]) self.se3_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[2]) models.UsagePrice( type=self.service_usage_types[0], price=10, forecast_price=20, start=self.start, end=self.end, ).save() models.UsagePrice( type=self.service_usage_types[1], price=20, forecast_price=40, start=self.start, end=self.end, ).save() days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: for dpo in models.DailyPricingObject.objects.all(): DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10, type=self.service_usage_types[0], ) DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=5, type=self.service_usage_types[1], )
def setUp(self): self.maxDiff = None self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) # TODO: unify with usages generator # base usages self.base_usage_type = UsageTypeFactory( usage_type='BU', by_cost=True, ) # regular usage self.regular_usage_type = UsageTypeFactory( usage_type='RU', by_cost=False, ) # team self.team = TeamFactory() # extra cost self.extra_cost_type = ExtraCostTypeFactory() # pricing services self.pricing_service1 = PricingServiceFactory() self.pricing_service1.regular_usage_types.add(self.regular_usage_type) self.pricing_service1.save() # NOTICE THAT PRICING SERVICE 2 IS NOT CHARGED FOR REGULAR USAGE self.pricing_service2 = PricingServiceFactory() # services self.service_environments = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.pricing_service1, ) self.service_environments.append( ServiceEnvironmentFactory.create( service__pricing_service=self.pricing_service2, )) self.service_environments.extend( ServiceEnvironmentFactory.create_batch(3)) # pricing service usages self.service_usage_types = UsageTypeFactory.create_batch( 3, usage_type='SU', ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=30, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=70, ) models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[2], pricing_service=self.pricing_service2, start=self.start, end=self.end, percent=100, ) # daily pricing objects # in pricing service 1 (& use pricing service 2) self.se1_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[0]) self.se2_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[1]) # in pricing service 2 self.se3_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[2]) # use pricing service 1 self.se4_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[3]) self.se5_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[4]) # use pricing service 2 (besides se1_dpo and se2_dpo) self.se6_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[5]) # other self.se7_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[5]) # SO FAR SUMMARY: # there are 2 pricing services: # pricing service 1: collect costs from 2 services (4 pricing objects: # se1_dpo and se2_dpo); is distributed according to usages of 2 service # usage types: sut[0] (30%) and sut[1] (70%) # pricing service 2: collect costs from 1 service (2 pricing objects: # se3_dpo); is distributed according to usages of 1 service usage type # (sut[2] - 100%) # there are also another 2 service environments (each has 2 pricing # objects) # TOTAL DAILY PRICING OBJECTS: 14 # USAGES # base usage type models.UsagePrice( type=self.base_usage_type, # cost per unit: 1, daily cost (usages are the same for each date): # 140, cost per daily pricing object: 10 cost=4200, forecast_cost=8400, # cost per unit: 2 start=self.start, end=self.end, ).save() # regular usage type models.UsagePrice( type=self.regular_usage_type, price=10, forecast_price=20, start=self.start, end=self.end, ).save() days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: # TODO: fix assigning DPO with wrong date to DailyUsage for dpo in models.DailyPricingObject.objects.all(): DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10, type=self.base_usage_type, ) DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=5, type=self.regular_usage_type, ) # team team_cost = models.TeamCost( team=self.team, cost=300, # daily cost: 10 forecast_cost=600, # daily cost: 20 start=self.start, end=self.end, ) team_cost.save() for se in self.service_environments[:5]: models.TeamServiceEnvironmentPercent( team_cost=team_cost, service_environment=se, percent=20, # 2 per day per se ).save() # extra cost for se in self.service_environments[:5]: models.ExtraCost( extra_cost_type=self.extra_cost_type, start=self.start, end=self.end, service_environment=se, cost=3000, # daily cost: 100 forecast_cost=6000, # daily cost: 200 ).save() # pricing service 1 service usage types usages for dpo, multiplier in zip(self.se4_dpo + self.se5_dpo, [1, 1, 3, 3]): days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: DailyUsageFactory( type=self.service_usage_types[0], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10 * multiplier, date=day, ) DailyUsageFactory( type=self.service_usage_types[1], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=50 * multiplier, date=day, ) # pricing service 2 service usage types usages for dpo in self.se1_dpo + self.se6_dpo: days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: DailyUsageFactory( type=self.service_usage_types[2], daily_pricing_object=dpo, service_environment=dpo.service_environment, value=100, date=day, )
def setUp(self): self.maxDiff = None self.today = date(2013, 10, 10) self.start = date(2013, 10, 1) self.end = date(2013, 10, 30) fixed_price = ( models.PricingServicePlugin.pricing_service_fixed_price_plugin ) self.pricing_service1 = PricingServiceFactory(plugin_type=fixed_price) self.service_environments = ServiceEnvironmentFactory.create_batch( 2, service__pricing_service=self.pricing_service1, ) self.service_environments.append(ServiceEnvironmentFactory()) self.service_usage_types = UsageTypeFactory.create_batch( 2, usage_type='SU', ) self.sut1 = models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[0], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=100, ) self.sut2 = models.ServiceUsageTypes.objects.create( usage_type=self.service_usage_types[1], pricing_service=self.pricing_service1, start=self.start, end=self.end, percent=100, ) self.se1_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[0] ) self.se2_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[1] ) self.se3_dpo = DailyPricingObjectFactory.create_batch( 2, service_environment=self.service_environments[2] ) models.UsagePrice( type=self.service_usage_types[0], price=10, forecast_price=20, start=self.start, end=self.end, ).save() models.UsagePrice( type=self.service_usage_types[1], price=20, forecast_price=40, start=self.start, end=self.end, ).save() days = rrule.rrule(rrule.DAILY, dtstart=self.start, until=self.end) for day in days: for dpo in models.DailyPricingObject.objects.all(): DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=10, type=self.service_usage_types[0], ) DailyUsageFactory( date=day, daily_pricing_object=dpo, service_environment=dpo.service_environment, value=5, type=self.service_usage_types[1], )