#NEWLINE# @ mock . patch ( 'sahara.db.sqlalchemy.api._get_regex_op' ) #NEWLINE# def test_regex_filter( self , get_regex_op ) : #NEWLINE# #INDENT# query = api . model_query ( m . ClusterTemplate , context . ctx ( ) ) #NEWLINE# regex_cols = [ 'name' , 'description' , 'plugin_name' ] #NEWLINE# search_opts = { #NEWLINE# #INDENT# 'name' : 'fred' , #NEWLINE# 'hadoop_version' : '2' , #NEWLINE# 'bogus' : 'jack' , #NEWLINE# 'plugin_name' : 'vanilla' , #NEWLINE# #UNINDENT# } #NEWLINE# get_regex_op . return_value = None #NEWLINE# ( query , remaining_opts ) = api . regex_filter ( query , m . ClusterTemplate , regex_cols , search_opts ) #NEWLINE# self . assertEqual ( search_opts , remaining_opts ) #NEWLINE# self . assertIsNot ( search_opts , remaining_opts ) #NEWLINE# get_regex_op . return_value = 'REGEXP' #NEWLINE# ( query , remaining_opts ) = api . regex_filter ( query , m . ClusterTemplate , [ ] , search_opts ) #NEWLINE# self . assertEqual ( search_opts , remaining_opts ) #NEWLINE# self . assertIsNot ( search_opts , remaining_opts ) #NEWLINE# get_regex_op . return_value = 'REGEXP' #NEWLINE# ( query , remaining_opts ) = api . regex_filter ( query , m . ClusterTemplate , regex_cols , search_opts ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'hadoop_version' : '2' , #NEWLINE# 'bogus' : 'jack' , #NEWLINE# #UNINDENT# } , remaining_opts ) #NEWLINE# regex_cols . append ( 'bogus' ) #NEWLINE# ( query , remaining_opts ) = api . regex_filter ( query , m . ClusterTemplate , regex_cols , search_opts ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'hadoop_version' : '2' , #NEWLINE# 'bogus' : 'jack' , #NEWLINE# #UNINDENT# } , remaining_opts ) #NEWLINE# search_opts [ 'name' ] = 5 #NEWLINE# ( query , remaining_opts ) = api . regex_filter ( query , m . ClusterTemplate , regex_cols , search_opts ) #NEWLINE# self . assertEqual ( { #NEWLINE# #INDENT# 'hadoop_version' : '2' , #NEWLINE# 'bogus' : 'jack' , #NEWLINE# 'name' : 5 , #NEWLINE# #UNINDENT# } , remaining_opts )