def test_package_creation_does_not_increase_price_for_cheaper_1_day_long_old_package_in_the_same_day( self): old_component_price = 10 new_component_price = old_component_price + 5 start_date = timezone.datetime(2014, 2, 26, tzinfo=pytz.UTC) package_change_date = start_date end_of_the_month = core_utils.month_end(package_change_date) with freeze_time(start_date): old_package = invoices_fixtures.create_package( component_price=old_component_price) customer = old_package.tenant.service_project_link.project.customer with freeze_time(package_change_date): old_package.delete() new_template = invoices_fixtures.create_package_template( component_price=new_component_price) new_package = packages_factories.OpenStackPackageFactory( template=new_template, tenant__service_project_link__project__customer=customer, ) old_components_price = old_package.template.price * ( package_change_date - start_date).days second_component_usage_days = invoices_utils.get_full_days( package_change_date, end_of_the_month) new_components_price = new_package.template.price * second_component_usage_days expected_price = old_components_price + new_components_price # assert self.assertEqual(invoices_models.Invoice.objects.count(), 1) self.assertEqual(Decimal(expected_price), invoices_models.Invoice.objects.first().price)
def test_package_creation_increases_price_from_old_package_if_it_is_more_expensive_in_the_end_of_the_month( self): old_component_price = 15 new_component_price = old_component_price - 5 start_date = timezone.datetime(2014, 2, 20, tzinfo=pytz.UTC) package_change_date = timezone.datetime(2014, 2, 27, tzinfo=pytz.UTC) end_of_the_month = core_utils.month_end(package_change_date) with freeze_time(start_date): old_package = invoices_fixtures.create_package( component_price=old_component_price) tenant = old_package.tenant with freeze_time(package_change_date): old_package.delete() new_template = invoices_fixtures.create_package_template( component_price=new_component_price) new_package = packages_factories.OpenStackPackageFactory( template=new_template, tenant=tenant, ) old_components_price = old_package.template.price * ( (package_change_date - start_date).days + 1) second_component_usage_days = invoices_utils.get_full_days( package_change_date, end_of_the_month) - 1 new_components_price = new_package.template.price * second_component_usage_days expected_price = old_components_price + new_components_price # assert self.assertEqual(invoices_models.Invoice.objects.count(), 1) self.assertEqual(Decimal(expected_price), invoices_models.Invoice.objects.first().price)