<s> import mock <EOL> from sahara . tests . unit import base <EOL> from sahara . utils import general <EOL> class UtilsGeneralTest ( base . SaharaWithDbTestCase ) : <EOL> def setUp ( self ) : <EOL> super ( UtilsGeneralTest , self ) . setUp ( ) <EOL> def test_find_dict ( self ) : <EOL> iterable = [ <EOL> { <EOL> "<STR_LIT:a>" : <NUM_LIT:1> <EOL> } , <EOL> { <EOL> "<STR_LIT:a>" : <NUM_LIT:1> , <EOL> "<STR_LIT:b>" : <NUM_LIT:2> , <EOL> "<STR_LIT:c>" : <NUM_LIT:3> <EOL> } , <EOL> { <EOL> "<STR_LIT:a>" : <NUM_LIT:2> <EOL> } , <EOL> { <EOL> "<STR_LIT:c>" : <NUM_LIT:3> <EOL> } <EOL> ] <EOL> self . assertEqual ( { "<STR_LIT:a>" : <NUM_LIT:1> , "<STR_LIT:b>" : <NUM_LIT:2> , "<STR_LIT:c>" : <NUM_LIT:3> } , <EOL> general . find_dict ( iterable , a = <NUM_LIT:1> , b = <NUM_LIT:2> ) ) <EOL> self . assertIsNone ( general . find_dict ( iterable , z = <NUM_LIT:4> ) ) <EOL> def test_find ( self ) : <EOL> lst = [ mock . Mock ( a = <NUM_LIT:5> ) , mock . Mock ( b = <NUM_LIT:5> ) , mock . Mock ( a = <NUM_LIT:7> , b = <NUM_LIT:7> ) ] <EOL> self . assertEqual ( lst [ <NUM_LIT:0> ] , general . find ( lst , a = <NUM_LIT:5> ) ) <EOL> self . assertEqual ( lst [ <NUM_LIT:1> ] , general . find ( lst , b = <NUM_LIT:5> ) ) <EOL> self . assertIsNone ( general . find ( lst , a = <NUM_LIT:8> ) ) <EOL> self . assertEqual ( lst [ <NUM_LIT:2> ] , general . find ( lst , a = <NUM_LIT:7> ) ) <EOL> self . assertEqual ( lst [ <NUM_LIT:2> ] , general . find ( lst , a = <NUM_LIT:7> , b = <NUM_LIT:7> ) ) <EOL> def test_generate_instance_name ( self ) : <EOL> inst_name = "<STR_LIT>" <EOL> self . assertEqual ( <EOL> inst_name , general . generate_instance_name ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> self . assertEqual ( <EOL> inst_name , general . generate_instance_name ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT:1> ) ) <EOL> def test_get_by_id ( self ) : <EOL> lst = [ mock . Mock ( id = <NUM_LIT:5> ) , mock . Mock ( id = <NUM_LIT:7> ) ] <EOL> self . assertIsNone ( general . get_by_id ( lst , <NUM_LIT:9> ) ) <EOL> self . assertEqual ( lst [ <NUM_LIT:0> ] , general . get_by_id ( lst , <NUM_LIT:5> ) ) <EOL> self . assertEqual ( lst [ <NUM_LIT:1> ] , general . get_by_id ( lst , <NUM_LIT:7> ) ) </s>
