Ejemplo n.º 1
0
 def test_team_average_no_price_cost(self):
     with self.assertRaises(NoPriceCostError):
         TeamPlugin.costs(
             date=self.date_out_of_range,
             service_environments=self.service_environments_subset,
             team=self.team_average,
             forecast=False,
         )
Ejemplo n.º 2
0
 def test_team_average_no_price_cost(self):
     with self.assertRaises(NoPriceCostError):
         TeamPlugin.costs(
             date=self.date_out_of_range,
             service_environments=self.service_environments_subset,
             team=self.team_average,
             forecast=False,
         )
Ejemplo n.º 3
0
 def test_team_assets_cost_0(
     self,
     team_daily_cost_mock,
     assets_count_mock,
     total_assets_mock,
 ):
     assets_count_mock.return_value = {
         self.service_environment1.id: 0,
         self.service_environment2.id: 0,
     }
     total_assets_mock.return_value = 0
     team_daily_cost_mock.return_value = (0, 0, 0)
     costs = TeamPlugin.costs(
         date=self.today,
         service_environments=self.service_environments_subset,
         team=self.team_assets,
         forecast=False,
     )
     self.assertEquals(costs, {
         self.service_environment1.id: [
             {
                 'cost': D('0'),
                 'type': self.team_assets,
                 'percent': D(0),
             }
         ],
         self.service_environment2.id: [
             {
                 'cost': D('0'),
                 'type': self.team_assets,
                 'percent': D(0),
             }
         ]
     })
Ejemplo n.º 4
0
    def test_team_assets_forecast_costs(
        self,
        assets_count_mock,
        total_assets_mock,
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 100,
            # self.service_environment3.id: 200,
        }
        total_assets_mock.return_value = 500

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_assets,
            forecast=True,
        )
        self.assertEquals(costs, {
            self.service_environment1.id: [
                {
                    'cost': D('24'),  # 200 / 500 * 60
                    'type': self.team_assets,
                    'percent': D(24) / D(60),
                }
            ],
            self.service_environment2.id: [
                {
                    'cost': D('12'),  # 100 / 500 * 60
                    'type': self.team_assets,
                    'percent': D(12) / D(60),
                }
            ]
        })
Ejemplo n.º 5
0
 def test_team_average_multiple_price_cost(self):
     TeamCostFactory(
         cost=900,
         forecast_cost=1800,
         start=self.start,
         end=self.end,
         team=self.team_average,
         members_count=20,
     )
     with self.assertRaises(MultiplePriceCostError):
         TeamPlugin.costs(
             date=self.today,
             service_environments=self.service_environments_subset,
             team=self.team_average,
             forecast=False,
         )
Ejemplo n.º 6
0
 def test_team_assets_cost_0(
     self,
     team_daily_cost_mock,
     assets_count_mock,
     total_assets_mock,
 ):
     assets_count_mock.return_value = {
         self.service_environment1.id: 0,
         self.service_environment2.id: 0,
     }
     total_assets_mock.return_value = 0
     team_daily_cost_mock.return_value = (0, 0, 0)
     costs = TeamPlugin.costs(
         date=self.today,
         service_environments=self.service_environments_subset,
         team=self.team_assets,
         forecast=False,
     )
     self.assertEquals(
         costs, {
             self.service_environment1.id: [{
                 'cost': D('0'),
                 'type': self.team_assets,
                 'percent': D(0),
             }],
             self.service_environment2.id: [{
                 'cost': D('0'),
                 'type': self.team_assets,
                 'percent': D(0),
             }]
         })
Ejemplo n.º 7
0
    def test_team_assets_forecast_costs(
        self,
        assets_count_mock,
        total_assets_mock,
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 100,
            # self.service_environment3.id: 200,
        }
        total_assets_mock.return_value = 500

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_assets,
            forecast=True,
        )
        self.assertEquals(
            costs,
            {
                self.service_environment1.id: [{
                    'cost': D('24'),  # 200 / 500 * 60
                    'type': self.team_assets,
                    'percent': D(24) / D(60),
                }],
                self.service_environment2.id: [{
                    'cost': D('12'),  # 100 / 500 * 60
                    'type': self.team_assets,
                    'percent': D(12) / D(60),
                }]
            })
Ejemplo n.º 8
0
 def test_team_average_multiple_price_cost(self):
     TeamCostFactory(
         cost=900,
         forecast_cost=1800,
         start=self.start,
         end=self.end,
         team=self.team_average,
         members_count=20,
     )
     with self.assertRaises(MultiplePriceCostError):
         TeamPlugin.costs(
             date=self.today,
             service_environments=self.service_environments_subset,
             team=self.team_average,
             forecast=False,
         )
