def test_bulk_delete_instance(self): """Test bulk deleting list of instances.""" self.impl.bulk_delete.return_value = None resp = self.client.post( '/instance/_bulk/delete', data=json.dumps({ 'instances': ['proid.app#0000000001', 'proid.app#0000000002'] }), content_type='application/json') self.assertEqual(resp.status_code, http_client.OK) self.assertEqual(self.impl.bulk_delete.call_args_list, [ mock.call(['proid.app#0000000001', 'proid.app#0000000002'], None), ]) self.impl.reset_mock() with user_set(self.app, '*****@*****.**'): resp = self.client.post( '/instance/_bulk/delete', data=json.dumps({ 'instances': ['proid.app#0000000001', 'proid.app#0000000002'] }), content_type='application/json') self.assertEqual(resp.status_code, http_client.OK) self.assertEqual(self.impl.bulk_delete.call_args_list, [ mock.call(['proid.app#0000000001', 'proid.app#0000000002'], '*****@*****.**'), ])
def test_delete_instance(self): """Test deleting an instance.""" self.impl.delete.return_value = None resp = self.client.delete('/instance/proid.app#0000000001') self.assertEqual(resp.status_code, http_client.OK) self.impl.delete.assert_called_once_with('proid.app#0000000001', None) self.impl.reset_mock() with user_set(self.app, '*****@*****.**'): resp = self.client.delete('/instance/proid.app#0000000001') self.assertEqual(resp.status_code, http_client.OK) self.impl.delete.assert_called_once_with('proid.app#0000000001', '*****@*****.**')
def test_post_instance(self): """Test creating an instance.""" self.impl.create.return_value = ['proid.app#0000000001'] rsrc = { 'services': [{ 'command': '/bin/sleep 60', 'name': 'sleep', 'restart': { 'interval': 60, 'limit': 0 } }], 'cpu': '10%', 'memory': '100M', 'disk': '100M' } resp = self.client.post('/instance/proid.app', data=json.dumps(rsrc), content_type='application/json') resp_json = b''.join(resp.response) self.assertEqual(json.loads(resp_json.decode()), {'instances': ['proid.app#0000000001']}) self.assertEqual(resp.status_code, http_client.OK) self.impl.create.assert_called_once_with('proid.app', rsrc, 1, None) self.impl.reset_mock() with user_set(self.app, '*****@*****.**'): resp = self.client.post('/instance/proid.app?count=2', data=json.dumps(rsrc), content_type='application/json') self.assertEqual(resp.status_code, http_client.OK) self.impl.create.assert_called_once_with('proid.app', rsrc, 2, '*****@*****.**') self.impl.create.side_effect = exc.InvalidInputError('foo', 'bar') resp = self.client.post('/instance/[email protected]', data=json.dumps(rsrc), content_type='application/json') self.assertEqual(resp.status_code, http_client.BAD_REQUEST)