def test_autocomplete(self): """Tests the autocomplete function""" self.assertEqual( 'user@host/db/', dbc.PostgreSQLConnection( 'uri', 'host', '3333', 'db', 'user', 'password' ).autocomplete()) self.assertEqual( 'user@host/', dbc.PostgreSQLConnection( 'uri', 'host', '3333', None, 'user', 'password' ).autocomplete())
def test_filter(self): """Tests the filter function""" self.assertEqual( True, dbc.PostgreSQLConnection( 'uri', 'host', '3333', 'db', 'user', 'password' ).filter_(Config.init(['user@host/db/'], navigator.args.parser))) self.assertEqual( False, dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ).filter_({'postgresql': Opts(user='******', host=None)}))
def test_subtitle(self): """Tests the subtitle function""" self.assertEqual( 'PostgreSQL Connection', dbc.PostgreSQLConnection( 'uri', 'host', '3333', 'db', 'user', 'password' ).subtitle())
def test_repr(self): """Tests the repr method""" con = dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ) self.assertEqual(repr(con), con.__repr__())
def test_matches(self): """Tests the matches method""" self.assertEqual( False, dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ).matches(Opts(gen='foo@bar')))
def test_init_tables(self): """Tests the init_tables method""" self.assertRaises( Exception, dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ).init_tables, [None])
def test_connect(self): """Tests the connect function""" self.assertRaises( InterfaceError, dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ).connect, [None]) self.assertEqual( None, dbc.PostgreSQLConnection( MOCK_URI.format( file=path.join(MOCK_DIR, '../resources/dbmanagr.sqlite')), 'host', '3333', 'db', 'user', 'password' ).connect(None)) self.assertEqual( None, dbc.PostgreSQLConnection( MOCK_URI.format( file=path.join(MOCK_DIR, '../resources/dbmanagr.sqlite')), 'host', '3333', 'db', 'user', 'password' ).connect(None)) self.assertEqual( None, dbc.PostgreSQLConnection( MOCK_URI.format( file=path.join( MOCK_DIR, '../resources/dbmanagr.sqlite')), 'host', '3333', 'db', 'user', 'password' ).connect('db')) self.assertEqual( None, dbc.PostgreSQLConnection( MOCK_URI.format( file=path.join( MOCK_DIR, '../resources/{database}/dbmanagr.sqlite')), 'host', '3333', 'db', 'user', 'password' ).connect('db'))
def test_databases(self): """Tests the databases function""" con = dbc.PostgreSQLConnection( 'postgresql+pg8000://{user}:{password}@{host}/{database}', 'host', '3333', 'db', 'user', 'password' ) self.assertRaises( Exception, con.databases) con._databases = [] self.assertEqual( [], con.databases())