Ejemplo n.º 9
0
    def test_team_distribute_forecast_costs(
        self,
        assets_count_mock,
        total_assets_mock,
        cores_count_mock,
        total_cores_mock
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_distribute,
            forecast=True,
        )
        # daily cost: 50
        # members count: time - 10, assets&cores - 20, assets - 20
        # dependent teams daily costs:
        # time - 10 (10/50 * 50)
        # assets & cores - 20
        # assets - 20
        self.assertEquals(costs, {
            self.service_environment1.id: [
                {
                    # time: 30% * 10 = 3
                    # assets & cores: 200 / 500 * 10  + 20 / 100 * 10 = 6
                    # assets: 200 / 500 * 20 = 8
                    'cost': D('17'),
                    'type': self.team_distribute,
                    'percent': D(17) / 50,
                }
            ],
            self.service_environment2.id: [
                {
                    # time: 40% * 10 = 4
                    # assets & cores: 200 / 500 * 10  + 40 / 100 * 10 = 8
                    # assets: 200 / 500 * 20 = 8
                    'cost': D('20'),
                    'type': self.team_distribute,
                    'percent': D(20) / 50,
                }
            ]
        })
Ejemplo n.º 10
0
    def test_team_distribute_costs(
        self,
        assets_count_mock,
        total_assets_mock,
        cores_count_mock,
        total_cores_mock
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_distribute,
            forecast=False,
        )
        # daily cost: 100
        # members count: time - 10, assets&cores - 20, assets - 20
        # dependent teams daily costs:
        # time - 20 (10/50 * 100)
        # assets & cores - 40
        # assets - 40
        self.assertEquals(costs, {
            self.service_environment1.id: [
                {
                    # time: 30% * 20 = 6
                    # assets & cores: 200 / 500 * 20  + 20 / 100 * 20 = 12
                    # assets: 200 / 500 * 40 = 16
                    'cost': D('34'),
                    'type': self.team_distribute,
                    'percent': D(34) / 100,
                }
            ],
            self.service_environment2.id: [
                {
                    # time: 40% * 20 = 8
                    # assets & cores: 200 / 500 * 20  + 40 / 100 * 20 = 16
                    # assets: 200 / 500 * 40 = 16
                    'cost': D('40'),
                    'type': self.team_distribute,
                    'percent': D(40) / 100,
                }
            ]
        })
Ejemplo n.º 11
0
    def test_team_distribute_forecast_costs(self, assets_count_mock,
                                            total_assets_mock,
                                            cores_count_mock,
                                            total_cores_mock):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_distribute,
            forecast=True,
        )
        # daily cost: 50
        # members count: time - 10, assets&cores - 20, assets - 20
        # dependent teams daily costs:
        # time - 10 (10/50 * 50)
        # assets & cores - 20
        # assets - 20
        self.assertEquals(
            costs,
            {
                self.service_environment1.id: [{
                    # time: 30% * 10 = 3
                    # assets & cores: 200 / 500 * 10  + 20 / 100 * 10 = 6
                    # assets: 200 / 500 * 20 = 8
                    'cost': D('17'),
                    'type': self.team_distribute,
                    'percent': D(17) / 50,
                }],
                self.service_environment2.id: [{
                    # time: 40% * 10 = 4
                    # assets & cores: 200 / 500 * 10  + 40 / 100 * 10 = 8
                    # assets: 200 / 500 * 20 = 8
                    'cost': D('20'),
                    'type': self.team_distribute,
                    'percent': D(20) / 50,
                }]
            })
Ejemplo n.º 12
0
    def test_team_average_forecast_costs(
        self,
        assets_count_mock,
        total_assets_mock,
        cores_count_mock,
        total_cores_mock
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_average,
            forecast=True,
        )
        # daily cost: 100
        # percentage:
        # time: se1 - 0.3, se2: 0.4
        # assets & cores: se1 - 0.3, se2 - 0.4
        # assets: se1 - 0.4, se2 - 0.4
        # distrubution: se1 - 0.34, se2 - 0.4
        # total: se1 - 1.34, se2 - 1.6
        self.assertEquals(costs, {
            self.service_environment1.id: [
                {
                    'cost': D('33.5'),  # 1.34 * 100 / 4 (total teams count)
                    'type': self.team_average,
                    'percent': D(33.5) / 100,
                }
            ],
            self.service_environment2.id: [
                {
                    'cost': D('40'),  # 1.6 * 100 / 4
                    'type': self.team_average,
                    'percent': D(40) / 100,
                }
            ]
        })
