本文整理汇总了Python中stalker.db.DBSession.commit方法的典型用法代码示例。如果您正苦于以下问题:Python DBSession.commit方法的具体用法?Python DBSession.commit怎么用?Python DBSession.commit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stalker.db.DBSession
的用法示例。
在下文中一共展示了DBSession.commit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_with_studio_is_working_properly
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_update_with_studio_is_working_properly(self):
"""testing if the default values are updated with the Studio instance
if there is a database connection and there is a Studio in there
"""
import datetime
from stalker import db, defaults
from stalker.db.session import DBSession
from stalker.models.studio import Studio
db.setup()
db.init()
# check the defaults are still using them self
self.assertEqual(
defaults.timing_resolution,
datetime.timedelta(hours=1)
)
studio = Studio(
name='Test Studio',
timing_resolution=datetime.timedelta(minutes=15)
)
DBSession.add(studio)
DBSession.commit()
# now check it again
self.assertEqual(
defaults.timing_resolution,
studio.timing_resolution
)
示例2: tearDown
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def tearDown(self):
"""clean up the test
"""
# clean up test database
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
DBSession.commit()
示例3: setUp
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def setUp(self):
"""set up
"""
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
DBSession.commit()
super(TaskJugglerScheduler_PostgreSQL_Tester, self).setUp()
示例4: test_deleting_time_log_for_a_task_with_status_complete
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_deleting_time_log_for_a_task_with_status_complete(self):
"""testing if it is not allowed to delete a time log of a task with
status completed
"""
# TODO: This is also testing some functionality from view.task, slit it
# create two new task
task0 = Task(
name='Test Task 0',
project=self.proj1,
status_list=self.task_status_list
)
task1 = Task(
name='Test Task 1',
parent=task0,
status_list=self.task_status_list,
resources=[self.user1]
)
task1.status = self.status_wip
DBSession.add_all([task0, task1])
DBSession.commit()
DBSession.flush()
transaction.commit()
self.assertEqual(task0.status, self.status_new)
self.assertEqual(task1.status, self.status_wip)
# now add a time log for task3 through create_time_log view
request = testing.DummyRequest()
# patch get_logged_in_user
admins = Group.query.filter(Group.name == 'admins').first()
self.user1.groups.append(admins)
m = mocker.Mocker()
obj = m.replace("stalker_pyramid.views.auth.get_logged_in_user")
obj(request)
m.result(self.user1)
m.count(1, 1000000000)
m.replay()
request.route_url = lambda x, id=1: 'view_user'
request.params['task_id'] = task1.id
request.params['resource_id'] = self.user1.id
request.params['start'] = "Fri, 19 Nov 2013 08:00:00 GMT"
request.params['end'] = "Fri, 19 Nov 2013 17:00:00 GMT"
response = time_log.create_time_log(request)
self.assertEqual(response.status_int, 200)
# set it to complete
task1.status = self.status_cmpl
# now try to remove it
request.matchdict['id'] = task1.time_logs[0].id
response = time_log.delete_time_log(request)
self.assertEqual(response.status_int, 500)
self.assertEqual(
response.body,
'Error: You can not delete a TimeLog of a Task with status CMPL'
)
示例5: tearDown
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def tearDown(self):
"""clean up the test
"""
# clean up test database
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
from sqlalchemy.exc import ProgrammingError
try:
DBSession.commit()
except ProgrammingError:
DBSession.rollback()
示例6: test_delete_will_delete_the_session_cache
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_delete_will_delete_the_session_cache(self):
"""testing if the LocalSession.delete() will delete the current cache
file
"""
# create a new user
new_user = User(
name='Test User',
login='test_user',
email='[email protected]',
password='secret'
)
# save it to the Database
DBSession.add(new_user)
DBSession.commit()
self.assertTrue(new_user.id is not None)
# save it to the local storage
local_session = LocalSession()
local_session.store_user(new_user)
# save the session
local_session.save()
# check if the file is created
# check if a file is created in the users local storage
self.assertTrue(
os.path.exists(
os.path.join(
defaults.local_storage_path,
defaults.local_session_data_file_name
)
)
)
# now delete the session by calling delete()
local_session.delete()
# check if the file is gone
# check if a file is created in the users local storage
self.assertFalse(
os.path.exists(
os.path.join(
defaults.local_storage_path,
defaults.local_session_data_file_name
)
)
)
# delete a second time
# this should not raise an OSError
local_session.delete()
示例7: setUpClass
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def setUpClass(cls):
"""setup tests in class level
"""
cls.config = {
'sqlalchemy.url':
'postgresql://stalker_admin:[email protected]/stalker_test',
'sqlalchemy.echo': False
}
# clean up test database
db.setup(cls.config)
from stalker.db.declarative import Base
Base.metadata.drop_all(db.DBSession.connection())
DBSession.commit()
示例8: test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_LocalSession_will_not_use_the_stored_data_if_it_is_invalid(self):
"""testing if the LocalSession will not use the stored session if it is
not valid anymore
"""
# create a new user
new_user = User(
name='Test User',
login='test_user',
email='[email protected]',
password='secret'
)
# save it to the Database
DBSession.add(new_user)
DBSession.commit()
self.assertTrue(new_user.id is not None)
# save it to the local storage
local_session = LocalSession()
local_session.store_user(new_user)
# save the session
local_session.save()
# set the valid time to an early date
local_session.valid_to = \
datetime.datetime.now() - datetime.timedelta(10)
# pickle the data
data = json.dumps(
{
'valid_to': local_session.valid_to,
'logged_in_user_id': -1
},
default=local_session.default_json_serializer
)
print('data: %s' % data)
local_session._write_data(data)
# now get it back with a new local_session
local_session2 = LocalSession()
self.assertEqual(
local_session2.logged_in_user_id, None
)
self.assertTrue(local_session2.logged_in_user is None)
示例9: test_logged_in_user_returns_the_stored_User_instance_from_last_time
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_logged_in_user_returns_the_stored_User_instance_from_last_time(self):
"""testing if logged_in_user returns the logged in user
"""
# create a new user
new_user = User(
name='Test User',
login='test_user',
email='[email protected]',
password='secret'
)
# save it to the Database
DBSession.add(new_user)
DBSession.commit()
self.assertIsNotNone(new_user.id)
# save it to the local storage
local_session = LocalSession()
local_session.store_user(new_user)
# save the session
local_session.save()
# now get it back with a new local_session
local_session2 = LocalSession()
self.assertEqual(
local_session2.logged_in_user_id,
new_user.id
)
self.assertEqual(
local_session2.logged_in_user,
new_user
)
示例10: test_get_version_from_full_path_with_multiple_repositories
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_get_version_from_full_path_with_multiple_repositories(self):
"""testing if the get version from full path is working fine with
multiple repositories and with same version names
"""
repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/")
DBSession.add(repo1)
repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/")
DBSession.add(repo2)
task_ft = FilenameTemplate(
name="Task Filename Template",
target_entity_type="Task",
path="$REPO{{project.repository.id}}/{{project.code}}/"
"{%- for parent_task in parent_tasks -%}"
"{{parent_task.nice_name}}/{%- endfor -%}",
filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}',
)
DBSession.add(task_ft)
structure1 = Structure(name="Commercial Project Structure", templates=[task_ft])
DBSession.add(structure1)
status1 = Status(name="Status 1", code="STS1")
status2 = Status(name="Status 2", code="STS2")
status3 = Status(name="Status 3", code="STS3")
DBSession.add_all([status1, status2, status3])
proj_status_list = StatusList(
name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3]
)
DBSession.add(proj_status_list)
task_status_list = StatusList(
name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3]
)
DBSession.add(task_status_list)
version_status_list = StatusList(
name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3]
)
DBSession.add(version_status_list)
project1 = Project(
name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list
)
DBSession.add(project1)
project2 = Project(
name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list
)
DBSession.add(project2)
task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list)
DBSession.add(task1)
task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list)
DBSession.add(task2)
DBSession.commit()
# now create versions
version1 = Version(task=task1, status_list=version_status_list)
DBSession.add(version1)
DBSession.commit()
version1.update_paths()
version2 = Version(task=task2, status_list=version_status_list)
DBSession.add(version2)
DBSession.commit()
version2.update_paths()
DBSession.commit()
logger.debug("version1.full_path : %s" % version1.full_path)
logger.debug("version2.full_path : %s" % version2.full_path)
# now try to get the versions with an EnvironmentBase instance
env = EnvironmentBase()
# version1
version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
self.assertEqual(version1_found, version1)
# version2
version2_found = env.get_version_from_full_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001")
self.assertEqual(version2_found, version2)
# version1 in windows
version1_found = env.get_version_from_full_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001")
self.assertEqual(version1_found, version1)
# version2 in windows
version2_found = env.get_version_from_full_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001")
self.assertEqual(version2_found, version2)
# version1 in linux
version1_found = env.get_version_from_full_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001")
self.assertEqual(version1_found, version1)
# version2 in linux
#.........这里部分代码省略.........
示例11: test_trim_repo_path_with_multiple_repositories
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_trim_repo_path_with_multiple_repositories(self):
"""testing if the trim_repo_path is working fine with multiple
repositories and with same version names
"""
repo0 = Repository(
name="Test Repo 0",
linux_path="/mnt/T/with_a_very_long_path_which_will_cause_errors/",
windows_path="T:/with_a_very_long_path_which_will_cause_errors/",
osx_path="/Volumes/T/" "with_a_very_long_path_which_will_cause_errors/",
)
DBSession.add(repo0)
repo1 = Repository(name="Test Repo 1", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/")
DBSession.add(repo1)
repo2 = Repository(name="Test Repo 2", linux_path="/mnt/S/", windows_path="S:/", osx_path="/Volumes/S/")
DBSession.add(repo2)
task_ft = FilenameTemplate(
name="Task Filename Template",
target_entity_type="Task",
path="{{project.code}}/{%- for parent_task in parent_tasks -%}" "{{parent_task.nice_name}}/{%- endfor -%}",
filename="{{task.nice_name}}_{{version.take_name}}" '_v{{"%03d"|format(version.version_number)}}',
)
DBSession.add(task_ft)
structure1 = Structure(name="Commercial Project Structure", templates=[task_ft])
DBSession.add(structure1)
status1 = Status(name="Status 1", code="STS1")
status2 = Status(name="Status 2", code="STS2")
status3 = Status(name="Status 3", code="STS3")
DBSession.add_all([status1, status2, status3])
proj_status_list = StatusList(
name="Project Statuses", target_entity_type="Project", statuses=[status1, status2, status3]
)
DBSession.add(proj_status_list)
task_status_list = StatusList(
name="Task Statuses", target_entity_type="Task", statuses=[status1, status2, status3]
)
DBSession.add(task_status_list)
version_status_list = StatusList(
name="Version Statuses", target_entity_type="Version", statuses=[status1, status2, status3]
)
DBSession.add(version_status_list)
project1 = Project(
name="Test Project 1", code="TP1", repositories=[repo1], structure=structure1, status_list=proj_status_list
)
DBSession.add(project1)
project2 = Project(
name="Test Project 2", code="TP2", repositories=[repo2], structure=structure1, status_list=proj_status_list
)
DBSession.add(project2)
task1 = Task(name="Test Task 1", code="TT1", project=project1, status_list=task_status_list)
DBSession.add(task1)
task2 = Task(name="Test Task 1", code="TT1", project=project2, status_list=task_status_list)
DBSession.add(task2)
DBSession.commit()
# now create versions
version1 = Version(task=task1, status_list=version_status_list)
DBSession.add(version1)
DBSession.commit()
version1.update_paths()
version2 = Version(task=task1, status_list=version_status_list)
DBSession.add(version2)
DBSession.commit()
version2.update_paths()
version3 = Version(task=task2, status_list=version_status_list)
DBSession.add(version3)
DBSession.commit()
version3.update_paths()
version4 = Version(task=task2, status_list=version_status_list)
DBSession.add(version4)
DBSession.commit()
version4.update_paths()
DBSession.commit()
logger.debug("version1.full_path : %s" % version1.full_path)
logger.debug("version2.full_path : %s" % version2.full_path)
logger.debug("version3.full_path : %s" % version2.full_path)
logger.debug("version4.full_path : %s" % version2.full_path)
# now try to get the versions with an EnvironmentBase instance
env = EnvironmentBase()
expected_value1 = "TP1/Test_Task_1/Test_Task_1_Main_v001"
expected_value2 = "TP2/Test_Task_1/Test_Task_1_Main_v001"
#.........这里部分代码省略.........
示例12: save_as
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def save_as(self, version):
"""the save action for houdini environment
"""
if not version:
return
from stalker import Version
assert isinstance(version, Version)
# get the current version, and store it as the parent of the new version
current_version = self.get_current_version()
# initialize path variables by using update_paths()
version.update_paths()
# set the extension to hip
if not hou.isApprentice():
version.extension = '.hip'
else:
version.extension = '.hipnc'
# define that this version is created with Houdini
version.created_with = self.name
# create the folder if it doesn't exists
try:
os.makedirs(
os.path.dirname(
version.absolute_full_path
)
)
except OSError:
# dirs exist
pass
# houdini uses / instead of \ under windows
# lets fix it
# set the environment variables
self.set_environment_variables(version)
# set the render file name
self.set_render_filename(version)
# houdini accepts only strings as file name, no unicode support as I
# see
hou.hipFile.save(file_name=str(version.absolute_full_path))
# set the environment variables again
self.set_environment_variables(version)
# append it to the recent file list
self.append_to_recent_files(
version.absolute_full_path
)
# update the parent info
if current_version:
version.parent = current_version
# update database with new version info
DBSession.commit()
return True
示例13: setUp
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def setUp(self):
"""set up the test
"""
db.setup()
db.init()
# get statuses
self.status_new = Status.query.filter_by(code="NEW").first()
self.status_wfd = Status.query.filter_by(code="WFD").first()
self.status_rts = Status.query.filter_by(code="RTS").first()
self.status_wip = Status.query.filter_by(code="WIP").first()
self.status_prev = Status.query.filter_by(code="PREV").first()
self.status_hrev = Status.query.filter_by(code="HREV").first()
self.status_drev = Status.query.filter_by(code="DREV").first()
self.status_oh = Status.query.filter_by(code="OH").first()
self.status_stop = Status.query.filter_by(code="STOP").first()
self.status_cmpl = Status.query.filter_by(code="CMPL").first()
self.test_user1 = User(
name='Test User 1',
login='testuser1',
email='[email protected]',
password='secret'
)
self.test_user2 = User(
name='Test User 2',
login='testuser2',
email='[email protected]',
password='secret'
)
self.test_user3 = User(
name='Test User 1',
login='testuser1',
email='[email protected]',
password='secret'
)
self.test_repo = Repository(
name='Test Repository'
)
self.test_structure = Structure(
name='test structure'
)
# project status list
self.test_project_status_list = StatusList(
name='Project Statuses',
target_entity_type='Project',
statuses=[
self.status_new,
self.status_wip,
self.status_oh,
self.status_stop,
self.status_cmpl
]
)
self.test_project1 = Project(
name='Test Project 1',
code='TP1',
lead=self.test_user1,
repository=self.test_repo,
structure=self.test_structure,
status_list=self.test_project_status_list
)
# create three Tasks
self.test_task1 = Task(
name='Test Task 1',
project=self.test_project1
)
self.test_task2 = Task(
name='Test Task 2',
project=self.test_project1
)
self.test_task3 = Task(
name='Test Task 3',
project=self.test_project1
)
# add everything to db
DBSession.add_all([
self.test_project1, self.test_project_status_list, self.test_repo,
self.test_structure, self.test_task1, self.test_task2,
self.test_task3, self.test_user1, self.test_user2
])
DBSession.commit()
self.kwargs = {
'task': self.test_task1,
'depends_to': self.test_task2,
'dependency_target': 'onend',
'gap_timing': 0,
'gap_unit': 'h',
'gap_model': 'length'
}
示例14: test_generic_data_attribute_can_hold_a_wide_variety_of_object_types
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def test_generic_data_attribute_can_hold_a_wide_variety_of_object_types(self):
"""testing if the generic_data attribute can hold any kind of object as
a list
"""
from stalker import db
db.setup()
new_simple_entity = SimpleEntity(**self.kwargs)
test_user = User(
name='email',
login='email',
email='[email protected]',
password='email',
)
from stalker import Department
test_department = Department(
name='department1'
)
from stalker import Repository
test_repo = Repository(
name='Test Repository'
)
from stalker import Structure
test_struct = Structure(
name='Test Project Structure'
)
from stalker import Status, StatusList
test_project_status_list = StatusList(
name='Project Status List',
target_entity_type='Project',
statuses=[
Status(name='Active', code='ACT')
]
)
from stalker import Project
test_proj = Project(
name='Test Project 1',
code='tp1',
repository=test_repo,
structure=test_struct,
status_list=test_project_status_list
)
new_simple_entity.generic_data.extend(
[test_proj, test_project_status_list, test_struct, test_repo,
test_department, test_user]
)
DBSession.add(new_simple_entity)
DBSession.commit()
# now check if it is added to the database correctly
del new_simple_entity
new_simple_entity_db = SimpleEntity.query \
.filter_by(name=self.kwargs['name']) \
.first()
self.assertTrue(test_proj in new_simple_entity_db.generic_data)
self.assertTrue(
test_project_status_list in new_simple_entity_db.generic_data)
self.assertTrue(test_struct in new_simple_entity_db.generic_data)
self.assertTrue(test_repo in new_simple_entity_db.generic_data)
self.assertTrue(test_department in new_simple_entity_db.generic_data)
self.assertTrue(test_user in new_simple_entity_db.generic_data)
DBSession.remove()
示例15: save_as
# 需要导入模块: from stalker.db import DBSession [as 别名]
# 或者: from stalker.db.DBSession import commit [as 别名]
def save_as(self, version):
""""the save action for nuke environment
uses Nukes own python binding
"""
# get the current version, and store it as the parent of the new version
current_version = self.get_current_version()
# first initialize the version path
version.update_paths()
# set the extension to '.nk'
version.extension = '.nk'
# set created_with to let the UI show Nuke icon in versions list
version.created_with = self.name
# set project_directory
# self.project_directory = os.path.dirname(version.absolute_path)
# create the main write node
self.create_main_write_node(version)
# replace read and write node paths
# self.replace_external_paths()
# create the path before saving
try:
os.makedirs(version.absolute_path)
except OSError:
# path already exists OSError
pass
# set frame range
# if this is a shot related task set it to shots resolution
is_shot_related_task = False
shot = None
from stalker import Shot
for task in version.task.parents:
if isinstance(task, Shot):
is_shot_related_task = True
shot = task
break
# set scene fps
project = version.task.project
self.set_fps(project.fps)
if version.version_number == 1:
if is_shot_related_task:
# just set if the frame range is not 1-1
if shot.cut_in != 1 and shot.cut_out != 1:
self.set_frame_range(
shot.cut_in,
shot.cut_out
)
imf = shot.image_format
else:
imf = project.image_format
# TODO: set the render resolution later
# self.set_resolution(
# imf.width,
# imf.height,
# imf.pixel_aspect
# )
nuke.scriptSaveAs(version.absolute_full_path)
if current_version:
# update the parent info
version.parent = current_version
# update database with new version info
DBSession.commit()
return True