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 test_service_alert_is_returned_when_aggregate_customer_is_the_same_as_its_scope_customer( self): scope = factories.TestServiceFactory(customer=self.customer) alert = logging_factories.AlertFactory(scope=scope) result = self._make_aggregate_request('customer', self.customer.uuid.hex) self.assertEqual(len(result), 1) self.assertTrue(result.filter(uuid=alert.uuid).exists())
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 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_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 test_customer_services_quota_decreases_on_service_deletion(self): service = factories.TestServiceFactory(customer=self.customer) service.delete() self.assert_quota_usage('nc_service_count', 0)
def test_customer_services_quota_increases_on_service_creation(self): factories.TestServiceFactory(customer=self.customer) self.assert_quota_usage('nc_service_count', 1)