|
@@ -1,7 +1,82 @@
|
|
|
+import datetime
|
|
|
+
|
|
|
from django.test import TestCase
|
|
|
from django.core.exceptions import ValidationError
|
|
|
|
|
|
-from ..models import Service, Cost, CostUse, Document
|
|
|
+from ..models import (
|
|
|
+ Cost, CostUse, Document, Good, GoodUse, Service)
|
|
|
+
|
|
|
+
|
|
|
+class ServiceTests(TestCase):
|
|
|
+ def setUp(self):
|
|
|
+ self.doc = Document.objects.create(name='budget')
|
|
|
+ self.electricity_cost = Cost.objects.create(
|
|
|
+ name='electricity',
|
|
|
+ price=10,
|
|
|
+ document=self.doc,
|
|
|
+ )
|
|
|
+ self.server = Good.objects.create(
|
|
|
+ name="Computer",
|
|
|
+ price=10,
|
|
|
+ document=self.doc,
|
|
|
+ provisioning_duration=datetime.timedelta(days=365*3),
|
|
|
+ )
|
|
|
+
|
|
|
+ def test_get_prices_zero(self):
|
|
|
+ s = Service.objects.create(name='Foo', document=self.doc)
|
|
|
+ self.assertEqual(s.get_prices(), {
|
|
|
+ 'total_costs_price': 0,
|
|
|
+ 'unit_costs_price': 0,
|
|
|
+ 'unit_goods_value_share': 0,
|
|
|
+ 'total_goods_value_share': 0,
|
|
|
+ })
|
|
|
+
|
|
|
+ def test_get_prices_w_costs(self):
|
|
|
+ s = Service.objects.create(name='Foo', document=self.doc)
|
|
|
+
|
|
|
+ CostUse.objects.create(
|
|
|
+ service=s, resource=self.electricity_cost, share=0.4)
|
|
|
+
|
|
|
+ self.assertEqual(s.get_prices(), {
|
|
|
+ 'total_costs_price': 10,
|
|
|
+ 'unit_costs_price': 0,
|
|
|
+ 'unit_goods_value_share': 0,
|
|
|
+ 'total_goods_value_share': 0,
|
|
|
+ })
|
|
|
+
|
|
|
+ s.subscriptions_count = 2
|
|
|
+ s.save()
|
|
|
+
|
|
|
+ self.assertEqual(s.get_prices(), {
|
|
|
+ 'total_costs_price': 10,
|
|
|
+ 'unit_costs_price': 5,
|
|
|
+ 'unit_goods_value_share': 0,
|
|
|
+ 'total_goods_value_share': 0,
|
|
|
+ })
|
|
|
+
|
|
|
+ def test_get_prices_w_goods(self):
|
|
|
+ s = Service.objects.create(
|
|
|
+ name='Foo', document=self.doc, subscriptions_count=0)
|
|
|
+
|
|
|
+ GoodUse.objects.create(
|
|
|
+ service=s, resource=self.server, share=0.4)
|
|
|
+
|
|
|
+ self.assertEqual(s.get_prices(), {
|
|
|
+ 'total_costs_price': 10/(365*3)*365.25/12,
|
|
|
+ 'unit_costs_price': 0,
|
|
|
+ 'unit_goods_value_share': 0,
|
|
|
+ 'total_goods_value_share': 10.0,
|
|
|
+ })
|
|
|
+
|
|
|
+ s.subscriptions_count = 2
|
|
|
+ s.save()
|
|
|
+
|
|
|
+ self.assertEqual(s.get_prices(), {
|
|
|
+ 'total_costs_price': 10/(365*3)*365.25/12,
|
|
|
+ 'unit_costs_price': 10/(365*3)*365.25/12/2,
|
|
|
+ 'unit_goods_value_share': 5,
|
|
|
+ 'total_goods_value_share': 10,
|
|
|
+ })
|
|
|
|
|
|
|
|
|
class AbstractUseTests(TestCase):
|