diff --git a/examples/test_rates.csv b/examples/test_rates.csv index e7093a0..746b41c 100644 --- a/examples/test_rates.csv +++ b/examples/test_rates.csv @@ -1,10 +1,10 @@ -region | service0 | hour | 0.32 +region | service0 | gigabyte | 0.32 region | service1 | gigabyte | 0.312 -region | service2 | hour | 0.43 +region | service2 | gigabyte | 0.43 region | service3 | gigabyte | 0.38 -region | service4 | hour | 0.43 +region | service4 | gigabyte | 0.43 region | service5 | gigabyte | 0.32 -region | service6 | hour | 0.312 +region | service6 | gigabyte | 0.312 region | service7 | gigabyte | 0.53 -region | service8 | hour | 0.73 +region | service8 | gigabyte | 0.73 region | service9 | gigabyte | 0.9 \ No newline at end of file diff --git a/tests/helpers.py b/tests/helpers.py index d98dc8f..8fd9997 100644 --- a/tests/helpers.py +++ b/tests/helpers.py @@ -22,6 +22,7 @@ def fill_db(session, numb_tenants, numb_resources, now): session.add(models.UsageEntry( service="service" + str(ii), volume=5, + unit='gigabyte', resource_id="resource_id_" + str(ii), tenant_id="tenant_id_" + str(i), start=(now - timedelta(days=20)), diff --git a/tests/test_api.py b/tests/test_api.py index f4c386a..fa23f6e 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -74,9 +74,6 @@ class TestApi(test_interface.TestInterface): helpers.fill_db(self.session, numTenants, numResources, now) - for entry in self.session.query(models.UsageEntry): - print entry - for i in range(numTenants): resp = self.app.post("/sales_order", params=json.dumps({"tenant": "tenant_id_" + @@ -177,21 +174,25 @@ class TestApi(test_interface.TestInterface): 'resources': { 'resouce_ID_1': { 'services': [{'name': 'service_1', - 'volume': Decimal(volume)}, + 'volume': Decimal(volume), + 'unit': 'second'}, {'name': 'service_2', - 'volume': Decimal(volume)}] + 'volume': Decimal(volume), + 'unit': 'second'}] }, 'resouce_ID_2': { 'services': [{'name': 'service_1', - 'volume': Decimal(volume)}, + 'volume': Decimal(volume), + 'unit': 'second'}, {'name': 'service_2', - 'volume': Decimal(volume)}] + 'volume': Decimal(volume), + 'unit': 'second'}] } } } - service_cost = round(convert_to(volume, rate['unit']) * rate['rate'], - 2) + service_cost = round( + convert_to(volume, 'second', rate['unit']) * rate['rate'], 2) total_cost = service_cost * 4 ratesManager = mock.MagicMock() @@ -204,7 +205,8 @@ class TestApi(test_interface.TestInterface): self.assertEquals(resource['total_cost'], str(service_cost * 2)) for service in resource['services']: self.assertEquals(service['volume'], - str(convert_to(volume, rate['unit']))) + str(convert_to(volume, 'second', + rate['unit']))) self.assertEquals(service['unit'], rate['unit']) self.assertEquals(service['cost'], str(service_cost))