Ejemplo n.º 13
0
    def test_team_distribute_costs(self, assets_count_mock, total_assets_mock,
                                   cores_count_mock, total_cores_mock):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_distribute,
            forecast=False,
        )
        # daily cost: 100
        # members count: time - 10, assets&cores - 20, assets - 20
        # dependent teams daily costs:
        # time - 20 (10/50 * 100)
        # assets & cores - 40
        # assets - 40
        self.assertEquals(
            costs,
            {
                self.service_environment1.id: [{
                    # time: 30% * 20 = 6
                    # assets & cores: 200 / 500 * 20  + 20 / 100 * 20 = 12
                    # assets: 200 / 500 * 40 = 16
                    'cost': D('34'),
                    'type': self.team_distribute,
                    'percent': D(34) / 100,
                }],
                self.service_environment2.id: [{
                    # time: 40% * 20 = 8
                    # assets & cores: 200 / 500 * 20  + 40 / 100 * 20 = 16
                    # assets: 200 / 500 * 40 = 16
                    'cost': D('40'),
                    'type': self.team_distribute,
                    'percent': D(40) / 100,
                }]
            })
Ejemplo n.º 14
0
    def test_team_average_forecast_costs(self, assets_count_mock,
                                         total_assets_mock, cores_count_mock,
                                         total_cores_mock):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_average,
            forecast=True,
        )
        # daily cost: 100
        # percentage:
        # time: se1 - 0.3, se2: 0.4
        # assets & cores: se1 - 0.3, se2 - 0.4
        # assets: se1 - 0.4, se2 - 0.4
        # distrubution: se1 - 0.34, se2 - 0.4
        # total: se1 - 1.34, se2 - 1.6
        self.assertEquals(
            costs,
            {
                self.service_environment1.id: [{
                    'cost': D('33.5'),  # 1.34 * 100 / 4 (total teams count)
                    'type': self.team_average,
                    'percent': D(33.5) / 100,
                }],
                self.service_environment2.id: [{
                    'cost': D('40'),  # 1.6 * 100 / 4
                    'type': self.team_average,
                    'percent': D(40) / 100,
                }]
            })
Ejemplo n.º 15
0
    def test_team_assets_cores_forecast_costs(
        self,
        assets_count_mock,
        total_assets_mock,
        cores_count_mock,
        total_cores_mock
    ):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_assets_cores,
            forecast=True,
        )
        self.assertEquals(costs, {
            self.service_environment1.id: [
                {
                    'cost': D('6'),  # 200 / 500 * 10 + 20 / 100 * 10
                    'type': self.team_assets_cores,
                    'percent': D(6) / D(20),
                }
            ],
            self.service_environment2.id: [
                {
                    'cost': D('8'),  # 200 / 500 * 10 + 40 / 100 * 10
                    'type': self.team_assets_cores,
                    'percent': D(8) / D(20),
                }
            ]
        })
Ejemplo n.º 16
0
 def test_team_time_forecast_costs(self):
     costs = TeamPlugin.costs(
         date=self.today,
         service_environments=self.service_environments_subset,
         team=self.team_time,
         forecast=True,
     )
     self.assertEquals(
         costs,
         {
             self.service_environment1.id: [{
                 'cost': D('6'),  # 30 % of daily cost 20
                 'type': self.team_time,
                 'percent': D('0.3'),
             }],
             self.service_environment2.id: [{
                 'cost': D('8'),  # 40 % of daily cost 20
                 'type': self.team_time,
                 'percent': D('0.4'),
             }]
         })
Ejemplo n.º 17
0
 def test_team_time_forecast_costs(self):
     costs = TeamPlugin.costs(
         date=self.today,
         service_environments=self.service_environments_subset,
         team=self.team_time,
         forecast=True,
     )
     self.assertEquals(costs, {
         self.service_environment1.id: [
             {
                 'cost': D('6'),  # 30 % of daily cost 20
                 'type': self.team_time,
                 'percent': D('0.3'),
             }
         ],
         self.service_environment2.id: [
             {
                 'cost': D('8'),  # 40 % of daily cost 20
                 'type': self.team_time,
                 'percent': D('0.4'),
             }
         ]
     })
Ejemplo n.º 18
0
    def test_team_assets_cores_forecast_costs(self, assets_count_mock,
                                              total_assets_mock,
                                              cores_count_mock,
                                              total_cores_mock):
        assets_count_mock.return_value = {
            self.service_environment1.id: 200,
            self.service_environment2.id: 200,
            # self.service_environment3.id: 100,
        }
        total_assets_mock.return_value = 500
        cores_count_mock.return_value = {
            self.service_environment1.id: 20,
            self.service_environment2.id: 40,
            # self.service_environment3.id: 40,
        }
        total_cores_mock.return_value = 100

        costs = TeamPlugin.costs(
            date=self.today,
            service_environments=self.service_environments_subset,
            team=self.team_assets_cores,
            forecast=True,
        )
        self.assertEquals(
            costs,
            {
                self.service_environment1.id: [{
                    'cost': D('6'),  # 200 / 500 * 10 + 20 / 100 * 10
                    'type': self.team_assets_cores,
                    'percent': D(6) / D(20),
                }],
                self.service_environment2.id: [{
                    'cost': D('8'),  # 200 / 500 * 10 + 40 / 100 * 10
                    'type': self.team_assets_cores,
                    'percent': D(8) / D(20),
                }]
            })