Beispiel #1
0
    def _test_schema(my):
        # prod type test
        prod_proj_code = "sample3d"
        if Project.get_by_code(prod_proj_code):
            prod_schema = Schema.get_by_project_code(prod_proj_code)
            parent_type = prod_schema.get_parent_type('prod/asset')
            my.assertEquals('prod/asset_library', parent_type)

            parent_type = prod_schema.get_parent_type('prod/sequence')
            my.assertEquals('prod/episode', parent_type)
            
            parent_type = prod_schema.get_parent_type('prod/shot')
            my.assertEquals('prod/sequence', parent_type)

            parent_type = prod_schema.get_parent_type('sthpw/task')
            my.assertEquals('*', parent_type)

            parent_type = prod_schema.get_parent_type('sthpw/note')
            my.assertEquals('*', parent_type)
            
            parent_type = prod_schema.get_parent_type('prod/render')
            my.assertEquals('*', parent_type)
            
            parent_type = prod_schema.get_parent_type('prod/submission')
            my.assertEquals('*', parent_type)
        
        schema = Schema.get_by_project_code("unittest")
        # create a new search_type
        schema.add_search_type("unittest/car", parent_type='unittest/person', commit=False)

        schema.add_search_type("unittest/house", parent_type='unittest/person', commit=False)
       
        
        
        parent_type = schema.get_parent_type('unittest/city')
        my.assertEquals('unittest/country', parent_type)

        # get all of the child types
        child_types = schema.get_child_types('unittest/person')
        #print "CHILD TYPES ", child_types
        expected = ['unittest/person_in_car', 'unittest/house']
        my.assertEquals(True, expected[0] in child_types)
        my.assertEquals(True, expected[1] in child_types)

        # create a new schema that has the unittest as the parent
        new_schema = SearchType.create(Schema.SEARCH_TYPE)
        new_schema.set_value("code", "unittest/custom")
        new_schema_xml = '''
        <schema parent='unittest'>
        <search_type name='unittest/account'/>
        <connect from='unittest/person' to='unittest/account' type='hierarchy'/>
        <connect from='*' to='unittest/poof' type='hierarchy'/>
        </schema>
        '''
        new_schema.set_xml(new_schema_xml)

        # get search_types defined in this schema
        search_types = new_schema.get_search_types(hierarchy=False)
        my.assertEquals(1, len(search_types) )

        # get all search_types
        search_types = new_schema.get_search_types()

        # add bunch of dummy initial tasks to the person
        initial_tasks = Task.add_initial_tasks(my.person, 'task')

        # check status_log static trigger
        single_task = initial_tasks[0]
        from pyasm.search import Search

        to_status = Search.eval('@GET(sthpw/status_log.to_status)', sobjects=[single_task], single=True)
        my.assertEquals(to_status, "Assignment")
        single_task.set_value('status', "Test Done")
        single_task.commit(triggers=True)
        

        ExpressionParser.clear_cache() 
        to_status = Search.eval("@GET(sthpw/status_log['@ORDER_BY','id desc'].to_status)", sobjects=[single_task], single=True)
        
        my.assertEquals(to_status, "Test Done")

        # get tasks with get_all_children()
        tasks = my.person.get_all_children("sthpw/task")
        my.assertEquals(len(initial_tasks), len(tasks) )

        
        # get notes with get_all_children()
        Note.create(my.person, "test note", context='default')
        Note.create(my.person, "test note2", context='default2')
        notes = my.person.get_all_children("sthpw/note")
        my.assertEquals(2, len(notes) )

        #relationship
        schema = Schema.get()
        if Project.get_by_code('sample3d'):
            relationship = schema.get_relationship('prod/asset','sthpw/snapshot')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/asset','sthpw/task')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/shot','sthpw/note')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

        relationship = schema.get_relationship('sthpw/file','sthpw/snapshot')
        my.assertEquals(relationship, 'code')
        relationship = schema.get_relationship('sthpw/project_type','sthpw/project')
        my.assertEquals(relationship, 'code')

        relationship = schema.get_relationship('unittest/car','unittest/house')
        my.assertEquals(relationship, None)

        # test parent filter search in sample3d
        if Project.get_by_code('sample3d'):
            from pyasm.prod.biz import *
            Project.set_project('sample3d')

            shot = Shot.get_by_code('RC_001_001')
            if not shot:
                shot = Shot.create('RC_001_001', 'Some test shot')
            asset = SearchType.create('prod/asset')
            asset.set_value('code','unittest010')
            asset.set_value('name','unittest010')
            asset.commit()
            for x in xrange(3):
                ShotInstance.create(shot, asset, 'unittest_veh_001', unique=False) 
            
            instances = ShotInstance.get_by_shot_and_asset(shot, asset)
            parent_type = 'prod/shot'
            parent_search = Search(parent_type)
            parent_search.add_filter('code','RC_001_001')
        
            search = Search('prod/shot_instance') 
            search.add_filter('asset_code', asset.get_code())
            # we want the base here
            sobject_type = search.get_search_type_obj().get_base_key()

            schema = Schema.get()
            relationship = schema.get_relationship(sobject_type, parent_type)
            parents = parent_search.get_sobjects()
            if parents:
                if relationship in ["code", "id", "search_type"]:
                    search.add_relationship_filters(parents) 
                    
            sobjects = search.get_sobjects()
            my.assertEquals(len(instances), len(sobjects))

            
            relationship_attrs = schema.get_relationship_attrs('sthpw/transaction_log','sthpw/sobject_log')
            rev_relationship_attrs = schema.get_relationship_attrs('sthpw/sobject_log','sthpw/transaction_log')
            for attrs in [ relationship_attrs,  rev_relationship_attrs]:
                my.assertEquals(attrs.get('from_col'), 'transaction_log_id')
                my.assertEquals(attrs.get('to_col'), 'id')
                my.assertEquals(attrs.get('from'), 'sthpw/sobject_log')
                my.assertEquals(attrs.get('to'), 'sthpw/transaction_log')
                my.assertEquals(attrs.get('relationship'), 'id')
                my.assertEquals(attrs.get('disabled'), None)


        Project.set_project('unittest')
