def test_create_tenant(self): ttl_create_index_call = MagicMock() with patch('meniscus.data.model.tenant_util._db_handler', self.ds_handler), patch( 'meniscus.data.model.tenant_util.ttl_tasks.create_index.delay', ttl_create_index_call): tenant_util.create_tenant(self.tenant_id) self.ds_handler.put.assert_called_once() self.ds_handler.create_sequence.assert_called_once_with( self.tenant_id) ttl_create_index_call.assert_called_once_with(self.tenant_id)
def test_create_tenant(self): ttl_create_index_call = MagicMock() with patch('meniscus.data.model.tenant_util._db_handler', self.ds_handler), patch( 'meniscus.data.model.tenant_util.' 'mapping_tasks.create_index.delay', ttl_create_index_call): tenant_util.create_tenant(self.tenant_id) self.ds_handler.put.assert_called_once() self.ds_handler.create_sequence.assert_called_once_with( self.tenant_id) ttl_create_index_call.assert_called_once_with(self.tenant_id)
def on_post(self, req, resp, validated_body): """ Create a new tenant when a HTTP POST is received """ body = validated_body['tenant'] tenant_id = str(body['tenant_id']) tenant_name = body.get('tenant_name', tenant_id) #validate that tenant does not already exists tenant = tenant_util.find_tenant(tenant_id=tenant_id) if tenant: api.abort(falcon.HTTP_400, 'Tenant with tenant_id {0} ' 'already exists'.format(tenant_id)) tenant_util.create_tenant(tenant_id=tenant_id, tenant_name=tenant_name) resp.status = falcon.HTTP_201 resp.set_header('Location', '/v1/{0}'.format(tenant_id))
def on_post(self, req, resp, validated_body): """ Create a new tenant when a HTTP POST is received """ body = validated_body['tenant'] tenant_id = str(body['tenant_id']) tenant_name = body.get('tenant_name', tenant_id) #validate that tenant does not already exists tenant = tenant_util.find_tenant(tenant_id=tenant_id) if tenant: api.abort( falcon.HTTP_400, 'Tenant with tenant_id {0} ' 'already exists'.format(tenant_id)) tenant_util.create_tenant(tenant_id=tenant_id, tenant_name=tenant_name) resp.status = falcon.HTTP_201 resp.set_header('Location', '/v1/{0}'.format(tenant_id))