def test_save_extra_cost_when_there_is_wrong_env(self): extra_cost_type = factory.ExtraCostTypeFactory() service_environment = factory.ServiceEnvironmentFactory() self.assertRaises( ServiceEnvironmentDoesNotExistError, self.client.post, '/scrooge/rest/allocationadmin/{0}/{1}/extracosts/save'.format( self.date.year, self.date.month, ), { 'rows': [{ 'extra_cost_type': { 'id': extra_cost_type.id, 'name': extra_cost_type.name }, 'extra_costs': [{ 'cost': 0.0, 'forecast_cost': 0.0, 'service': service_environment.service_id, 'env': 111, }] }] }, format='json' )
def test_save_extra_cost_when_there_is_bad_env(self): extra_cost_type = factory.ExtraCostTypeFactory() service_environment = factory.ServiceEnvironmentFactory() self.client.post( '/scrooge/rest/allocationadmin/{0}/{1}/extracosts/save'.format( self.date.year, self.date.month, ), { 'rows': [{ 'extra_cost_type': { 'id': extra_cost_type.id, 'name': extra_cost_type.name }, 'extra_costs': [{ 'cost': 0.0, 'forecast_cost': 0.0, 'service': service_environment.service_id, 'env': False, }] }] }, format='json' ) self.assertEquals(models.ExtraCost.objects.count(), 0)
def test_get_extra_cost_when_there_is_one_additional_type(self): extra_cost_type = factory.ExtraCostTypeFactory() response = self.client.get( '/scrooge/rest/allocationadmin/{0}/{1}/'.format( self.date.year, self.date.month, ) ) self.assertEquals( json.loads(response.content)['extracosts'], { 'name': 'Extra Costs', 'rows': [{ 'extra_cost_type': { 'id': 1, 'name': 'Other' }, 'extra_costs': [{}] }, { 'extra_cost_type': { 'id': 2, 'name': 'Support' }, 'extra_costs': [{}] }, { 'extra_cost_type': { 'id': extra_cost_type.id, 'name': extra_cost_type.name }, 'extra_costs': [{}] }], 'template': 'tabextracostsadmin.html' } )
def test_get_extra_cost_when_there_is_one_additional_type_and_cost(self): cost = 100.0 forecast_cost = 200.0 first_day, last_day, days_in_month = get_dates( self.date.year, self.date.month, ) extra_cost_type = factory.ExtraCostTypeFactory() service_environment = factory.ServiceEnvironmentFactory() extra_cost = factory.ExtraCostFactory( extra_cost_type=extra_cost_type, start=first_day, end=last_day, cost=cost, forecast_cost=forecast_cost, service_environment=service_environment, ) response = self.client.get( '/scrooge/rest/allocationadmin/{0}/{1}/'.format( self.date.year, self.date.month, ) ) self.assertEquals( json.loads(response.content)['extracosts'], { 'name': 'Extra Costs', 'rows': [{ 'extra_cost_type': { 'id': 1, 'name': 'Other' }, 'extra_costs': [{}] }, { 'extra_cost_type': { 'id': 2, 'name': 'Support' }, 'extra_costs': [{}] }, { 'extra_cost_type': { 'id': extra_cost_type.id, 'name': extra_cost_type.name }, 'extra_costs': [{ 'id': extra_cost.id, 'cost': extra_cost.cost, 'forecast_cost': extra_cost.forecast_cost, 'service': extra_cost.service_environment.service_id, 'env': extra_cost.service_environment.environment_id }] }], 'template': 'tabextracostsadmin.html' } )
def test_update_extra_cost_when_everything_is_ok(self): cost = 100.0 forecast_cost = 200.0 first_day, last_day, days_in_month = get_dates( self.date.year, self.date.month, ) extra_cost_type = factory.ExtraCostTypeFactory() service_environment = factory.ServiceEnvironmentFactory() extra_cost = models.ExtraCost.objects.create( cost=50.0, forecast_cost=50.0, service_environment=service_environment, extra_cost_type=extra_cost_type, start=first_day, end=last_day, ) self.client.post( '/scrooge/rest/allocationadmin/{0}/{1}/extracosts/save'.format( self.date.year, self.date.month, ), { 'rows': [{ 'extra_cost_type': { 'id': extra_cost_type.id, 'name': extra_cost_type.name }, 'extra_costs': [{ 'id': extra_cost.id, 'cost': cost, 'forecast_cost': forecast_cost, 'service': service_environment.service_id, 'env': service_environment.environment_id, }] }] }, format='json' ) extra_cost = models.ExtraCost.objects.all()[0] self.assertEquals(extra_cost.cost, cost) self.assertEquals(extra_cost.forecast_cost, forecast_cost)