def _test_parent_search(self): from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','burt') person.commit() person2 = SearchType.create('unittest/person') person2.set_value('name_first','sean') person2.commit() person_search = Search('unittest/person') person_search.add_filters('id', [person.get_id(), person2.get_id()]) for xrange in (1, 50): Task.create(person, 'process_CC','some task', 'admin', context='process_CC') for xrange in (1, 50): Task.create(person2, 'process_DD','some task', 'admin') # find parent of tasks search2 = Search('sthpw/task') search2.add_relationship_filters([person,person2]) tasks = search2.get_sobjects() search3 = Search('sthpw/task') search3.add_relationship_search_filter(person_search) tasks2 = search3.get_sobjects() self.assertEquals(SObject.get_values(tasks, 'id'), SObject.get_values(tasks2, 'id'))
def execute(self): person = SearchType.create('unittest/person') person.set_value('name_first', 'john') person.commit(triggers=False) person2 = SearchType.create('unittest/person') person2.set_value('name_first', 'zoe') person2.commit(triggers=False) task = Task.create(person, "unittest_person", "hello") task = Task.create(person2, "unittest_person", "hello")
def execute(my): person = SearchType.create("unittest/person") person.set_value("name_first", "john") person.commit(triggers=False) person2 = SearchType.create("unittest/person") person2.set_value("name_first", "zoe") person2.commit(triggers=False) task = Task.create(person, "unittest_person", "hello") task = Task.create(person2, "unittest_person", "hello")
def _test_child_search(self): from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','pete') person.commit() for xrange in (1, 50): Task.create(person, 'process_AA','some task', 'admin', context='process_AA') person2 = SearchType.create('unittest/person') person2.set_value('name_first','jamie') person2.commit() person2_tasks = [] for xrange in (1, 50): person2_tasks.append(Task.create(person2, 'process_BB','some task', 'admin', context='process_BB')) task_search = Search('sthpw/task') task_search.add_filters('process', ['process_AA', 'process_BB']) tasks = task_search.get_sobjects() search2 = Search('unittest/person') search2.add_relationship_filters(tasks) persons = search2.get_sobjects() search3 = Search('unittest/person') search3.add_relationship_search_filter(task_search) persons_fast = search3.get_sobjects() self.assertEquals(SObject.get_values(persons, 'id'), SObject.get_values(persons_fast, 'id')) self.assertEquals(SObject.get_values(persons_fast, 'name_first'), ['pete','jamie']) # if I retire all the tasks for person2 for task in tasks: if task.get_value('process') =='process_BB': task.retire() task_search = Search('sthpw/task') task_search.add_filters('process', ['process_AA', 'process_BB']) tasks = task_search.get_sobjects() search4 = Search('unittest/person') search4.add_relationship_search_filter(task_search) persons_fast = search4.get_sobjects() search2 = Search('unittest/person') search2.add_relationship_filters(tasks) persons = search2.get_sobjects() self.assertEquals(SObject.get_values(persons, 'id'), SObject.get_values(persons_fast, 'id')) self.assertEquals(SObject.get_values(persons_fast, 'name_first'), ['pete']) # test add_filters() with an empty array task_search = Search('sthpw/task') task_search.add_filters('process', []) tasks = task_search.get_sobjects() self.assertEquals(tasks, []) expected = '''SELECT %s"task".* FROM %s"task" WHERE "task"."id" is NULL AND ("task"."s_status" != 'retired' or "task"."s_status" is NULL) ORDER BY "task"."search_type", "task"."search_code"'''%(self.sthpw_prefix, self.sthpw_prefix) statement = task_search.get_statement() self.assertEquals(statement, expected)
def _test_child_search(my): from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','pete') person.commit() for xrange in (1, 50): Task.create(person, 'process_AA','some task', 'admin', context='process_AA') person2 = SearchType.create('unittest/person') person2.set_value('name_first','jamie') person2.commit() person2_tasks = [] for xrange in (1, 50): person2_tasks.append(Task.create(person2, 'process_BB','some task', 'admin', context='process_BB')) task_search = Search('sthpw/task') task_search.add_filters('process', ['process_AA', 'process_BB']) tasks = task_search.get_sobjects() search2 = Search('unittest/person') search2.add_relationship_filters(tasks) persons = search2.get_sobjects() search3 = Search('unittest/person') search3.add_relationship_search_filter(task_search) persons_fast = search3.get_sobjects() my.assertEquals(SObject.get_values(persons, 'id'), SObject.get_values(persons_fast, 'id')) my.assertEquals(SObject.get_values(persons_fast, 'name_first'), ['pete','jamie']) # if I retire all the tasks for person2 for task in tasks: if task.get_value('process') =='process_BB': task.retire() task_search = Search('sthpw/task') task_search.add_filters('process', ['process_AA', 'process_BB']) tasks = task_search.get_sobjects() search4 = Search('unittest/person') search4.add_relationship_search_filter(task_search) persons_fast = search4.get_sobjects() search2 = Search('unittest/person') search2.add_relationship_filters(tasks) persons = search2.get_sobjects() my.assertEquals(SObject.get_values(persons, 'id'), SObject.get_values(persons_fast, 'id')) my.assertEquals(SObject.get_values(persons_fast, 'name_first'), ['pete'])
def execute(self): input = self.get_input() search_key = input.get("search_key") task = Search.get_by_search_key(search_key) parent = task.get_parent() if not parent: raise TacticException("Task parent not found.") # get the definition of the trigger trigger_sobj = self.get_trigger_sobj() data = trigger_sobj.get_value("data") try: data = jsonloads(data) except: raise TacticException("Incorrect formatting of trigger [%s]." % trigger_sobj.get_value("code")) # check against source status if present src_status = data.get("src_status") if src_status: task_status = task.get_value("status") if task_status != src_status: return process_names = data.get("output") if not process_names: return # only create new task if another of the same # process does not already exist search = Search("sthpw/task") search.add_filters("process", process_names) search.add_parent_filter(parent) search.add_project_filter() tasks = search.get_sobjects() existing_processes = [x.get_value("process") for x in tasks] for process in process_names: if process in existing_processes: continue else: Task.create(parent, process, start_date=None, end_date=None)
def execute(my): input = my.get_input() search_key = input.get("search_key") task = Search.get_by_search_key(search_key) parent = task.get_parent() # get the definition of the trigger trigger_sobj = my.get_trigger_sobj() data = trigger_sobj.get_value("data") data = jsonloads(data) process = data.get("output") description = "" # FIXME: # find out if there is already a task of that process Task.create(parent, process, description, start_date=None, end_date=None)
def _test_multi_task(self): # create a dummy sobject sobject = SearchType.create("unittest/person") pipeline_xml = ''' <pipeline> <process name="a"/> <process type="action" name="b"/> <connect from="a" to="b"/> </pipeline> ''' pipeline, processes = self.get_pipeline(pipeline_xml) sobject.set_value("pipeline_code", pipeline.get_code()) sobject.commit() for process_name, process in processes.items(): process.set_json_value( "workflow", { 'on_complete': ''' sobject.set_value('name_first', '%s') ''' % process_name, }) process.commit() task = Task.create(sobject, process="a", description="Test Task") task2 = Task.create(sobject, process="a", description="Test Task 2") task.set_value("status", "complete") task.commit() self.assertEquals(False, "b" == sobject.get_value("name_first")) task2.set_value("status", "complete") task2.commit() self.assertEquals(True, "b" == sobject.get_value("name_first"))
def _test_multi_task(self): # create a dummy sobject sobject = SearchType.create("unittest/person") pipeline_xml = ''' <pipeline> <process name="a"/> <process type="action" name="b"/> <connect from="a" to="b"/> </pipeline> ''' pipeline, processes = self.get_pipeline(pipeline_xml) sobject.set_value("pipeline_code", pipeline.get_code() ) sobject.commit() for process_name, process in processes.items(): process.set_json_value("workflow", { 'on_complete': ''' sobject.set_value('name_first', '%s') ''' % process_name, } ) process.commit() task = Task.create(sobject, process="a", description="Test Task") task2 = Task.create(sobject, process="a", description="Test Task 2") task.set_value("status", "complete") task.commit() self.assertEquals( False, "b" == sobject.get_value("name_first")) task2.set_value("status", "complete") task2.commit() self.assertEquals( True, "b" == sobject.get_value("name_first"))
def _test_task(my): # create a dummy sobject sobject = SearchType.create("unittest/person") pipeline_xml = ''' <pipeline> <process name="a"/> <process type="action" name="b"/> <connect from="a" to="b"/> </pipeline> ''' pipeline, processes = my.get_pipeline(pipeline_xml) sobject.set_value("pipeline_code", pipeline.get_code() ) sobject.commit() for process_name, process in processes.items(): process.set_json_value("workflow", { #'on_in_progress': ''' #sobject.set_value('name_first', '%s') #''' % process_name, 'on_complete': ''' sobject.set_value('name_first', '%s') ''' % process_name, } ) process.commit() task = Task.create(sobject, process="a", description="Test Task") # TODO: not quite sure if this should be related to "action" #task.set_value("status", "in_progress") #task.commit() #my.assertEquals( "in_progress", sobject.get_value("name_first")) task.set_value("status", "complete") task.commit() my.assertEquals( "b", sobject.get_value("name_first"))
def _test_task(self): # create a dummy sobject sobject = SearchType.create("unittest/person") pipeline_xml = ''' <pipeline> <process name="a"/> <process type="action" name="b"/> <connect from="a" to="b"/> </pipeline> ''' pipeline, processes = self.get_pipeline(pipeline_xml) sobject.set_value("pipeline_code", pipeline.get_code()) sobject.commit() for process_name, process in processes.items(): process.set_json_value( "workflow", { #'on_in_progress': ''' #sobject.set_value('name_first', '%s') #''' % process_name, 'on_complete': ''' sobject.set_value('name_first', '%s') ''' % process_name, }) process.commit() task = Task.create(sobject, process="a", description="Test Task") # TODO: not quite sure if this should be related to "action" #task.set_value("status", "in_progress") #task.commit() #self.assertEquals( "in_progress", sobject.get_value("name_first")) task.set_value("status", "complete") task.commit() self.assertEquals("b", sobject.get_value("name_first"))
def execute(my): left_cb , right_cb = my.get_checkbox_cols() web = WebContainer.get_web() select_shots = web.get_form_values(right_cb.CB_NAME) if not select_shots: return select_tasks = web.get_form_values("sthpw_task") if not select_tasks: return # get all of the shots shots = [] for shot_search_key in select_shots: shot = Search.get_by_search_key(shot_search_key) shots.append(shot) # get all of the tasks tasks = [] for task_search_key in select_tasks: task = Search.get_by_search_key(task_search_key) tasks.append(task) # copy these tasks into the selected shots from pyasm.biz import Task for shot in shots: for task in tasks: # extract the properties of each task process = task.get_value("process") description = task.get_value("description") assigned = task.get_value("assigned") supe = task.get_value("supervisor") # create a new tasks new_task = Task.create(shot, process, description, assigned=assigned,\ supervisor=supe) my.sobjects.append(new_task) my.add_description("Added template tasks to shot(s)")
def execute(self): left_cb , right_cb = self.get_checkbox_cols() web = WebContainer.get_web() select_shots = web.get_form_values(right_cb.CB_NAME) if not select_shots: return select_tasks = web.get_form_values("sthpw_task") if not select_tasks: return # get all of the shots shots = [] for shot_search_key in select_shots: shot = Search.get_by_search_key(shot_search_key) shots.append(shot) # get all of the tasks tasks = [] for task_search_key in select_tasks: task = Search.get_by_search_key(task_search_key) tasks.append(task) # copy these tasks into the selected shots from pyasm.biz import Task for shot in shots: for task in tasks: # extract the properties of each task process = task.get_value("process") description = task.get_value("description") assigned = task.get_value("assigned") supe = task.get_value("supervisor") # create a new tasks new_task = Task.create(shot, process, description, assigned=assigned,\ supervisor=supe) self.sobjects.append(new_task) self.add_description("Added template tasks to shot(s)")
def _test_context_output(self): # create a dummy sobject sobject = self.setup() # create a pipeline pipeline_xml = ''' <pipeline> <process type="auto" name="a"/> <process type="manual" name="b"/> <connect from="a" to="b"/> </pipeline> ''' pipeline, processes = self.get_pipeline(pipeline_xml) sobject.set_value("pipeline_code", pipeline.get_code()) sobject.commit() process = processes.get("a") process.set_json_value( "workflow", { 'output': { 'context': 'test,test2', }, 'on_action': r''' path = "/tmp/test.txt" f = open(path, 'w') f.write("OMG\n") f.close() path2 = "/tmp/test2.txt" f = open(path2, 'w') f.write("OMG2\n") f.close() sobject = input.get("sobject") search_key = sobject.get("__search_key__") server.simple_checkin(search_key, "test", path, mode="move") server.simple_checkin(search_key, "test2", path2, mode="move") ''' }) process.commit() # create a task for b task = Task.create(sobject, process="b") # Run the pipeline, this will stop at b process = "a" output = { "pipeline": pipeline, "sobject": sobject, "process": process, } Trigger.call(self, "process|pending", output) # use data flow to get the input path. Basically, this states # "get me whatever self input is delivering" dataflow = Dataflow() path = dataflow.get_input_path(sobject, "b") print "path: ", path task.set_value("status", "complete") task.commit()
def _test_multi_db_subselect(self): from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin') person.commit() Task.create(person, 'subselect','some task', 'admin', status="a") from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin2') person.commit() Task.create(person, 'subselect','some task', 'admin', status="b") from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin3') person.commit() Task.create(person, 'subselect','some task', 'admin', status="c") # find people by carin that have a task "subselect" search_person = Search("unittest/person") search_task = Search("sthpw/task") search_person.add_relationship_search_filter(search_task,use_multidb=False) search_task.add_filter("process", "subselect") sobjects = search_person.get_sobjects() self.assertEquals(len(sobjects), 3) # find people by carin that have a task "subselect", using # subselect search_person = Search("unittest/person") search_task = Search("sthpw/task") search_person.add_relationship_search_filter(search_task,use_multidb=True) search_task.add_filter("process", "subselect") sobjects = search_person.get_sobjects() self.assertEquals(len(sobjects), 3) # find task that carin has search_task = Search("sthpw/task") search_person = Search("unittest/person") search_person.add_filter('name_first','carin') search_task.add_relationship_search_filter(search_person,use_multidb=True) sobjects = search_task.get_sobjects() # test an order by on a task status (cross database join) # Note this will not work on Postgres or SQLite which do not # support cross database joins search_person = Search("unittest/person") search_person.add_order_by("sthpw/task.status", direction="desc") statement = search_person.get_statement() can_join = DatabaseImpl.can_search_types_join( \ "unittest/person", "sthpw/task") if can_join: expected = '''SELECT %s"person".* FROM %s"person" LEFT OUTER JOIN %s"task" ON "person"."code" = "task"."search_code" WHERE "task"."search_type" = 'unittest/person?project=unittest' ORDER BY "task"."status" desc''' % (self.prefix, self.prefix, self.sthpw_prefix) self.assertEquals(expected, statement) sobjects = search_person.get_sobjects() names = [x.get_value("name_first") for x in sobjects] expected = ['carin3','carint2','carin'] self.assertEquals(expected, names)
def _test_multi_db_subselect(my): from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin') person.commit() Task.create(person, 'subselect','some task', 'admin', status="a") from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin2') person.commit() Task.create(person, 'subselect','some task', 'admin', status="b") from pyasm.biz import Task person = SearchType.create('unittest/person') person.set_value('name_first','carin3') person.commit() Task.create(person, 'subselect','some task', 'admin', status="c") # find people by carin that have a task "subselect" search_person = Search("unittest/person") search_task = Search("sthpw/task") search_person.add_relationship_search_filter(search_task,use_multidb=False) search_task.add_filter("process", "subselect") sobjects = search_person.get_sobjects() my.assertEquals(len(sobjects), 3) # find people by carin that have a task "subselect", using # subselect search_person = Search("unittest/person") search_task = Search("sthpw/task") search_person.add_relationship_search_filter(search_task,use_multidb=True) search_task.add_filter("process", "subselect") sobjects = search_person.get_sobjects() my.assertEquals(len(sobjects), 3) # find task that carin has search_task = Search("sthpw/task") search_person = Search("unittest/person") search_person.add_filter('name_first','carin') search_task.add_relationship_search_filter(search_person,use_multidb=True) sobjects = search_task.get_sobjects() # test an order by on a task status search_person = Search("unittest/person") search_person.add_order_by("sthpw/task.status", direction="desc") statement = search_person.get_statement() expected = '''SELECT %s."person".* FROM %s."person" LEFT OUTER JOIN "sthpw"."task" ON "person"."code" = "task"."search_code" WHERE "task"."search_type" = 'unittest/person?project=unittest' ORDER BY "task"."status" desc''' % (my.prefix, my.prefix) my.assertEquals(expected, statement) sobjects = search_person.get_sobjects() names = [x.get_value("name_first") for x in sobjects] expected = ['carin3','carint2','carin'] my.assertEquals(expected, names)