Пример #1
0
 def test_calculate_negative_amount_per_day(self):
     instance = Rate()
     instance.description = 'Test Rate'
     instance.amount = Decimal(-10)
     instance.days = 11
     instance.user = User.objects.create_user('*****@*****.**')
     instance.save()
     instance.refresh_from_db()
     self.assertEqual(instance.amount_per_day, to_decimal(-0.909))
Пример #2
0
 def test_calculate_negative_amount_per_day(self):
     instance = Rate()
     instance.description = 'Test Rate'
     instance.amount = Decimal(-10)
     instance.days = 11
     instance.user = User.objects.create_user('*****@*****.**')
     instance.save()
     instance.refresh_from_db()
     self.assertEqual(instance.amount_per_day, to_decimal(-0.909))
Пример #3
0
 def _associate_rates(self, name, rates):
     user = getattr(self, name)
     for item in rates:
         rate = Rate()
         rate.description = 'Test Rate'
         rate.amount = item.amount
         rate.days = item.days
         rate.user = user
         rate.save()
Пример #4
0
 def _associate_rates(self, name, rates):
     user = getattr(self, name)
     for item in rates:
         rate = Rate()
         rate.description = 'Test Rate'
         rate.amount = item.amount
         rate.days = item.days
         rate.user = user
         rate.save()
Пример #5
0
    def test_total_something(self):
        instance = Rate()
        instance.description = 'Test Rate'
        instance.amount = Decimal(10)
        instance.days = 10
        instance.user = User.objects.create_user('*****@*****.**')
        instance.save()

        actual = Rate.objects.total()
        self.assertEqual(actual, to_decimal(1))
Пример #6
0
    def test_total_something(self):
        instance = Rate()
        instance.description = 'Test Rate'
        instance.amount = Decimal(10)
        instance.days = 10
        instance.user = User.objects.create_user('*****@*****.**')
        instance.save()

        actual = Rate.objects.total()
        self.assertEqual(actual, to_decimal(1))
Пример #7
0
    def create_rate(self, description ="Test Rate", days=10, amount = 10):
        usr = User.objects.create_user('*****@*****.**')

        rate = Rate()
        rate.description = description
        rate.amount = Decimal(amount)
        rate.days = days
        rate.user = usr

        rate.save()
        rate.refresh_from_db()

        return rate
Пример #8
0
class TestTransactRateBalance(TestCase):
    def setUp(self):
        self.rate1 = Rate()
        self.rate1.description = 'Test 1'
        self.rate1.amount = -50
        self.rate1.days = 30
        self.rate1.save()
        self.rate1.refresh_from_db()

        self.rate2 = Rate()
        self.rate2.description = 'Test 2'
        self.rate2.amount = -100
        self.rate2.days = 30
        self.rate2.save()
        self.rate2.refresh_from_db()

    def test_transaction(self):
        Transaction.objects.transact_rate_balance()
        self.assertEqual(Transaction.objects.total(),
                         to_decimal(-5, place='0.01'))
Пример #9
0
class TestTransactRateBalance(TestCase):
    def setUp(self):
        self.rate1 = Rate()
        self.rate1.description = 'Test 1'
        self.rate1.amount = -50
        self.rate1.days = 30
        self.rate1.save()
        self.rate1.refresh_from_db()

        self.rate2 = Rate()
        self.rate2.description = 'Test 2'
        self.rate2.amount = -100
        self.rate2.days = 30
        self.rate2.save()
        self.rate2.refresh_from_db()

    def test_transaction(self):
        Transaction.objects.transact_rate_balance()
        self.assertEqual(Transaction.objects.total(),
                         to_decimal(-5, place='0.01'))
Пример #10
0
class TestRate(TestCase):
    def setUp(self):
        self.rate1 = Rate()
        self.rate1.description = 'Test 1'
        self.rate1.amount = -50
        self.rate1.days = 30
        self.rate1.save()
        self.rate1.refresh_from_db()

        self.rate2 = Rate()
        self.rate2.description = 'Test 2'
        self.rate2.amount = -100
        self.rate2.days = 30
        self.rate2.save()
        self.rate2.refresh_from_db()

        self.rate3 = Rate()
        self.rate3.description = 'Test 3'
        self.rate3.amount = 100
        self.rate3.days = 5
        self.rate3.save()
        self.rate3.refresh_from_db()

    def test_amount_per_day(self):
        self.assertEqual(self.rate1.amount_per_day, to_decimal(-1.667))
        self.assertEqual(self.rate2.amount_per_day, to_decimal(-3.333))
        self.assertEqual(self.rate3.amount_per_day, to_decimal(20))

    def test_total(self):
        self.assertEqual(Rate.objects.total(), to_decimal(15))
Пример #11
0
class TestRate(TestCase):
    def setUp(self):
        self.rate1 = Rate()
        self.rate1.description = 'Test 1'
        self.rate1.amount = -50
        self.rate1.days = 30
        self.rate1.save()
        self.rate1.refresh_from_db()

        self.rate2 = Rate()
        self.rate2.description = 'Test 2'
        self.rate2.amount = -100
        self.rate2.days = 30
        self.rate2.save()
        self.rate2.refresh_from_db()

        self.rate3 = Rate()
        self.rate3.description = 'Test 3'
        self.rate3.amount = 100
        self.rate3.days = 5
        self.rate3.save()
        self.rate3.refresh_from_db()

    def test_amount_per_day(self):
        self.assertEqual(self.rate1.amount_per_day, to_decimal(-1.667))
        self.assertEqual(self.rate2.amount_per_day, to_decimal(-3.333))
        self.assertEqual(self.rate3.amount_per_day, to_decimal(20))

    def test_total(self):
        self.assertEqual(Rate.objects.total(),
                         to_decimal(15))