def test_project_deletion_with_servers_fails(self):
        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(True)

        self.mox.ReplayAll()
        data = self.interact(expected_status_code=400)
        self.assertTrue('instances in it' in data.get('message'))
    def test_project_deletion_with_servers_fails(self):
        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(True)

        self.mox.ReplayAll()
        data = self.interact(expected_status_code=400)
        self.assertTrue('instances in it' in data.get('message'))
    def test_project_deletion_late_not_found(self):
        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(False)
        projects._project_has_images(self.tenant_id).AndReturn(False)
        self.fake_client_set.compute.networks.list().AndReturn([])

        self.tenant.delete().AndRaise(osc_exc.NotFound('deleted'))

        self.mox.ReplayAll()
        self.interact(expected_status_code=204)
    def test_project_deletion_late_not_found(self):
        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(False)
        projects._project_has_images(self.tenant_id).AndReturn(False)
        self.fake_client_set.compute.networks.list().AndReturn([])

        self.tenant.delete().AndRaise(osc_exc.NotFound('deleted'))

        self.mox.ReplayAll()
        self.interact(expected_status_code=204)
 def test_project_has_servers(self):
     self.fake_client_set.compute.servers.list(
         detailed=False,
         search_opts=dict(all_tenants=1,
                          tenant_id='PID',
                          limit=1)) \
             .AndReturn(['SERVER'])
     self.mox.ReplayAll()
     with self.app.test_request_context():
         self.install_fake_auth()
         self.assertTrue(projects._project_has_servers('PID'))
 def test_project_has_servers(self):
     self.fake_client_set.compute.servers.list(
         detailed=False,
         search_opts=dict(all_tenants=1,
                          tenant_id='PID',
                          limit=1)) \
             .AndReturn(['SERVER'])
     self.mox.ReplayAll()
     with self.app.test_request_context():
         self.install_fake_auth()
         self.assertTrue(projects._project_has_servers('PID'))
    def test_project_deletion_with_networks(self):
        def _net(**kwargs):
            return doubles.make(self.mox, doubles.Network, **kwargs)

        nets = [_net(id='n1', project_id=self.tenant_id),
                _net(id='n2', project_id=u'other'),
                _net(id='n3', project_id=self.tenant_id)]

        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(False)
        projects._project_has_images(self.tenant_id).AndReturn(False)

        self.fake_client_set.compute.networks.list().AndReturn(nets)
        self.fake_client_set.compute.networks.disassociate(nets[0])
        self.fake_client_set.compute.networks.disassociate(nets[2])

        self.tenant.delete()

        self.mox.ReplayAll()
        self.interact(expected_status_code=204)
    def test_project_deletion_with_networks(self):
        def _net(**kwargs):
            return doubles.make(self.mox, doubles.Network, **kwargs)

        nets = [
            _net(id='n1', project_id=self.tenant_id),
            _net(id='n2', project_id=u'other'),
            _net(id='n3', project_id=self.tenant_id)
        ]

        self.fake_client_set.identity_admin \
            .tenants.get(self.tenant_id).AndReturn(self.tenant)
        projects._project_has_servers(self.tenant_id).AndReturn(False)
        projects._project_has_images(self.tenant_id).AndReturn(False)

        self.fake_client_set.compute.networks.list().AndReturn(nets)
        self.fake_client_set.compute.networks.disassociate(nets[0])
        self.fake_client_set.compute.networks.disassociate(nets[2])

        self.tenant.delete()

        self.mox.ReplayAll()
        self.interact(expected_status_code=204)