本文整理汇总了Python中tracim.model.DBSession类的典型用法代码示例。如果您正苦于以下问题:Python DBSession类的具体用法?Python DBSession怎么用?Python DBSession使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DBSession类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete
def delete(self, token):
"""Delete lock.
Returns True on success. False, if token does not exist, or is expired.
"""
self._lock.acquireWrite()
try:
lock_db = self.__base_query().filter(Lock.token == token).one_or_none()
_logger.debug("delete %s" % lockString(from_base_to_dict(lock_db)))
if lock_db is None:
return False
# Remove url to lock mapping
url2token = DBSession.query(Url2Token).filter(
Url2Token.path == lock_db.root,
Url2Token.token == token).one_or_none()
if url2token is not None:
DBSession.delete(url2token)
# Remove the lock
DBSession.delete(lock_db)
transaction.commit()
self._flush()
finally:
self._lock.release()
return True
示例2: test_create_user
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_new_revision
def test_new_revision(self):
admin = DBSession.query(User).filter(User.email == '[email protected]').one()
workspace = self._create_workspace_and_test(name='workspace_1', user=admin)
folder = self._create_content_and_test(name='folder_1', workspace=workspace, type=ContentType.Folder)
page = self._create_content_and_test(
workspace=workspace,
parent=folder,
name='file_1',
description='content of file_1',
type=ContentType.Page,
owner=admin
)
DBSession.flush()
# Model create a new instance with list of column
new_revision_by_model = ContentRevisionRO.new_from(page.revision)
# Test create a new instance from dynamic listing of model columns mapping
new_revision_by_test = self._new_from(page.revision)
new_revision_by_model_dict = self._get_dict_representation(new_revision_by_model)
new_revision_by_test_dict = self._get_dict_representation(new_revision_by_test)
# They must be identical
eq_(new_revision_by_model_dict, new_revision_by_test_dict)
示例4: test_create
def test_create(self, key='1'):
eq_(0, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())
eq_(0, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())
user_admin = DBSession.query(User).filter(User.email == '[email protected]').one()
workspace = Workspace(label="TEST_WORKSPACE_%s" % key)
DBSession.add(workspace)
DBSession.flush()
eq_(1, DBSession.query(Workspace).filter(Workspace.label == 'TEST_WORKSPACE_%s' % key).count())
created_content = self._create_content(
owner=user_admin,
workspace=workspace,
type=ContentType.Page,
label='TEST_CONTENT_%s' % key,
description='TEST_CONTENT_DESCRIPTION_%s' % key,
revision_type=ActionDescription.CREATION
)
eq_(1, DBSession.query(ContentRevisionRO).filter(ContentRevisionRO.label == 'TEST_CONTENT_%s' % key).count())
content = DBSession.query(Content).filter(Content.id == created_content.id).one()
eq_('TEST_CONTENT_%s' % key, content.label)
eq_('TEST_CONTENT_DESCRIPTION_%s' % key, content.description)
return created_content
示例5: ensure_calendar_exist
def ensure_calendar_exist(self, workspace: Workspace) -> None:
# Note: Cyclic imports
from tracim.lib.calendar import CalendarManager
from tracim.model.organisational import WorkspaceCalendar
calendar_manager = CalendarManager(self._user)
try:
calendar_manager.enable_calendar_file(
calendar_class=WorkspaceCalendar,
related_object_id=workspace.workspace_id,
raise_=True,
)
# If previous calendar file no exist, calendar must be created
except FileNotFoundError:
self._user.ensure_auth_token()
# Ensure database is up-to-date
DBSession.flush()
transaction.commit()
calendar_manager.create_then_remove_fake_event(
calendar_class=WorkspaceCalendar,
related_object_id=workspace.workspace_id,
)
示例6: test_unit__rename_content__ok
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
)
)
示例7: test_update_password
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',
)
示例8: test_func__rights_read_workspace_calendar__fail__as_unauthorized
def test_func__rights_read_workspace_calendar__fail__as_unauthorized(self):
lawrence = DBSession.query(User).filter(
User.email == '[email protected]'
).one()
workspace = WorkspaceApi(lawrence).create_workspace(
'workspace_1',
save_now=False
)
workspace.calendar_enabled = True
DBSession.flush()
workspace_calendar_url = CalendarManager.get_workspace_calendar_url(
workspace.workspace_id
)
transaction.commit()
radicale_base_url = CalendarManager.get_base_url()
client = caldav.DAVClient(
radicale_base_url,
username='[email protected]',
password='foobarbaz'
)
caldav.Calendar(
parent=client,
client=client,
url=workspace_calendar_url
).events()
示例9: create
def create(self, content_type: str, workspace: Workspace, parent: Content=None, label:str ='', do_save=False, is_temporary: bool=False) -> Content:
assert content_type in ContentType.allowed_types()
if content_type == ContentType.Folder and not label:
label = self.generate_folder_label(workspace, parent)
content = Content()
content.owner = self._user
content.parent = parent
content.workspace = workspace
content.type = content_type
content.label = label
content.is_temporary = is_temporary
content.revision_type = ActionDescription.CREATION
if content.type in (
ContentType.Page,
ContentType.Thread,
):
content.file_extension = '.html'
if do_save:
DBSession.add(content)
self.save(content, ActionDescription.CREATION)
return content
示例10: _load
def _load(self, fixture_class):
if fixture_class not in self._loaded:
fixture = fixture_class(DBSession)
fixture.insert()
self._loaded.append(fixture_class)
DBSession.flush()
transaction.commit()
示例11: _get_content_by_label
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()
示例12: tearDown
def tearDown(self):
"""Tear down test fixture for each functional test method."""
DBSession.close()
daemons.execute_in_thread('radicale', lambda: transaction.commit())
teardown_db()
transaction.commit()
DBSession.close_all()
config['tg.app_globals'].sa_engine.dispose()
示例13: restore_one
def restore_one(self, workspace_id, flush=True):
workspace = DBSession.query(Workspace).filter(Workspace.is_deleted==True).filter(Workspace.workspace_id==workspace_id).one()
workspace.is_deleted = False
if flush:
DBSession.flush()
return workspace
示例14: _base_query
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)
示例15: test_ldap_auth_sync
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())