def test_get_store_dsn(self): settings = DatabaseSettings(address='address', username='******') self.assertEqual(settings.get_store_uri(), 'postgres://username@address:5432/stoq') self.assertEqual(settings.get_store_dsn(), 'dbname=stoq host=address port=5432 user=username')
def test_get_tool_args(self): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') self.assertEqual(settings.get_tool_args(), ['-U', 'username', '-h', 'address', '-p', '12345'])
def test_get_store_dsn_port(self): settings = DatabaseSettings(address='address', username='******', port='12345') self.assertEqual(settings.get_store_uri(), 'postgres://username@address:12345/stoq') self.assertEqual(settings.get_store_dsn(), 'dbname=stoq host=address port=12345 user=username')
def test_get_command_line_arguments(self): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') self.assertEqual(settings.get_command_line_arguments(), [ '-d', 'stoq', '-H', 'address', '-p', '12345', '-u', 'username', '-w', 'password' ])
def test_get_store_dsn_password(self): settings = DatabaseSettings(address='address', username='******', password='******') self.assertEquals(settings.get_store_uri(), 'postgres://*****:*****@address:5432/stoq') self.assertEquals( settings.get_store_dsn(), 'dbname=stoq host=address port=5432 user=username password=password')
def test_get_tool_args(self): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') self.assertEquals(settings.get_tool_args(), ['-U', 'username', '-h', 'address', '-p', '12345'])
def test_get_store_dsn_password(self): settings = DatabaseSettings(address='address', username='******', password='******') self.assertEqual(settings.get_store_uri(), 'postgres://*****:*****@address:5432/stoq') self.assertEqual( settings.get_store_dsn(), 'dbname=stoq host=address port=5432 user=username password=password' )
def test_create_super_store(self, create_database, StoqlibStore): settings = DatabaseSettings(address='localhost', username='******') store = settings.create_super_store() self.assertEqual(create_database.call_count, 1) uri = create_database.call_args[0][0] self.assertEquals( str(uri), 'postgres://username@localhost:5432/postgres?isolation=read-committed') self.assertEqual(StoqlibStore.call_count, 1) self.failUnless(store)
def test_get_command_line_arguments(self): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') self.assertEquals(settings.get_command_line_arguments(), ['-d', 'stoq', '-H', 'address', '-p', '12345', '-u', 'username', '-w', 'password'])
def test_create_super_store(self, create_database, StoqlibStore): settings = DatabaseSettings(address='localhost', username='******') store = settings.create_super_store() self.assertEqual(create_database.call_count, 1) uri = create_database.call_args[0][0] self.assertEqual( str(uri), 'postgres://username@localhost:5432/postgres?isolation=read-committed' ) self.assertEqual(StoqlibStore.call_count, 1) self.assertTrue(store)
def test_create_store(self, create_database, StoqlibStore): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') store = settings.create_store() self.assertEqual(create_database.call_count, 1) uri = create_database.call_args[0][0] self.assertEquals( str(uri), 'postgres://*****:*****@address:12345/stoq?isolation=read-committed') self.assertEqual(StoqlibStore.call_count, 1) self.failUnless(store)
def test_create_store(self, create_database, StoqlibStore): settings = DatabaseSettings(address='address', username='******', password='******', port='12345') store = settings.create_store() self.assertEqual(create_database.call_count, 1) uri = create_database.call_args[0][0] self.assertEqual( str(uri), 'postgres://*****:*****@address:12345/stoq?isolation=read-committed' ) self.assertEqual(StoqlibStore.call_count, 1) self.assertTrue(store)
def test_get_store_dsn_no_host(self, tld): settings = DatabaseSettings(address='address', username='******') # Force address to be empty, just like when we connect using # the unix socket settings.address = '' tld.return_value = None with self.assertRaisesRegex( DatabaseError, "Could not find a database server on this computer"): settings.get_store_dsn() tld.return_value = ('<unix_socket>', 1234) self.assertEqual(settings.get_store_dsn(), 'dbname=stoq host=<unix_socket> port=1234 user=username')
def test_create_store_localhost(self, test_local_database, create_database, StoqlibStore): # FIXME: This should not be necessary, instead DatabaseSettings should # do if address is not None to differenciate between '' and None os.environ.pop('PGHOST', None) test_local_database.return_value = ('/var/run/postgresql', '5432') settings = DatabaseSettings(address='', username='******') store = settings.create_store() self.assertEqual(create_database.call_count, 1) test_local_database.called_once_with() uri = create_database.call_args[0][0] self.assertEqual(uri.host, '/var/run/postgresql') self.assertEqual(uri.port, 5432) self.assertEqual( str(uri), 'postgres://username@%2Fvar%2Frun%2Fpostgresql:5432/stoq?isolation=read-committed' ) self.assertEqual(StoqlibStore.call_count, 1) self.assertTrue(store)
def test_create_store_localhost(self, test_local_database, create_database, StoqlibStore): # FIXME: This should not be necessary, instead DatabaseSettings should # do if address is not None to differenciate between '' and None os.environ.pop('PGHOST', None) test_local_database.return_value = ('/var/run/postgresql', '5432') settings = DatabaseSettings(address='', username='******') store = settings.create_store() self.assertEqual(create_database.call_count, 1) test_local_database.called_once_with() uri = create_database.call_args[0][0] self.assertEquals(uri.host, '/var/run/postgresql') self.assertEquals(uri.port, 5432) self.assertEquals( str(uri), 'postgres://username@%2Fvar%2Frun%2Fpostgresql:5432/stoq?isolation=read-committed') self.assertEqual(StoqlibStore.call_count, 1) self.failUnless(store)
def create_wizard(self): options = mock.Mock() options.sqldebug = False options.verbose = False if self.settings is None: self.settings = DatabaseSettings(address=u'localhost', port=12345, dbname=u'dbname', username=u'username', password=u'password') self.settings.has_database = lambda: False self.config = self.fake.StoqConfig(self.settings) wizard = FirstTimeConfigWizard(options, self.config) return wizard
def test_get_store_dsn_no_host(self, tld): settings = DatabaseSettings(address='address', username='******') # Force address to be empty, just like when we connect using # the unix socket settings.address = '' tld.return_value = None with self.assertRaisesRegex( DatabaseError, "Could not find a database server on this computer"): settings.get_store_dsn() tld.return_value = ('<unix_socket>', 1234) self.assertEqual( settings.get_store_dsn(), 'dbname=stoq host=<unix_socket> port=1234 user=username')
def test_get_store_dsn(self): settings = DatabaseSettings(address='address', username='******') self.assertEquals(settings.get_store_uri(), 'postgres://username@address:5432/stoq') self.assertEquals(settings.get_store_dsn(), 'dbname=stoq host=address port=5432 user=username')
def test_get_store_dsn(self): settings = DatabaseSettings(address='address', username='******') self.assertEquals(settings.get_store_dsn(), 'postgres://username@address:5432/stoq')
def test_get_store_dsn_password(self): settings = DatabaseSettings(address='address', username='******', password='******') self.assertEquals(settings.get_store_dsn(), 'postgres://*****:*****@address:5432/stoq')