<s> from st2tests . base import CleanDbTestCase <EOL> from st2common . models . db . keyvalue import KeyValuePairDB <EOL> from st2common . persistence . keyvalue import KeyValuePair <EOL> from st2common . services . keyvalues import KeyValueLookup <EOL> class TestKeyValueLookup ( CleanDbTestCase ) : <EOL> def test_non_hierarchical_lookup ( self ) : <EOL> k1 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k2 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k3 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> lookup = KeyValueLookup ( ) <EOL> self . assertEquals ( str ( lookup . k1 ) , k1 . value ) <EOL> self . assertEquals ( str ( lookup . k2 ) , k2 . value ) <EOL> self . assertEquals ( str ( lookup . k3 ) , k3 . value ) <EOL> def test_hierarchical_lookup_dotted ( self ) : <EOL> k1 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k2 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k3 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> lookup = KeyValueLookup ( ) <EOL> self . assertEquals ( str ( lookup . a . b ) , k1 . value ) <EOL> self . assertEquals ( str ( lookup . a . b . c ) , k2 . value ) <EOL> self . assertEquals ( str ( lookup . b . c ) , k3 . value ) <EOL> self . assertEquals ( str ( lookup . a ) , '<STR_LIT>' ) <EOL> def test_hierarchical_lookup_dict ( self ) : <EOL> k1 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k2 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> k3 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> lookup = KeyValueLookup ( ) <EOL> self . assertEquals ( str ( lookup [ '<STR_LIT:a>' ] [ '<STR_LIT:b>' ] ) , k1 . value ) <EOL> self . assertEquals ( str ( lookup [ '<STR_LIT:a>' ] [ '<STR_LIT:b>' ] [ '<STR_LIT:c>' ] ) , k2 . value ) <EOL> self . assertEquals ( str ( lookup [ '<STR_LIT:b>' ] [ '<STR_LIT:c>' ] ) , k3 . value ) <EOL> self . assertEquals ( str ( lookup [ '<STR_LIT:a>' ] ) , '<STR_LIT>' ) <EOL> def test_missing_key_lookup ( self ) : <EOL> lookup = KeyValueLookup ( ) <EOL> self . assertEquals ( str ( lookup . missing_key ) , '<STR_LIT>' ) <EOL> self . assertTrue ( lookup . missing_key , '<STR_LIT>' ) <EOL> def test_secret_lookup ( self ) : <EOL> secret_value = '<STR_LIT>' + '<STR_LIT>' <EOL> k1 = KeyValuePair . add_or_update ( KeyValuePairDB ( <EOL> name = '<STR_LIT>' , value = secret_value , <EOL> secret = True , encrypted = True ) <EOL> ) <EOL> k2 = KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) <EOL> lookup = KeyValueLookup ( ) <EOL> self . assertEquals ( str ( lookup . k1 ) , k1 . value ) <EOL> self . assertEquals ( str ( lookup . k2 ) , k2 . value ) </s>
