def test_project_creation_associate_fails(self): self.mox.StubOutWithMock(projects, '_project_to_view') self.mox.StubOutWithMock(projects, '_quotaset_for_project') networks = self.fake_client_set.compute.networks tenants = self.fake_client_set.identity_admin.tenants tenant = doubles.make(self.mox, doubles.Tenant, name=self.name, id='PID', description=self.description) networks.get(self.net_id).AndReturn( doubles.make(self.mox, doubles.Network, label='NETLABEL', id=self.net_id, project_id=None)) tenants.create(self.name, self.description).AndReturn(tenant) networks.associate(self.net_id, tenant.id).AndRaise(osc_exc.BadRequest('failure')) tenant.delete() self.mox.ReplayAll() data = self.interact(expected_status_code=400) self.assertTrue(self.net_id in data.get('message'))
def test_create_existing_network(self): (name, vlan, cidr) = ('net-name', 3301, '10.0.0.0/24') self.fake_client_set.compute.networks.create( label=name, vlan_start=vlan, cidr=cidr)\ .AndRaise(osc_exc.BadRequest('fail')) self.mox.ReplayAll() post_params = {"name": name, "vlan": vlan, "cidr": cidr} self.post(post_params, expected_status_code=400)
def test_upload_bad(self): self.fake_client_set.compute.keypairs.create('TestKP', 'PUBLIC')\ .AndRaise(osc_exc.BadRequest('Keypair data is invalid')) self.mox.ReplayAll() data = self.interact({ 'name': 'TestKP', 'public-key': 'PUBLIC' }, expected_status_code=400) self.assertTrue('Keypair data' in data.get('message', ''))
def test_add_failure(self): compute = self.fake_client_set.compute tcs = mock_client_set(self.mox) compute.servers.get(self.server.id).AndReturn(self.server) compute.security_groups.get(self.sg_id).AndReturn(self.sg) ifwrs.client_set_for_tenant(self.server.tenant_id, fallback_to_api=True) \ .AndReturn(tcs) tcs.compute.servers.add_security_group(self.server, self.sg.name)\ .AndRaise(osc_exc.BadRequest('failure')) self.mox.ReplayAll() self.interact(expected_status_code=400)
def test_create_bad_user(self): client = self.fake_client_set (name, email, passw) = ('user-a', '*****@*****.**', 'bananas') client.identity_admin.users.list().AndReturn([self.user]) client.identity_admin.users.create( name=name, email=email, password=passw, enabled=True) \ .AndRaise(osc_exc.BadRequest('fail')) self.mox.ReplayAll() self._interact(expected_status_code=400, data={ "name": name, "email": email, "password": passw, "admin": False, })
def test_remove_failure(self): compute = self.fake_client_set.compute compute.servers.get(self.server.id).AndReturn(self.server) compute.security_groups._list( '/servers/%s/os-security-groups' % self.server.id, 'security_groups').AndReturn([self.sg]) ifwrs.assert_admin_or_project_user( u'FWPROJECT', eperm_status=404) ifwrs.client_set_for_tenant(u'FWPROJECT', fallback_to_api=True) \ .AndReturn(self.tcs) self.tcs.compute.servers.remove_security_group( self.server, self.sg.name) \ .AndRaise(osc_exc.BadRequest('failure')) self.mox.ReplayAll() self.interact(expected_status_code=400)