Beispiel #2
0
    def _test_schema(my):
        # prod type test
        prod_proj_code = "sample3d"
        if Project.get_by_code(prod_proj_code):
            prod_schema = Schema.get_by_project_code(prod_proj_code)
            parent_type = prod_schema.get_parent_type('prod/asset')
            my.assertEquals('prod/asset_library', parent_type)

            parent_type = prod_schema.get_parent_type('prod/sequence')
            my.assertEquals('prod/episode', parent_type)

            parent_type = prod_schema.get_parent_type('prod/shot')
            my.assertEquals('prod/sequence', parent_type)

            parent_type = prod_schema.get_parent_type('sthpw/task')
            my.assertEquals('*', parent_type)

            parent_type = prod_schema.get_parent_type('sthpw/note')
            my.assertEquals('*', parent_type)

            parent_type = prod_schema.get_parent_type('prod/render')
            my.assertEquals('*', parent_type)

            parent_type = prod_schema.get_parent_type('prod/submission')
            my.assertEquals('*', parent_type)

        schema = Schema.get_by_project_code("unittest")
        # create a new search_type
        schema.add_search_type("unittest/car",
                               parent_type='unittest/person',
                               commit=False)

        schema.add_search_type("unittest/house",
                               parent_type='unittest/person',
                               commit=False)

        parent_type = schema.get_parent_type('unittest/city')
        my.assertEquals('unittest/country', parent_type)

        # get all of the child types
        child_types = schema.get_child_types('unittest/person')
        expected = ['unittest/person_in_car', 'unittest/house']
        my.assertEquals(True, expected[0] in child_types)
        my.assertEquals(True, expected[1] in child_types)

        # create a new schema that has the unittest as the parent
        new_schema = SearchType.create(Schema.SEARCH_TYPE)
        new_schema.set_value("code", "unittest/custom")
        new_schema_xml = '''
        <schema parent='unittest'>
        <search_type name='unittest/account'/>
        <connect from='unittest/person' to='unittest/account' type='hierarchy'/>
        <connect from='*' to='unittest/poof' type='hierarchy'/>
        </schema>
        '''
        new_schema.set_xml(new_schema_xml)

        # get search_types defined in this schema
        search_types = new_schema.get_search_types(hierarchy=False)
        my.assertEquals(1, len(search_types))

        # get all search_types
        search_types = new_schema.get_search_types()

        # add bunch of dummy initial tasks to the person
        initial_tasks = Task.add_initial_tasks(my.person, 'task')

        # check status_log static trigger
        single_task = initial_tasks[0]
        from pyasm.search import Search

        to_status = Search.eval('@GET(sthpw/status_log.to_status)',
                                sobjects=[single_task],
                                single=True)
        my.assertEquals(to_status, "Assignment")
        single_task.set_value('status', "Test Done")
        single_task.commit(triggers=True)

        ExpressionParser.clear_cache()
        to_status = Search.eval(
            "@GET(sthpw/status_log['@ORDER_BY','id desc'].to_status)",
            sobjects=[single_task],
            single=True)

        my.assertEquals(to_status, "Test Done")

        # get tasks with get_all_children()
        tasks = my.person.get_all_children("sthpw/task")
        my.assertEquals(len(initial_tasks), len(tasks))

        # get notes with get_all_children()
        Note.create(my.person, "test note", context='default')
        Note.create(my.person, "test note2", context='default2')
        notes = my.person.get_all_children("sthpw/note")
        my.assertEquals(2, len(notes))

        #relationship
        schema = Schema.get()
        if Project.get_by_code('sample3d'):
            relationship = schema.get_relationship('prod/asset',
                                                   'sthpw/snapshot')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/asset', 'sthpw/task')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

            relationship = schema.get_relationship('prod/shot', 'sthpw/note')
            my.assertEquals(relationship, 'search_code')
            #my.assertEquals(relationship, 'search_type')

        relationship = schema.get_relationship('sthpw/file', 'sthpw/snapshot')
        my.assertEquals(relationship, 'code')
        relationship = schema.get_relationship('sthpw/project_type',
                                               'sthpw/project')
        my.assertEquals(relationship, 'code')

        relationship = schema.get_relationship('unittest/car',
                                               'unittest/house')
        my.assertEquals(relationship, None)

        # test parent filter search in sample3d
        if Project.get_by_code('sample3d'):
            from pyasm.prod.biz import *
            Project.set_project('sample3d')

            shot = Shot.get_by_code('RC_001_001')
            if not shot:
                shot = Shot.create('RC_001_001', 'Some test shot')
            asset = SearchType.create('prod/asset')
            asset.set_value('code', 'unittest010')
            asset.set_value('name', 'unittest010')
            asset.commit()
            for x in xrange(3):
                ShotInstance.create(shot,
                                    asset,
                                    'unittest_veh_001',
                                    unique=False)

            instances = ShotInstance.get_by_shot_and_asset(shot, asset)
            parent_type = 'prod/shot'
            parent_search = Search(parent_type)
            parent_search.add_filter('code', 'RC_001_001')

            search = Search('prod/shot_instance')
            search.add_filter('asset_code', asset.get_code())
            # we want the base here
            sobject_type = search.get_search_type_obj().get_base_key()

            schema = Schema.get()
            relationship = schema.get_relationship(sobject_type, parent_type)
            parents = parent_search.get_sobjects()
            if parents:
                if relationship in ["code", "id", "search_type"]:
                    search.add_relationship_filters(parents)

            sobjects = search.get_sobjects()
            my.assertEquals(len(instances), len(sobjects))

            relationship_attrs = schema.get_relationship_attrs(
                'sthpw/transaction_log', 'sthpw/sobject_log')
            rev_relationship_attrs = schema.get_relationship_attrs(
                'sthpw/sobject_log', 'sthpw/transaction_log')
            for attrs in [relationship_attrs, rev_relationship_attrs]:
                my.assertEquals(attrs.get('from_col'), 'transaction_log_id')
                my.assertEquals(attrs.get('to_col'), 'id')
                my.assertEquals(attrs.get('from'), 'sthpw/sobject_log')
                my.assertEquals(attrs.get('to'), 'sthpw/transaction_log')
                my.assertEquals(attrs.get('relationship'), 'id')
                my.assertEquals(attrs.get('disabled'), None)

        Project.set_project('unittest')