<s> try : <EOL> from configparser import ConfigParser , NoOptionError <EOL> except ImportError : <EOL> from ConfigParser import ConfigParser , NoOptionError <EOL> import unittest <EOL> from ofxclient . config import SecurableConfigParser <EOL> def makeConfig ( keyring_available = True , ** kwargs ) : <EOL> conf = None <EOL> conf = SecurableConfigParser ( keyring_available = keyring_available , ** kwargs ) <EOL> conf . add_section ( '<STR_LIT>' ) <EOL> conf . add_section ( '<STR_LIT>' ) <EOL> conf . set ( '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT>' ) <EOL> conf . set_secure ( '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> conf . set ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> conf . set_secure ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> return conf <EOL> class IdentifySecureOptionTests ( unittest . TestCase ) : <EOL> def testIsSecureOption ( self ) : <EOL> c = makeConfig ( ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:username>' ) ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> def testStaysSecure ( self ) : <EOL> c = makeConfig ( ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> c . set ( '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> def testStaysUnsecure ( self ) : <EOL> c = makeConfig ( ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:username>' ) ) <EOL> c . set ( '<STR_LIT>' , '<STR_LIT:username>' , '<STR_LIT>' ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:username>' ) ) <EOL> def testSetThenSetSecureTurnsSecure ( self ) : <EOL> c = makeConfig ( ) <EOL> c . set ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> c . set_secure ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> c . set ( '<STR_LIT>' , '<STR_LIT:foo>' , '<STR_LIT:bar>' ) <EOL> self . assertTrue ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:foo>' ) ) <EOL> def testItemsHavePasswords ( self ) : <EOL> c = makeConfig ( ) <EOL> items = sorted ( c . items ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( <EOL> items , <EOL> [ ( '<STR_LIT:password>' , '<STR_LIT>' ) , ( '<STR_LIT:username>' , '<STR_LIT>' ) ] <EOL> ) <EOL> self . assertEqual ( len ( items ) , <NUM_LIT:2> ) <EOL> def testSecureItems ( self ) : <EOL> c = makeConfig ( ) <EOL> items = sorted ( c . secure_items ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( items , [ ( '<STR_LIT:password>' , '<STR_LIT>' ) ] ) <EOL> self . assertEqual ( len ( items ) , <NUM_LIT:1> ) <EOL> c . remove_option ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> items = sorted ( c . secure_items ( '<STR_LIT>' ) ) <EOL> self . assertEqual ( len ( items ) , <NUM_LIT:0> ) <EOL> def testGet ( self ) : <EOL> c = makeConfig ( ) <EOL> self . assertEqual ( c . get ( '<STR_LIT>' , '<STR_LIT:password>' ) , '<STR_LIT>' ) <EOL> self . assertNotEqual ( <EOL> ConfigParser . get ( c , '<STR_LIT>' , '<STR_LIT:password>' ) , <EOL> '<STR_LIT>' <EOL> ) <EOL> self . assertEqual ( c . get ( '<STR_LIT>' , '<STR_LIT:username>' ) , '<STR_LIT>' ) <EOL> c . remove_option ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . assertRaises ( NoOptionError , c . get , '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> def testUnsavedOptions ( self ) : <EOL> c = makeConfig ( ) <EOL> s_option = "<STR_LIT>" % ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> c . set ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertFalse ( s_option in c . _unsaved ) <EOL> c . remove_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertFalse ( s_option in c . _unsaved ) <EOL> c . set_secure ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( s_option in c . _unsaved ) <EOL> self . assertTrue ( c . _unsaved [ s_option ] [ <NUM_LIT:0> ] == '<STR_LIT>' ) <EOL> self . assertTrue ( c . _unsaved [ s_option ] [ <NUM_LIT:1> ] == '<STR_LIT>' ) <EOL> c . remove_option ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> self . assertTrue ( s_option in c . _unsaved ) <EOL> self . assertTrue ( c . _unsaved [ s_option ] [ <NUM_LIT:0> ] == '<STR_LIT>' ) <EOL> self . assertTrue ( c . _unsaved [ s_option ] [ <NUM_LIT:1> ] is None ) <EOL> def testKeyringOffSet ( self ) : <EOL> c = makeConfig ( keyring_available = False ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:username>' ) ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> self . assertEqual ( c . _unsaved , { } ) <EOL> c . set_secure ( '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> self . assertEqual ( c . get ( '<STR_LIT>' , '<STR_LIT:password>' ) , '<STR_LIT>' ) <EOL> self . assertEqual ( c . get ( '<STR_LIT>' , '<STR_LIT:username>' ) , '<STR_LIT>' ) <EOL> c . remove_option ( '<STR_LIT>' , '<STR_LIT:password>' ) <EOL> self . assertFalse ( c . is_secure_option ( '<STR_LIT>' , '<STR_LIT:password>' ) ) <EOL> self . assertEqual ( c . _unsaved , { } ) <EOL> pass </s>
