def create_links(self, limit1, usage1, limit2, usage2): link1 = factories.TestServiceProjectLinkFactory(project=self.project) link1.set_quota_limit('vcpu', limit1) link1.set_quota_usage('vcpu', usage1) link2 = factories.TestServiceProjectLinkFactory(project=self.project) link2.set_quota_limit('vcpu', limit2) link2.set_quota_usage('vcpu', usage2)
def test_service_project_link_alert_is_not_returned_when_its_scope_is_related_to_another_project( self): not_owned_alert = logging_factories.AlertFactory( scope=factories.TestServiceProjectLinkFactory()) spl = factories.TestServiceProjectLinkFactory(project=self.project) owned_alert = logging_factories.AlertFactory(scope=spl) result = self._make_aggregate_request('project', self.project.uuid.hex) self.assertTrue(result.filter(uuid=owned_alert.uuid).exists()) self.assertFalse(result.filter(uuid=not_owned_alert.uuid).exists())
def create_resource(self, customer, project): settings = factories.ServiceSettingsFactory(customer=customer) service = factories.TestServiceFactory(customer=customer, settings=settings) spl = factories.TestServiceProjectLinkFactory(service=service, project=project) resource = factories.TestNewInstanceFactory(service_project_link=spl) return resource
def setUp(self): self.customer = factories.CustomerFactory() self.settings = factories.ServiceSettingsFactory(shared=True) self.service = factories.TestServiceFactory(customer=self.customer, settings=self.settings) self.user1 = factories.UserFactory() self.project1 = factories.ProjectFactory(customer=self.customer) self.project1.add_user(self.user1, ProjectRole.ADMINISTRATOR) self.spl1 = factories.TestServiceProjectLinkFactory(service=self.service, project=self.project1) self.vm1 = factories.TestNewInstanceFactory(service_project_link=self.spl1) self.user2 = factories.UserFactory() self.project2 = factories.ProjectFactory(customer=self.customer) self.project2.add_user(self.user2, ProjectRole.ADMINISTRATOR) self.spl2 = factories.TestServiceProjectLinkFactory(service=self.service, project=self.project2) self.vm2 = factories.TestNewInstanceFactory(service_project_link=self.spl2) self.service_url = factories.TestServiceFactory.get_url(self.service)
def test_customer_and_project_service_project_link_quota_updated(self): self.assert_quota_usage('nc_service_project_link_count', 0) service = factories.TestServiceFactory(customer=self.customer) project1 = factories.ProjectFactory(customer=self.customer) factories.TestServiceProjectLinkFactory(service=service, project=project1) project2 = factories.ProjectFactory(customer=self.customer) factories.TestServiceProjectLinkFactory(service=service, project=project2) self.assertEqual(project1.quotas.get(name='nc_service_project_link_count').usage, 1) self.assertEqual(project2.quotas.get(name='nc_service_project_link_count').usage, 1) self.assert_quota_usage('nc_service_project_link_count', 2) self.assert_quota_usage('nc_service_count', 1) project2.delete() project1.delete() self.assert_quota_usage('nc_service_count', 1) self.assert_quota_usage('nc_service_project_link_count', 0)
def test_if_limit_is_reached_provisioning_is_delayed(self, params): link = factories.TestServiceProjectLinkFactory() factories.TestNewInstanceFactory.create_batch( size=params['size'], state=models.TestNewInstance.States.CREATING, service_project_link=link) vm = factories.TestNewInstanceFactory( state=models.TestNewInstance.States.CREATION_SCHEDULED, service_project_link=link) serialized_vm = utils.serialize_instance(vm) mocked_retry = Mock() tasks.ThrottleProvisionTask.retry = mocked_retry tasks.ThrottleProvisionTask().si( serialized_vm, 'create', state_transition='begin_starting').apply() self.assertEqual(mocked_retry.called, params['retried'])
def test_price_estimate_scope_cannot_be_updated(self): other_service_project_link = structure_factories.TestServiceProjectLinkFactory( project=self.project) self.valid_data[ 'scope'] = structure_factories.TestServiceProjectLinkFactory.get_url( other_service_project_link) self.client.force_authenticate(self.users['staff']) response = self.client.patch(factories.PriceEstimateFactory.get_url( self.price_estimate), data=self.valid_data) self.assertEqual(response.status_code, status.HTTP_405_METHOD_NOT_ALLOWED) reread_price_estimate = models.PriceEstimate.objects.get( id=self.price_estimate.id) self.assertNotEqual(reread_price_estimate.scope, other_service_project_link)
def test_only_alerts_where_scopes_customer_is_the_aggregated_one_are_returned( self): customer_related_alerts = [] logging_factories.AlertFactory(scope=factories.ProjectFactory()) spl = factories.TestServiceProjectLinkFactory( service__customer=self.customer) customer_related_alerts.append( logging_factories.AlertFactory(scope=spl)) service = factories.TestServiceFactory(customer=self.customer) customer_related_alerts.append( logging_factories.AlertFactory(scope=service)) expected_alerts_ids = [alert.uuid for alert in customer_related_alerts] result = self._make_aggregate_request('customer', self.customer.uuid.hex) actual_alerts_ids = [alert.uuid for alert in result] self.assertItemsEqual(expected_alerts_ids, actual_alerts_ids)
def test_when_virtual_machine_is_deleted_descendant_resources_unlinked( self): # Arrange vm = factories.TestNewInstanceFactory() settings = factories.ServiceSettingsFactory(scope=vm) service = factories.TestServiceFactory(settings=settings) link = factories.TestServiceProjectLinkFactory(service=service) child_vm = factories.TestNewInstanceFactory(service_project_link=link) other_vm = factories.TestNewInstanceFactory() # Act vm.delete() # Assert self.assertFalse( test_models.TestNewInstance.objects.filter( id=child_vm.id).exists()) self.assertFalse( test_models.TestService.objects.filter(id=service.id).exists()) self.assertFalse( ServiceSettings.objects.filter(id=settings.id).exists()) self.assertTrue( test_models.TestNewInstance.objects.filter( id=other_vm.id).exists())
def setUp(self): self.user = factories.UserFactory(is_staff=True) self.client.force_authenticate(user=self.user) self.service_project_link = factories.TestServiceProjectLinkFactory()
def setUp(self): self.link = factories.TestServiceProjectLinkFactory()