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 )
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()
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='******', email='*****@*****.**', password='******') # 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() # 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)
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()
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
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' )
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()
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='******', email='*****@*****.**', password='******' ) # 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()
def setUpClass(cls): """setup tests in class level """ cls.config = { 'sqlalchemy.url': 'postgresql://*****:*****@localhost/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()
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='******', email='*****@*****.**', password='******' ) # 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)
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='******', email='*****@*****.**', password='******') # 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)
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='******', email='*****@*****.**', password='******') # 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()
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='******', email='*****@*****.**', password='******' ) # 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 )
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
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
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.code}}/{{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.query.filter_by(target_entity_type='Project').first() task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() 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 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 osx version1_found = env.get_version_from_full_path( '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version1_found, version1) # version2 in osx version2_found = env.get_version_from_full_path( '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(version2_found, version2)
def setUp(self): """set up the test """ # we need a database db.setup(self.config) db.init() # replace datetime now function # create departments self.test_dep1 = Department(name='Dep1') self.test_dep2 = Department(name='Dep2') # create resources self.test_user1 = User( login='******', name='User1', email='*****@*****.**', password='******', departments=[self.test_dep1] ) DBSession.add(self.test_user1) self.test_user2 = User( login='******', name='User2', email='*****@*****.**', password='******', departments=[self.test_dep1] ) DBSession.add(self.test_user2) self.test_user3 = User( login='******', name='User3', email='*****@*****.**', password='******', departments=[self.test_dep2] ) DBSession.add(self.test_user3) self.test_user4 = User( login='******', name='User4', email='*****@*****.**', password='******', departments=[self.test_dep2] ) DBSession.add(self.test_user4) # user with two departments self.test_user5 = User( login='******', name='User5', email='*****@*****.**', password='******', departments=[self.test_dep1, self.test_dep2] ) DBSession.add(self.test_user5) # user with no departments self.test_user6 = User( login='******', name='User6', email='*****@*****.**', password='******' ) DBSession.add(self.test_user6) # repository self.test_repo = Repository( name='Test Repository', linux_path='/mnt/T/', windows_path='T:/', osx_path='/Volumes/T/' ) DBSession.add(self.test_repo) # statuses self.test_status1 = Status(name='Status 1', code='STS1') self.test_status2 = Status(name='Status 2', code='STS2') self.test_status3 = Status(name='Status 3', code='STS3') self.test_status4 = Status(name='Status 4', code='STS4') self.test_status5 = Status(name='Status 5', code='STS5') DBSession.add_all([self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5]) # status lists self.test_proj_status_list = StatusList( name='Project Status List', statuses=[self.test_status1, self.test_status2, self.test_status3], target_entity_type='Project' ) DBSession.add(self.test_proj_status_list) # create one project self.test_proj1 = Project( name='Test Project 1', code='TP1', repository=self.test_repo, status_list=self.test_proj_status_list, start=datetime.datetime(2013, 4, 4), end=datetime.datetime(2013, 5, 4) ) DBSession.add(self.test_proj1) self.test_proj1.now = datetime.datetime(2013, 4, 4) # create task status list with DBSession.no_autoflush: self.test_task_status_list = StatusList.query\ .filter_by(target_entity_type='Task').first() # create two tasks with the same resources self.test_task1 = Task( name='Task1', project=self.test_proj1, resources=[self.test_user1, self.test_user2], alternative_resources=[ self.test_user3, self.test_user4, self.test_user5 ], schedule_model=0, schedule_timing=50, schedule_unit='h', status_list=self.test_task_status_list ) DBSession.add(self.test_task1) self.test_task2 = Task( name='Task2', project=self.test_proj1, resources=[self.test_user1, self.test_user2], alternative_resources=[ self.test_user3, self.test_user4, self.test_user5 ], depends=[self.test_task1], schedule_model=0, schedule_timing=60, schedule_unit='h', status_list=self.test_task_status_list ) DBSession.add(self.test_task2) DBSession.commit()
def setUp(self): """set up the test """ db.setup() db.init() self.user1 = User( name='Test User 1', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user1) self.user2 = User( name='Test User 2', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user2) self.user3 = User( name='Test User 2', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user3) # Review Statuses self.status_new = Status.query.filter_by(code='NEW').first() self.status_rrev = Status.query.filter_by(code='RREV').first() self.status_app = Status.query.filter_by(code='APP').first() # Task Statuses 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_cmpl = Status.query.filter_by(code='CMPL').first() self.project_status_list = StatusList( target_entity_type='Project', statuses=[ self.status_new, self.status_wip, self.status_cmpl ] ) DBSession.add(self.project_status_list) self.temp_path = tempfile.mkdtemp() self.repo = Repository( name='Test Repository', linux_path=self.temp_path, windows_path=self.temp_path, osx_path=self.temp_path ) DBSession.add(self.repo) self.structure = Structure( name='Test Project Structure' ) DBSession.add(self.structure) self.project = Project( name='Test Project', code='TP', status_list=self.project_status_list, repository=self.repo ) DBSession.add(self.project) self.task1 = Task( name='Test Task 1', project=self.project, resources=[self.user1], responsible=[self.user2] ) DBSession.add(self.task1) self.task2 = Task( name='Test Task 2', project=self.project, responsible=[self.user1] ) DBSession.add(self.task2) self.task3 = Task( name='Test Task 3', parent=self.task2, resources=[self.user1] ) DBSession.add(self.task3) self.task4 = Task( name='Test Task 4', project=self.project, resources=[self.user1], depends=[self.task3], responsible=[self.user2], schedule_timing=2, schedule_unit='h' ) DBSession.add(self.task4) self.task5 = Task( name='Test Task 5', project=self.project, resources=[self.user2], depends=[self.task3], responsible=[self.user2], schedule_timing=2, schedule_unit='h' ) DBSession.add(self.task5) self.task6 = Task( name='Test Task 6', project=self.project, resources=[self.user3], depends=[self.task3], responsible=[self.user2], schedule_timing=2, schedule_unit='h' ) DBSession.add(self.task6) self.kwargs = { 'task': self.task1, 'reviewer': self.user1 } #self.review = Review(**self.kwargs) #DBSession.add(self.review) # add everything to the db DBSession.commit()
def setUp(self): """set up the test """ # we need a database db.setup(self.config) db.init() # replace datetime now function # create departments self.test_dep1 = Department(name="Dep1") self.test_dep2 = Department(name="Dep2") # create resources self.test_user1 = User( login="******", name="User1", email="*****@*****.**", password="******", departments=[self.test_dep1] ) DBSession.add(self.test_user1) self.test_user2 = User( login="******", name="User2", email="*****@*****.**", password="******", departments=[self.test_dep1] ) DBSession.add(self.test_user2) self.test_user3 = User( login="******", name="User3", email="*****@*****.**", password="******", departments=[self.test_dep2] ) DBSession.add(self.test_user3) self.test_user4 = User( login="******", name="User4", email="*****@*****.**", password="******", departments=[self.test_dep2] ) DBSession.add(self.test_user4) # user with two departments self.test_user5 = User( login="******", name="User5", email="*****@*****.**", password="******", departments=[self.test_dep1, self.test_dep2], ) DBSession.add(self.test_user5) # user with no departments self.test_user6 = User(login="******", name="User6", email="*****@*****.**", password="******") DBSession.add(self.test_user6) # repository self.test_repo = Repository( name="Test Repository", linux_path="/mnt/T/", windows_path="T:/", osx_path="/Volumes/T/" ) DBSession.add(self.test_repo) # statuses self.test_status1 = Status(name="Status 1", code="STS1") self.test_status2 = Status(name="Status 2", code="STS2") self.test_status3 = Status(name="Status 3", code="STS3") self.test_status4 = Status(name="Status 4", code="STS4") self.test_status5 = Status(name="Status 5", code="STS5") DBSession.add_all( [self.test_status1, self.test_status2, self.test_status3, self.test_status4, self.test_status5] ) # status lists self.test_proj_status_list = StatusList( name="Project Status List", statuses=[self.test_status1, self.test_status2, self.test_status3], target_entity_type="Project", ) DBSession.add(self.test_proj_status_list) # create one project self.test_proj1 = Project( name="Test Project 1", code="TP1", repository=self.test_repo, status_list=self.test_proj_status_list, start=datetime.datetime(2013, 4, 4), end=datetime.datetime(2013, 5, 4), ) DBSession.add(self.test_proj1) self.test_proj1.now = datetime.datetime(2013, 4, 4) # create task status list with DBSession.no_autoflush: self.test_task_status_list = StatusList.query.filter_by(target_entity_type="Task").first() # create two tasks with the same resources self.test_task1 = Task( name="Task1", project=self.test_proj1, resources=[self.test_user1, self.test_user2], alternative_resources=[self.test_user3, self.test_user4, self.test_user5], schedule_model=0, schedule_timing=50, schedule_unit="h", status_list=self.test_task_status_list, ) DBSession.add(self.test_task1) self.test_task2 = Task( name="Task2", project=self.test_proj1, resources=[self.test_user1, self.test_user2], alternative_resources=[self.test_user3, self.test_user4, self.test_user5], depends=[self.test_task1], schedule_model=0, schedule_timing=60, schedule_unit="h", status_list=self.test_task_status_list, ) DBSession.add(self.test_task2) DBSession.commit()
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 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 osx version1_found = env.get_version_from_full_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version1_found, version1) # version2 in osx version2_found = env.get_version_from_full_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(version2_found, version2)
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" # version1 native trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 native trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 windows trimmed_path = env.trim_repo_path("T:/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 windows trimmed_path = env.trim_repo_path("S:/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 linux trimmed_path = env.trim_repo_path("/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 linux trimmed_path = env.trim_repo_path("/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2) # version1 osx trimmed_path = env.trim_repo_path("/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value1) # version2 osx trimmed_path = env.trim_repo_path("/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001") self.assertEqual(trimmed_path, expected_value2)
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.query.filter_by(target_entity_type='Project').first() task_status_list = \ StatusList.query.filter_by(target_entity_type='Task').first() DBSession.add(task_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) DBSession.add(version2) DBSession.commit() version2.update_paths() version3 = Version(task=task2) DBSession.add(version3) DBSession.commit() version3.update_paths() version4 = Version(task=task2) 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' # version1 native trimmed_path = env.trim_repo_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 native trimmed_path = env.trim_repo_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 windows trimmed_path = env.trim_repo_path( 'T:/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 windows trimmed_path = env.trim_repo_path( 'S:/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 linux trimmed_path = env.trim_repo_path( '/mnt/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 linux trimmed_path = env.trim_repo_path( '/mnt/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2) # version1 osx trimmed_path = env.trim_repo_path( '/Volumes/T/TP1/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value1) # version2 osx trimmed_path = env.trim_repo_path( '/Volumes/S/TP2/Test_Task_1/Test_Task_1_Main_v001') self.assertEqual(trimmed_path, expected_value2)
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='******', email='*****@*****.**', password='******' ) self.test_user2 = User( name='Test User 2', login='******', email='*****@*****.**', password='******' ) self.test_user3 = User( name='Test User 1', login='******', email='*****@*****.**', password='******' ) 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' }
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='*****@*****.**', password='******', ) 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()
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='******', email='*****@*****.**', password='******') self.test_user2 = User(name='Test User 2', login='******', email='*****@*****.**', password='******') self.test_user3 = User(name='Test User 1', login='******', email='*****@*****.**', password='******') 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', 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' }
def setUp(self): """set up the test """ db.setup() db.init() self.user1 = User( name='Test User 1', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user1) self.user2 = User( name='Test User 2', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user2) self.user3 = User( name='Test User 2', login='******', email='*****@*****.**', password='******' ) DBSession.add(self.user3) # Review Statuses self.status_new = Status.query.filter_by(code='NEW').first() self.status_rrev = Status.query.filter_by(code='RREV').first() self.status_app = Status.query.filter_by(code='APP').first() # Task Statuses 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_cmpl = Status.query.filter_by(code='CMPL').first() self.project_status_list = StatusList( target_entity_type='Project', statuses=[ self.status_new, self.status_wip, self.status_cmpl ] ) DBSession.add(self.project_status_list) self.temp_path = tempfile.mkdtemp() self.repo = Repository( name='Test Repository', linux_path=self.temp_path, windows_path=self.temp_path, osx_path=self.temp_path ) DBSession.add(self.repo) self.structure = Structure( name='Test Project Structure' ) DBSession.add(self.structure) self.project = Project( name='Test Project', code='TP', lead=self.user1, status_list=self.project_status_list, repository=self.repo ) DBSession.add(self.project) self.task1 = Task( name='Test Task 1', project=self.project, resources=[self.user1] ) DBSession.add(self.task1) self.task2 = Task( name='Test Task 2', project=self.project ) DBSession.add(self.task2) self.task3 = Task( name='Test Task 3', parent=self.task2, resources=[self.user1] ) DBSession.add(self.task3) self.kwargs = { 'task': self.task1, 'reviewer': self.user1 } #self.review = Review(**self.kwargs) #DBSession.add(self.review) # add everything to the db DBSession.commit()
def test_creating_a_time_log_for_a_leaf_task_will_set_its_parents_status_to_wip(self): """testing if the status of the parent task will turn to wip if time log is entered to a child task """ # 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 ) task2 = Task( name='Test Task 2', parent=task1, resources=[self.user1], status_list=self.task_status_list, status=self.status_rts ) task3 = Task( name='Test Task 3', parent=task1, resources=[self.user1], status_list=self.task_status_list, status=self.status_rts ) task4 = Task( name='Test Task 4', parent=task0, resources=[self.user1], status_list=self.task_status_list, status=self.status_rts ) DBSession.add_all([task0, task1, task2, task3, task4]) DBSession.commit() DBSession.flush() transaction.commit() self.assertEqual(task0.status, self.status_new) self.assertEqual(task1.status, self.status_new) self.assertEqual(task2.status, self.status_rts) self.assertEqual(task3.status, self.status_rts) self.assertEqual(task4.status, self.status_rts) # 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'] = task3.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) # now expect to have the status of task1 to be wip self.assertEqual(task3.status, self.status_wip) self.assertEqual(task2.status, self.status_rts) self.assertEqual(task1.status, self.status_wip) self.assertEqual(task0.status, self.status_wip) self.assertEqual(task4.status, self.status_rts) request.params['task_id'] = task2.id request.params['resource_id'] = self.user1.id request.params['start'] = "Fri, 18 Nov 2013 08:00:00 GMT" request.params['end'] = "Fri, 18 Nov 2013 17:00:00 GMT" response = time_log.create_time_log(request) self.assertEqual(response.status_int, 200) # now expect to have the status of task1 to be wip self.assertEqual(task3.status, self.status_wip) self.assertEqual(task2.status, self.status_wip) self.assertEqual(task1.status, self.status_wip) self.assertEqual(task0.status, self.status_wip) self.assertEqual(task4.status, self.status_rts) # now request a review and approve the task2 and task3 and expect the # task1 status is complete from stalker_pyramid.views.task import request_review, review_task #request = testing.DummyRequest() request.matchdict['id'] = task2.id request.params['send_email'] = 0 request.route_url = lambda x, id: 'localhost:6453/tasks/23/view' request.route_path = lambda x, id: '/tasks/23/view' response = request_review(request) self.assertEqual(response.status_int, 200) #request = testing.DummyRequest() request.matchdict['id'] = task3.id request.params['send_email'] = 0 response = request_review(request) print response.body self.assertEqual(response.status_int, 200) self.assertEqual(task3.status, self.status_prev) self.assertEqual(task2.status, self.status_prev) self.assertEqual(task1.status, self.status_wip) self.assertEqual(task0.status, self.status_wip) self.assertEqual(task4.status, self.status_rts) # approve the task2 request.matchdict['id'] = task2.id request.params['review'] = 'Approve' response = review_task(request) self.assertEqual(response.status_int, 200) # and except task1 is still wip self.assertEqual(task3.status, self.status_prev) self.assertEqual(task2.status, self.status_cmpl) self.assertEqual(task1.status, self.status_wip) self.assertEqual(task0.status, self.status_wip) self.assertEqual(task4.status, self.status_rts) # approve the task3 request.matchdict['id'] = task3.id request.params['review'] = 'Approve' response = review_task(request) self.assertEqual(response.status_int, 200) # now check the statuses self.assertEqual(task3.status, self.status_cmpl) self.assertEqual(task2.status, self.status_cmpl) self.assertEqual(task1.status, self.status_cmpl) self.assertEqual(task0.status, self.status_wip) self.assertEqual(task4.status, self.status_rts)