<s> import unittest <EOL> from sqlalchemy . engine import create_engine <EOL> from sqlalchemy . orm . session import sessionmaker <EOL> from geeknote import storage <EOL> import pickle <EOL> def hacked_init ( self ) : <EOL> '''<STR_LIT>''' <EOL> engine = create_engine ( '<STR_LIT>' , echo = False ) <EOL> storage . Base . metadata . create_all ( engine ) <EOL> Session = sessionmaker ( bind = engine ) <EOL> self . session = Session ( ) <EOL> class storageTest ( unittest . TestCase ) : <EOL> def setUp ( self ) : <EOL> stor = storage . Storage <EOL> stor . __init__ = hacked_init <EOL> self . storage = stor ( ) <EOL> self . otoken = '<STR_LIT>' <EOL> self . userinfo = { '<STR_LIT:email>' : '<STR_LIT>' } <EOL> self . tags = { u'<STR_LIT>' : <NUM_LIT:1> , u'<STR_LIT>' : <NUM_LIT:2> , u'<STR_LIT>' : '<STR_LIT>' } <EOL> self . notebooks = { u'<STR_LIT>' : u'<STR_LIT>' } <EOL> self . storage . createUser ( self . otoken , <EOL> self . userinfo ) <EOL> def test_create_user_without_token_fail ( self ) : <EOL> self . assertFalse ( self . storage . createUser ( None , self . userinfo ) ) <EOL> def test_create_user_without_info_fail ( self ) : <EOL> self . assertFalse ( self . storage . createUser ( self . otoken , None ) ) <EOL> def test_remove_user_success ( self ) : <EOL> self . assertTrue ( self . storage . removeUser ( ) ) <EOL> def test_get_user_token_success ( self ) : <EOL> self . assertEquals ( self . storage . getUserToken ( ) , self . otoken ) <EOL> def test_get_user_info_success ( self ) : <EOL> self . assertEquals ( self . storage . getUserInfo ( ) , self . userinfo ) <EOL> def test_get_user_props_success ( self ) : <EOL> props = [ { u'<STR_LIT>' : '<STR_LIT>' } , <EOL> { u'<STR_LIT:info>' : { '<STR_LIT:email>' : '<STR_LIT>' } } ] <EOL> self . assertEquals ( self . storage . getUserprops ( ) , props ) <EOL> def test_get_user_props_exists_success ( self ) : <EOL> self . assertEquals ( self . storage . getUserprop ( '<STR_LIT:info>' ) , <EOL> self . userinfo ) <EOL> def test_get_user_prop_not_exists ( self ) : <EOL> self . assertFalse ( self . storage . getUserprop ( '<STR_LIT>' ) ) <EOL> def test_set_new_user_prop ( self ) : <EOL> self . assertFalse ( self . storage . getUserprop ( '<STR_LIT>' ) ) <EOL> self . assertTrue ( self . storage . setUserprop ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> self . assertEquals ( self . storage . getUserprop ( '<STR_LIT>' ) , '<STR_LIT>' ) <EOL> def test_set_exists_user_prop ( self ) : <EOL> newmail = { '<STR_LIT:email>' : '<STR_LIT>' } <EOL> self . assertEquals ( self . storage . getUserprop ( '<STR_LIT:info>' ) , self . userinfo ) <EOL> self . assertTrue ( self . storage . setUserprop ( '<STR_LIT:info>' , newmail ) , newmail ) <EOL> self . assertEquals ( self . storage . getUserprop ( '<STR_LIT:info>' ) , newmail ) <EOL> def test_get_empty_settings ( self ) : <EOL> self . assertEquals ( self . storage . getSettings ( ) , { } ) <EOL> def test_set_settings_success ( self ) : <EOL> self . storage . setSettings ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertEquals ( self . storage . getSettings ( ) , <EOL> { u'<STR_LIT>' : u"<STR_LIT>" } ) <EOL> def test_set_setting_error_type_fail ( self ) : <EOL> self . assertFalse ( self . storage . setSettings ( '<STR_LIT>' ) ) <EOL> def test_set_setting_none_value_fail ( self ) : <EOL> self . assertFalse ( self . storage . setSettings ( { '<STR_LIT:key>' : None } ) ) <EOL> def test_update_settings_fail ( self ) : <EOL> self . storage . setSettings ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertTrue ( self . storage . setSettings ( { '<STR_LIT>' : '<STR_LIT>' } ) ) <EOL> self . assertEquals ( self . storage . getSettings ( ) , <EOL> { u'<STR_LIT>' : u"<STR_LIT>" } ) <EOL> def test_get_setting_exist_success ( self ) : <EOL> self . storage . setSettings ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> editor = self . storage . getSetting ( '<STR_LIT>' ) <EOL> self . assertEquals ( pickle . loads ( editor ) , '<STR_LIT>' ) <EOL> def test_set_setting_true ( self ) : <EOL> editor = '<STR_LIT>' <EOL> self . assertTrue ( self . storage . setSetting ( '<STR_LIT>' , editor ) ) <EOL> self . assertEquals ( self . storage . getSetting ( '<STR_LIT>' ) , editor ) <EOL> def test_get_setting_not_exist_fail ( self ) : <EOL> self . assertFalse ( self . storage . getSetting ( '<STR_LIT>' ) ) <EOL> def test_set_tags_success ( self ) : <EOL> self . assertTrue ( self . storage . setTags ( self . tags ) ) <EOL> def test_set_tags_error_type_fail ( self ) : <EOL> self . assertFalse ( self . storage . setTags ( '<STR_LIT>' ) ) <EOL> def test_set_tags_none_value_fail ( self ) : <EOL> self . assertFalse ( self . storage . setTags ( { '<STR_LIT>' : None } ) ) <EOL> def test_get_tags_success ( self ) : <EOL> tags = { u'<STR_LIT>' : u'<STR_LIT:1>' , u'<STR_LIT>' : u'<STR_LIT:2>' , u'<STR_LIT>' : u'<STR_LIT>' } <EOL> self . assertTrue ( self . storage . setTags ( self . tags ) ) <EOL> self . assertEquals ( self . storage . getTags ( ) , tags ) <EOL> def test_replace_tags_success ( self ) : <EOL> tags = { u'<STR_LIT>' : u'<STR_LIT:1>' , u'<STR_LIT>' : u'<STR_LIT:2>' , u'<STR_LIT>' : u'<STR_LIT:3>' } <EOL> self . assertTrue ( self . storage . setTags ( self . tags ) ) <EOL> self . tags [ u'<STR_LIT>' ] = <NUM_LIT:3> <EOL> self . assertTrue ( self . storage . setTags ( self . tags ) ) <EOL> self . assertEquals ( self . storage . getTags ( ) , tags ) <EOL> def test_set_notebooks_success ( self ) : <EOL> self . assertEquals ( self . storage . getNotebooks ( ) , { } ) <EOL> self . storage . setNotebooks ( self . notebooks ) <EOL> self . assertEquals ( self . storage . getNotebooks ( ) , self . notebooks ) <EOL> def test_replace_notebooks_success ( self ) : <EOL> newnotebooks = { u'<STR_LIT>' : u'<STR_LIT>' } <EOL> self . storage . setNotebooks ( self . notebooks ) <EOL> self . storage . setNotebooks ( newnotebooks ) <EOL> self . assertEquals ( self . storage . getNotebooks ( ) , newnotebooks ) <EOL> def test_get_empty_search_success ( self ) : <EOL> self . assertFalse ( self . storage . getSearch ( ) ) <EOL> def test_get_search_exists_success ( self ) : <EOL> query = '<STR_LIT>' <EOL> self . assertTrue ( self . storage . setSearch ( query ) ) <EOL> self . assertEquals ( self . storage . getSearch ( ) , query ) <EOL> def test_set_notebooks_error_type_fail ( self ) : <EOL> self . assertFalse ( self . storage . setNotebooks ( '<STR_LIT>' ) ) <EOL> def test_set_notebooks_none_value_fail ( self ) : <EOL> self . assertFalse ( self . storage . setNotebooks ( { '<STR_LIT>' : None } ) ) <EOL> def test_set_search_true ( self ) : <EOL> self . assertTrue ( self . storage . setSearch ( '<STR_LIT>' ) ) <EOL> class modelsTest ( unittest . TestCase ) : <EOL> def test_rept_userprop ( self ) : <EOL> userprop = storage . Userprop ( key = '<STR_LIT:test>' , <EOL> value = '<STR_LIT:value>' ) <EOL> self . assertEquals ( userprop . __repr__ ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_repr_setting ( self ) : <EOL> setting = storage . Setting ( key = '<STR_LIT:test>' , <EOL> value = '<STR_LIT:value>' ) <EOL> self . assertEquals ( setting . __repr__ ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_repr_notebook ( self ) : <EOL> notebook = storage . Notebook ( name = '<STR_LIT>' , <EOL> guid = '<STR_LIT>' ) <EOL> self . assertEquals ( notebook . __repr__ ( ) , <EOL> "<STR_LIT>" ) <EOL> def test_repr_tag ( self ) : <EOL> tag = storage . Tag ( tag = '<STR_LIT>' , <EOL> guid = '<STR_LIT>' ) <EOL> self . assertEquals ( tag . __repr__ ( ) , "<STR_LIT>" ) <EOL> def test_repr_search ( self ) : <EOL> search = storage . Search ( search_obj = '<STR_LIT>' ) <EOL> self . assertEquals ( search . __repr__ ( ) , <EOL> "<STR_LIT>" % search . timestamp ) </s>
