def test_expand_references():
    'Test that references are expanded from serialized cache.'
    cache_path = os.path.join(tempfile.gettempdir(), '{0}.dbm'.format(uuid.uuid4().hex))

    def make_cache(session, cache_path):
        'Create a serialised file cache.'
        serialized_file_cache = ftrack_api.cache.SerialisedCache(ftrack_api.cache.FileCache(cache_path), encode=session.encode, decode=session.decode)
        return serialized_file_cache
    session = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    expanded_results = dict()
    query_string = 'select asset.parent from AssetVersion where asset is_not None limit 10'
    for sequence in session.query(query_string):
        asset = sequence.get('asset')
        expanded_results.setdefault(asset.get('id'), asset.get('parent'))
    new_session = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    new_session_two = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    for sequence in new_session.query(query_string):
        asset = sequence.get('asset')
        assert (asset.get('parent') == expanded_results[asset.get('id')])
        assert (new_session_two.get(asset.entity_type, asset.get('id')).get('parent') == expanded_results[asset.get('id')])
Test that references are expanded from serialized cache.
def test_expand_references():
    
    cache_path = os.path.join(tempfile.gettempdir(), '{0}.dbm'.format(uuid.uuid4().hex))

    def make_cache(session, cache_path):
        'Create a serialised file cache.'
        serialized_file_cache = ftrack_api.cache.SerialisedCache(ftrack_api.cache.FileCache(cache_path), encode=session.encode, decode=session.decode)
        return serialized_file_cache
    session = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    expanded_results = dict()
    query_string = 'select asset.parent from AssetVersion where asset is_not None limit 10'
    for sequence in session.query(query_string):
        asset = sequence.get('asset')
        expanded_results.setdefault(asset.get('id'), asset.get('parent'))
    new_session = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    new_session_two = ftrack_api.Session(cache=(lambda session, cache_path=cache_path: make_cache(session, cache_path)))
    for sequence in new_session.query(query_string):
        asset = sequence.get('asset')
        assert (asset.get('parent') == expanded_results[asset.get('id')])
        assert (new_session_two.get(asset.entity_type, asset.get('id')).get('parent') == expanded_results[asset.get('id')])