#!/usr/bin/env python
# -*- coding: utf-8 -*-
# === sqlalchemy_tree.tests -----------------------------------------------===
# Copyright © 2011-2012, RokuSigma Inc. and contributors. See AUTHORS for more
# details.
#
# Some rights reserved.
#
# Redistribution and use in source and binary forms of the software as well as
# documentation, with or without modification, are permitted provided that the
# following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * The names of the copyright holders or contributors may not be used to
# endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE COPYRIGHT HOLDERS AND
# CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
# PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE AND
# DOCUMENTATION, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ===----------------------------------------------------------------------===
# ===----------------------------------------------------------------------===
# This file is based on two BSD-licensed open source projects, SQLAMP and
# Django MPTT. The copyright of the original code is held by its respective
# authors, and the license for each is included below. The work of merging
# these two projects and the continuing work that goes into improvements and
# bug fixes is under copyright held by RokuSigma Inc. and other contributors,
# and distributed under the terms of the three-clause BSD license as described
# above. ALL THREE LICENSE APPLY TO THIS WORK AND ALL AND DERIVED WORKS.
# ===----------------------------------------------------------------------===
# ===----------------------------------------------------------------------===
# SQLAMP
#
# Copyright 2009 Anton Gritsay <anton@angri.ru>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# ===----------------------------------------------------------------------===
# ===----------------------------------------------------------------------===
# Django MPTT
#
# Copyright (c) 2007, Jonathan Buchanan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of
# this software and associated documentation files (the "Software"), to deal in
# the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
# the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# ===----------------------------------------------------------------------===
# Python standard library unit tests
from unittest2 import TestCase
# SQLAlchemy object-relational mapper
from sqlalchemy import *
from sqlalchemy.orm import mapper, relationship, backref, sessionmaker
# SQLAlchemy tree extension
from sqlalchemy_tree import *
# ===----------------------------------------------------------------------===
class _Database(object):
def __init__(self):
self.engine = create_engine('sqlite:///:memory:')
self.metadata = MetaData(self.engine)
self.Session = sessionmaker(bind=self.engine)
db = _Database()
# ===----------------------------------------------------------------------===
class Named(object):
def __init__(self, *args, **kwargs):
name = kwargs.pop('name', None)
parent = kwargs.pop('parent', None)
super(Named, self).__init__(*args, **kwargs)
self.name = name
self.parent = parent
def __unicode__(self):
return self.name
named = Table('sqlalchemy_tree__tests__named', db.metadata,
# Primary-key:
Column('id', Integer,
Sequence('sqlalchemy_tree__tests__named__id_seq'),
primary_key = True),
# Unicode identifier:
Column('name', Unicode,
nullable = False,
unique = True),
# Adjacency-list link:
Column('parent_id', Integer,
ForeignKey('sqlalchemy_tree__tests__named.id')),
)
Named.tree = TreeManager(named)
mapper(Named, named, properties={
'parent': relationship(Named,
backref = backref('children', lazy='dynamic'),
remote_side = named.c.id),
})
Named.tree.register()
# ===----------------------------------------------------------------------===
def get_tree_details():
""
options = Named.tree._tree_options
def _get_subtree(parent):
if parent is None:
children = db.session.query(Named) \
.filter(Named.tree.filter_root_nodes()) \
.order_by(options.tree_id_field) \
.all()
else:
children = db.session.query(Named) \
.filter(parent.tree.filter_children()) \
.order_by(options.left_field) \
.all()
return [(n.name, {'id': getattr(n, options.tree_id_field.name),
'left': getattr(n, options.left_field.name),
'right':getattr(n, options.right_field.name),
'depth':getattr(n, options.depth_field.name)},
_get_subtree(n))
for n in children]
return _get_subtree(None)
class TreeTestMixin(object):
"Provides a framework for testing tree structures using the `named` table."
def _fill_tree(self):
def _create_node(name, fields, parent=None):
node = Named(name=name)
Nam
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
共22个文件
py:21个
pkg-info:1个
资源分类:Python库 所属语言:Python 资源全名:SQLAlchemy-ORM-tree-0.0.7.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059
资源推荐
资源详情
资源评论
收起资源包目录
SQLAlchemy-ORM-tree-0.0.7.tar.gz (22个子文件)
SQLAlchemy-ORM-tree-0.0.7
PKG-INFO 862B
._setup.py 187B
sqlalchemy_tree
options.py 13KB
.___init__.py 187B
manager
unmapped.py 12KB
.___init__.py 184B
class_.py 12KB
__init__.py 5KB
._class_.py 188B
._instance.py 188B
._unmapped.py 184B
instance.py 17KB
types.py 6KB
tests
.___init__.py 189B
__init__.py 113KB
__init__.py 5KB
orm.py 44KB
._orm.py 187B
._types.py 187B
._exceptions.py 187B
exceptions.py 6KB
setup.py 4KB
共 22 条
- 1
资源评论
挣扎的蓝藻
- 粉丝: 12w+
- 资源: 15万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功