def test_const_sales_weight_avg(self):
        MAX_LAST_SALES = 5
        YEAR = 2019
        JANUARY = 1
        FEBRUARY = 2

        seller = self.get_seller()

        january_sale = self.create_sale(seller=seller, month=JANUARY, year=YEAR, amount=4500)
        february_sale = self.create_sale(seller=seller, month=FEBRUARY, year=YEAR, amount=6700)

        january_weight = 1

        february_weight = 2

        weights_sum = january_weight + february_weight

        weighted_avg = ((january_sale.comission_value * january_weight) + (february_sale.comission_value * february_weight)) / weights_sum

        last_sales = get_seller_last_sales(seller=seller, max_last_sales=MAX_LAST_SALES)

        sale_weighted_avg = comission_weight_avg(sales=last_sales)

        decimal_places = 10

        self.assertAlmostEqual(
            sale_weighted_avg,
            weighted_avg,
            decimal_places
        )
Пример #2
0
 def test_get_sales(self):
     MAX_LAST_SALES = 5
     seller = self.get_seller()
     self.generate_sales(seller=seller, year=2019)
     last_sales_length = len(
         get_seller_last_sales(seller=seller,
                               max_last_sales=MAX_LAST_SALES))
     self.assertEquals(last_sales_length, MAX_LAST_SALES)
    def test_get_no_sales(self):

        MAX_LAST_SALES = 5

        seller = self.get_seller()

        last_sales = get_seller_last_sales(seller=seller, max_last_sales=MAX_LAST_SALES)

        self.assertFalse(last_sales)
Пример #4
0
 def test_sales_weight_avg(self):
     seller = self.get_seller()
     CONSTANT_AMOUNT = Decimal(500.0)
     PERCENTAGE = Sale.calculate_comission(plan=seller.plan,
                                           amount=CONSTANT_AMOUNT)
     MAX_LAST_SALES = 5
     self.generate_const_sales(seller=seller,
                               year=2019,
                               amount=CONSTANT_AMOUNT)
     last_sales = get_seller_last_sales(seller=seller,
                                        max_last_sales=MAX_LAST_SALES)
     sale_weighted_avg = comission_weight_avg(sales=last_sales)
     self.assertEquals(sale_weighted_avg, PERCENTAGE)