mik-laj commented on a change in pull request #10081:
URL: https://github.com/apache/airflow/pull/10081#discussion_r464043248
##########
File path: tests/cli/commands/test_connection_command.py
##########
@@ -111,6 +112,112 @@ def test_cli_connections_include_secrets(self):
connection_command.connections_list(args)
+class TestCliExportConnections(unittest.TestCase):
+ @provide_session
+ def setUp(self, session=None):
+ clear_db_connections(add_default_connections_back=False)
+ merge_conn(
+ Connection(
+ conn_id="airflow_db",
+ conn_type="mysql",
+ host="mysql",
+ login="root",
+ password="",
+ schema="airflow",
+ ),
+ session
+ )
+ merge_conn(
+ Connection(
+ conn_id="druid_broker_default",
+ conn_type="druid",
+ host="druid-broker",
+ port=8082,
+ extra='{"endpoint": "druid/v2/sql"}',
+ ),
+ session
+ )
+
+ self.parser = cli_parser.get_parser()
+
+ @provide_session
+ def tearDown(self, session=None):
+ clear_db_connections(add_default_connections_back=False)
+
+ def test_cli_connections_export_as_json(self):
+ output_filepath = 'connections.json'
+ open_mock = mock.mock_open()
+
+ with mock.patch.object(connection_command, "open", open_mock):
+ args = self.parser.parse_args([
+ "connections",
+ "export",
+ "--format",
+ "json",
+ "--output-file",
+ output_filepath,
+ ])
+ connection_command.connections_export(args)
+
+ expected_connections = json.dumps({
+ "airflow_db": {
+ "conn_type": "mysql",
+ "host": "mysql",
+ "port": None,
+ "is_encrypted": False,
+ "is_extra_encrypted": False,
+ "extra": None
+ },
+ "druid_broker_default": {
+ "conn_type": "druid",
+ "host": "druid-broker",
+ "port": 8082,
+ "is_encrypted": False,
+ "is_extra_encrypted": False,
+ "extra": {
+ "endpoint": "druid/v2/sql",
+ }
+ }
+ })
+ open_mock.assert_called_with(output_filepath, "w")
+
open_mock.return_value.write.assert_called_once_with(expected_connections)
+
+ def test_cli_connections_export_as_yaml(self):
+ output_filepath = '/path/to/connections.yaml'
+ open_mock = mock.mock_open()
+
+ with mock.patch.object(connection_command, "open", open_mock):
+ args = self.parser.parse_args([
+ "connections",
+ "export",
+ "--format",
+ "yaml",
+ "--output-file",
+ output_filepath,
+ ])
+ connection_command.connections_export(args)
+
+ expected_connections = \
+"""airflow_db:
+ conn_type: mysql
+ extra: null
+ host: mysql
+ is_encrypted: false
+ is_extra_encrypted: false
+ port: null
+druid_broker_default:
+ conn_type: druid
+ extra:
Review comment:
I'm afraid that this field type is a string, so it cannot contain an
object. This will build us an object that LocalFilesystemBackend cannot load.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]