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 test_creating_a_time_log_for_a_task_whose_dependending_tasks_already_has_time_logs(self): """testing if a HTTPServer error will be raised when a time log tried to be for a task whose depending tasks already has time logs created (This test should be in Stalker) """ # create a new task task2 = Task( name='Test Task 2', project=self.proj1, depends=[self.task1], resources=[self.user1], schedule_timing=4, schedule_unit= 'd', schedule_model='effort', status_list=self.task_status_list ) DBSession.add(task2) DBSession.flush() transaction.commit() # set the status of task1 to complete self.task1.status = self.status_cmpl # artificially update task2 status to rts task2.status = self.status_rts DBSession.flush() transaction.commit() # and now create time logs for task2 request = testing.DummyRequest() request.params['task_id'] = task2.id request.params['resource_id'] = self.user1.id request.params['start'] = "Fri, 01 Nov 2013 08:00:00 GMT" request.params['end'] = "Fri, 01 Nov 2013 17:00:00 GMT" response = time_log.create_time_log(request) self.assertEqual(response.status_int, 200) DBSession.add(task2) DBSession.flush() transaction.commit() # now because task2 is depending on to the task1 # and task2 has now started, entering any new time logs to task1 # is forbidden request = testing.DummyRequest() request.params['task_id'] = self.task1.id request.params['resource_id'] = self.user1.id request.params['start'] = "Fri, 02 Nov 2013 08:00:00 GMT" request.params['end'] = "Fri, 02 Nov 2013 17:00:00 GMT" response = time_log.create_time_log(request) self.assertEqual( response.status_int, 500 )
def create_shot_hierarchy(self): """creates the related shot hierarchy """ logged_in_user = self.get_logged_in_user() from stalker import Task from stalker.db.session import DBSession shot = self.get_shot() if not shot: shot = self.create_shot() # creat shot tasks # Anim anim_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Anim').first() if not anim_task: anim_task = Task( name='Anim', parent=shot, type=self.get_type('Animation'), bid_timing=10, bid_unit='min', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) DBSession.add(anim_task) # Camera camera_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Camera').first() if not camera_task: camera_task = Task( name='Camera', parent=shot, type=self.get_type('Camera'), bid_timing=10, bid_unit='min', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) DBSession.add(camera_task) # Cleanup cleanup_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Cleanup').first() if not cleanup_task: cleanup_task = Task( name='Cleanup', parent=shot, type=self.get_type('Cleanup'), bid_timing=10, bid_unit='min', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) DBSession.add(cleanup_task) # Comp comp_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Comp').first() if not comp_task: comp_task = Task( name='Comp', parent=shot, type=self.get_type('Comp'), bid_timing=10, bid_unit='min', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) DBSession.add(comp_task) # Lighting lighting_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Lighting').first() if not lighting_task: lighting_task = Task( name='Lighting', parent=shot, type=self.get_type('Lighting'), bid_timing=10, bid_unit='min', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) DBSession.add(lighting_task) # Plate plate_task = Task.query.filter(Task.parent == shot).filter(Task.name == 'Plate').first() if not plate_task: import datetime import pytz from stalker import defaults utc_now = datetime.datetime.now(pytz.utc) plate_task = Task( name='Plate', parent=shot, type=self.get_type('Plate'), schedule_timing=10, schedule_unit='min', schedule_model='duration', created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', start=utc_now, # this will be rounded to the timing resolution duration=defaults.timing_resolution ) DBSession.add(plate_task) # Create a dummy version if there is non from stalker import Version all_versions = Version.query.filter(Version.task == plate_task).all() if not all_versions: v = Version( task=plate_task, take_name='Main', # TODO: use the track name as take created_by=logged_in_user, updated_by=logged_in_user, description='Autocreated by Resolve', ) from anima.env import blackmagic resolve = blackmagic.get_resolve() version_info = resolve.GetVersion() v.created_with = 'Resolve%s.%s' % (version_info[0], version_info[1]) DBSession.add(v) # set the status the task with DBSession.no_autoflush: from stalker import Status cmpl = Status.query.filter(Status.code == 'CMPL').first() plate_task.status = cmpl # add dependency relation camera_task.depends = [plate_task] anim_task.depends = [camera_task] lighting_task.depends = [anim_task, camera_task] cleanup_task.depends = [plate_task] comp_task.depends = [lighting_task, cleanup_task] DBSession.commit() return shot