コード例 #1
0
    def test_get_price_from_cost_total_excluded_services(
            self, get_total_usage_mock):
        get_total_usage_mock.return_value = 10.0
        usage_price = models.UsagePrice(
            start=datetime.date(2013, 10, 10),
            end=datetime.date(2013, 10, 10),
            cost=3000,
            type=self.usage_type_cost_wh,
        )
        result = self.plugin._get_price_from_cost(
            usage_price,
            False,
            excluded_services=[self.service_environment1],
        )

        self.assertEquals(result, D(300))
        get_total_usage_mock.assert_called_with(
            start=datetime.date(2013, 10, 10),
            end=datetime.date(2013, 10, 10),
            usage_type=self.usage_type_cost_wh,
            excluded_services=[self.service_environment1],
            excluded_services_environments=None,
            warehouse=None,
            service_environments=None,
        )
コード例 #2
0
    def test_get_price_from_cost_total_usage_0(self, get_total_usage_mock):
        get_total_usage_mock.return_value = 0.0
        usage_price = models.UsagePrice(
            start=datetime.date(2013, 10, 10),
            end=datetime.date(2013, 10, 10),
            cost=3000,
            type=self.usage_type_cost_wh,
        )
        result = self.plugin._get_price_from_cost(usage_price, False)

        self.assertEquals(result, D(0))
コード例 #3
0
 def add_usage_price(usage_type, prices_costs, warehouse=None):
     for daterange, price_cost in zip(dates, prices_costs):
         start, end = daterange
         usage_price = models.UsagePrice(
             type=usage_type,
             start=start,
             end=end,
         )
         if warehouse is not None:
             usage_price.warehouse = warehouse
         if usage_type.by_cost:
             usage_price.cost = price_cost[0]
             usage_price.forecast_cost = price_cost[1]
         else:
             usage_price.price = price_cost[0]
             usage_price.forecast_price = price_cost[1]
         usage_price.save()
コード例 #4
0
    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,
                )
コード例 #5
0
    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],
                )