本文整理汇总了Python中tracim.model.DBSession.query方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.query方法的具体用法?Python DBSession.query怎么用?Python DBSession.query使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tracim.model.DBSession
的用法示例。
在下文中一共展示了DBSession.query方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_unit__rename_content__ok
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_unit__rename_content__ok(self):
provider = self._get_provider()
environ = self._get_environ(
provider,
'[email protected]',
)
w1f1d1 = provider.getResourceInst(
'/w1/w1f1/w1f1d1.txt',
environ,
)
content_w1f1d1 = DBSession.query(ContentRevisionRO) \
.filter(Content.label == 'w1f1d1') \
.one() # It must exist only one revision, cf fixtures
ok_(content_w1f1d1, msg='w1f1d1 should be exist')
content_w1f1d1_id = content_w1f1d1.content_id
w1f1d1.moveRecursive('/w1/w1f1/w1f1d1_RENAMED.txt')
# Database content is renamed
content_w1f1d1 = DBSession.query(ContentRevisionRO) \
.filter(ContentRevisionRO.content_id == content_w1f1d1_id) \
.order_by(ContentRevisionRO.revision_id.desc()) \
.first()
eq_(
'w1f1d1_RENAMED',
content_w1f1d1.label,
msg='File should be labeled w1f1d1_RENAMED, not {0}'.format(
content_w1f1d1.label
)
)
示例2: test_create_user
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_create_user(self):
self._connect_user(
'[email protected]',
'[email protected]',
)
user_count = DBSession.query(User) \
.filter(User.email == '[email protected]').count()
eq_(0, user_count, 'User should not exist yet')
# Create a new user
try_post_user = self.app.post(
'/admin/users',
OrderedDict([
('name', 'TEST'),
('email', '[email protected]'),
('password', 'password'),
('is_tracim_manager', 'off'),
('is_tracim_admin', 'off'),
('send_email', 'off'),
])
)
eq_(try_post_user.status_code, 302,
"Code should be 302, but is %d" % try_post_user.status_code)
user = DBSession.query(User) \
.filter(User.email == '[email protected]').one()
ok_(user, msg="User should exist now")
ok_(user.validate_password('password'))
# User must have webdav digest
ok_(user.webdav_left_digest_response_hash)
示例3: test_update_password
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_update_password(self):
self._connect_user(
'[email protected]',
'foobarbaz',
)
user = DBSession.query(User) \
.filter(User.email == '[email protected]').one()
webdav_digest = user.webdav_left_digest_response_hash
try_post_user = self.app.post(
'/user/{user_id}/password?_method=PUT'.format(
user_id=user.user_id
),
OrderedDict([
('current_password', 'foobarbaz'),
('new_password1', 'new-password'),
('new_password2', 'new-password'),
])
)
eq_(try_post_user.status_code, 302,
"Code should be 302, but is %d" % try_post_user.status_code)
user = DBSession.query(User) \
.filter(User.email == '[email protected]').one()
ok_(user.validate_password('new-password'))
ok_(
webdav_digest != user.webdav_left_digest_response_hash,
msg='Webdav digest should be updated',
)
示例4: test_ldap_auth_sync
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_ldap_auth_sync(self):
# User is unknown in tracim database
eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())
self._connect_user('[email protected]', 'rms')
# User is registered in tracim database
eq_(1, DBSession.query(User).filter(User.email == '[email protected]').count())
示例5: _base_query
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def _base_query(self):
if self._user.profile.id>=Group.TIM_ADMIN:
return DBSession.query(Workspace).filter(Workspace.is_deleted==False)
return DBSession.query(Workspace).\
join(Workspace.roles).\
filter(UserRoleInWorkspace.user_id==self._user.user_id).\
filter(Workspace.is_deleted==False)
示例6: _get_content_by_label
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def _get_content_by_label(self, label: str) -> Content:
revision = DBSession.query(ContentRevisionRO) \
.filter(ContentRevisionRO.label == label) \
.one()
return DBSession.query(Content) \
.filter(Content.id == revision.content_id) \
.one()
示例7: test_ldap_auth_fail_no_account
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_ldap_auth_fail_no_account(self):
# User is unknown in tracim database
eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())
self._connect_user('[email protected]', 'no-pass')
# User is registered in tracim database
eq_(0, DBSession.query(User).filter(User.email == '[email protected]').count())
示例8: test_create_with_group
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_create_with_group(self):
more_args = ['--add-to-group', 'managers', '--add-to-group', 'administrators']
self._create_user('[email protected]', 'toor', more_args=more_args)
user = DBSession.query(User).filter(User.email == '[email protected]').one()
group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()
ok_(user in group_managers.users)
ok_(user in group_administrators.users)
示例9: _create_workspace_and_test
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def _create_workspace_and_test(self, name, user) -> Workspace:
"""
All extra parameters (*args, **kwargs) are for Workspace init
:return: Created workspace instance
"""
WorkspaceApi(user).create_workspace(name, save_now=True)
eq_(1, DBSession.query(Workspace).filter(Workspace.label == name).count())
return DBSession.query(Workspace).filter(Workspace.label == name).one()
示例10: test_change_groups
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_change_groups(self):
# create an user in managers group
more_args = ['--add-to-group', 'managers']
self._create_user('[email protected]', 'toor', more_args=more_args)
user = DBSession.query(User).filter(User.email == '[email protected]').one()
group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()
ok_(user in group_managers.users)
ok_(user not in group_administrators.users)
# Update him and add to administrators group
add_to_admins_argvs = ['-l', '[email protected]', '--add-to-group', 'administrators']
self._execute_command(UpdateUserCommand, 'gearbox user update', add_to_admins_argvs)
user = DBSession.query(User).filter(User.email == '[email protected]').one()
group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()
ok_(user in group_managers.users)
ok_(user in group_administrators.users)
# remove him from administrators group
remove_from_admins_argvs = ['-l', '[email protected]', '--remove-from-group', 'administrators']
self._execute_command(UpdateUserCommand, 'gearbox user update', remove_from_admins_argvs)
user = DBSession.query(User).filter(User.email == '[email protected]').one()
group_managers = DBSession.query(Group).filter(Group.group_name == 'managers').one()
group_administrators = DBSession.query(Group).filter(Group.group_name == 'administrators').one()
ok_(user in group_managers.users)
ok_(user not in group_administrators.users)
示例11: test_update
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_update(self):
created_content = self.test_create()
content = DBSession.query(Content).filter(Content.id == created_content.id).one()
eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
with new_revision(content):
time.sleep(0.00001)
content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED'
DBSession.flush()
eq_(2, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1').count())
eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
with new_revision(content):
time.sleep(0.00001)
content.description = 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2'
content.label = 'TEST_CONTENT_1_UPDATED_2'
DBSession.flush()
eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_1_UPDATED_2').count())
eq_(1, DBSession.query(Content).filter(Content.id == created_content.id).count())
revision_1 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1').one()
revision_2 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED').one()
revision_3 = DBSession.query(ContentRevisionRO)\
.filter(ContentRevisionRO.description == 'TEST_CONTENT_DESCRIPTION_1_UPDATED_2').one()
# Updated dates must be different
ok_(revision_1.updated < revision_2.updated < revision_3.updated)
# Created dates must be equal
ok_(revision_1.created == revision_2.created == revision_3.created)
示例12: test_children
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_children(self):
admin = DBSession.query(User).filter(User.email == '[email protected]').one()
self._create_thread_and_test(
workspace_name='workspace_1',
folder_name='folder_1',
thread_name='thread_1',
user=admin
)
workspace = DBSession.query(Workspace).filter(Workspace.label == 'workspace_1').one()
folder = ContentApi.get_canonical_query().filter(Content.label == 'folder_1').one()
eq_([folder, ], list(workspace.get_valid_children()))
示例13: test_created_workspace_radicale_calendar
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_created_workspace_radicale_calendar(self):
self._connect_user(
'[email protected]',
'[email protected]',
)
workspaces_count = DBSession.query(Workspace)\
.filter(Workspace.label == 'WTESTCAL').count()
eq_(0, workspaces_count, 'Workspace should not exist yet !')
radicale_workspaces_folder = '{0}/workspace'\
.format(config.get('radicale.server.filesystem.folder'))
eq_(
False,
os.path.isdir(radicale_workspaces_folder),
'Radicale workskpaces folder should not exist yet',
)
# Create a new workspace, his calendar should be created to
try_post_workspace = self.app.post(
'/admin/workspaces',
OrderedDict([
('name', 'WTESTCAL'),
('description', 'WTESTCALDESCR'),
('calendar_enabled', 'on'),
])
)
eq_(try_post_workspace.status_code, 302,
"Code should be 302, but is %d" % try_post_workspace.status_code)
workspaces_calendars = len([
name for name in os.listdir(radicale_workspaces_folder)
if name.endswith('.ics')
])
workspace = DBSession.query(Workspace) \
.filter(Workspace.label == 'WTESTCAL').one()
eq_(
1,
workspaces_calendars,
'Radicale workspace path should list 1 calendar',
)
workspace_calendar = '{0}/{1}.ics'.format(
radicale_workspaces_folder,
workspace.workspace_id,
)
workspace_calendar_exist = os.path.isfile(workspace_calendar)
eq_(
True,
workspace_calendar_exist,
'Workspace calendar should be created',
)
示例14: get_last_unread
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def get_last_unread(self, parent_id: int, content_type: str,
workspace: Workspace=None, limit=10) -> [Content]:
assert parent_id is None or isinstance(parent_id, int) # DYN_REMOVE
assert content_type is not None# DYN_REMOVE
assert isinstance(content_type, str) # DYN_REMOVE
read_revision_ids = DBSession.query(RevisionReadStatus.revision_id) \
.filter(RevisionReadStatus.user_id==self._user_id)
not_read_revisions = self._revisions_base_query(workspace) \
.filter(~ContentRevisionRO.revision_id.in_(read_revision_ids)) \
.subquery()
not_read_content_ids_query = DBSession.query(
distinct(not_read_revisions.c.content_id)
)
not_read_content_ids = list(map(
itemgetter(0),
not_read_content_ids_query,
))
not_read_contents = self._base_query(workspace) \
.filter(Content.content_id.in_(not_read_content_ids)) \
.order_by(desc(Content.updated))
if content_type != ContentType.Any:
not_read_contents = not_read_contents.filter(
Content.type==content_type)
else:
not_read_contents = not_read_contents.filter(
Content.type!=ContentType.Folder)
if parent_id:
not_read_contents = not_read_contents.filter(
Content.parent_id==parent_id)
result = []
for item in not_read_contents:
new_item = None
if ContentType.Comment == item.type:
new_item = item.parent
else:
new_item = item
# INFO - D.A. - 2015-05-20
# We do not want to show only one item if the last 10 items are
# comments about one thread for example
if new_item not in result:
result.append(new_item)
if len(result) >= limit:
break
return result
示例15: test_ldap_attributes_sync
# 需要导入模块: from tracim.model import DBSession [as 别名]
# 或者: from tracim.model.DBSession import query [as 别名]
def test_ldap_attributes_sync(self):
# User is already know in database
eq_(1, DBSession.query(User).filter(User.email == '[email protected]').count())
# His display name is Lawrence L.
lawrence = DBSession.query(User).filter(User.email == '[email protected]').one()
eq_('Lawrence L.', lawrence.display_name)
# After connexion with LDAP, his display_name is updated (see ldap fixtures)
self._connect_user('[email protected]', 'foobarbaz')
lawrence = DBSession.query(User).filter(User.email == '[email protected]').one()
eq_('Lawrence Lessig', lawrence.display_name)