def test_enable_postgis(self, mock_dump_cmd): connector = PgDumpGisConnector() connector.settings['ADMIN_USER'] = '******' connector._enable_postgis() self.assertIn('"CREATE EXTENSION IF NOT EXISTS postgis;"', mock_dump_cmd.call_args[0][0]) self.assertIn('--username=foo', mock_dump_cmd.call_args[0][0])
def test_enable_postgis_port(self, mock_dump_cmd): connector = PgDumpGisConnector() connector.settings['ADMIN_USER'] = '******' # Without connector.settings.pop('PORT', None) connector._enable_postgis() self.assertNotIn(' --port=', mock_dump_cmd.call_args[0][0]) # With connector.settings['PORT'] = 42 connector._enable_postgis() self.assertIn(' --port=42', mock_dump_cmd.call_args[0][0])
class PgDumpGisConnectorTest(TestCase): def setUp(self): self.connector = PgDumpGisConnector() self.connector.settings['HOST'] = 'hostname' @patch('dbbackup.db.postgresql.PgDumpGisConnector.run_command', return_value=(BytesIO(b'foo'), BytesIO())) def test_restore_dump(self, mock_dump_cmd, mock_restore_cmd): dump = self.connector.create_dump() # Without ADMINUSER self.connector.settings.pop('ADMIN_USER', None) self.connector.restore_dump(dump) self.assertTrue(mock_restore_cmd.called) # With self.connector.settings['ADMIN_USER'] = '******' self.connector.restore_dump(dump) self.assertTrue(mock_restore_cmd.called) def test_enable_postgis(self, mock_dump_cmd): self.connector.settings['ADMIN_USER'] = '******' self.connector._enable_postgis() self.assertIn('"CREATE EXTENSION IF NOT EXISTS postgis;"', mock_dump_cmd.call_args[0][0]) self.assertIn('--username=foo', mock_dump_cmd.call_args[0][0]) def test_enable_postgis_host(self, mock_dump_cmd): self.connector.settings['ADMIN_USER'] = '******' # Without self.connector.settings.pop('HOST', None) self.connector._enable_postgis() self.assertNotIn(' --host=', mock_dump_cmd.call_args[0][0]) # With self.connector.settings['HOST'] = 'foo' self.connector._enable_postgis() self.assertIn(' --host=foo', mock_dump_cmd.call_args[0][0]) def test_enable_postgis_port(self, mock_dump_cmd): self.connector.settings['ADMIN_USER'] = '******' # Without self.connector.settings.pop('PORT', None) self.connector._enable_postgis() self.assertNotIn(' --port=', mock_dump_cmd.call_args[0][0]) # With self.connector.settings['PORT'] = 42 self.connector._enable_postgis() self.assertIn(' --port=42', mock_dump_cmd.call_args[0][0])
def test_enable_postgis(self, mock_dump_cmd): connector = PgDumpGisConnector() connector.settings['ADMIN_USER'] = '******' connector._enable_postgis() self.assertIn('"CREATE EXTENSION IF NOT EXISTS postgis;"', mock_dump_cmd.call_args[0][0]) self.assertIn('--user=foo', mock_dump_cmd.call_args[0][0])