Prab-27 commented on code in PR #75177:
URL: https://github.com/apache/airflow/pull/75177#discussion_r4431602926
##########
airflow-ctl/tests/airflow_ctl/ctl/test_cli_config.py:
##########
@@ -939,6 +943,66 @@ def
test_clear_task_instances_body_accepts_parsed_list_fields(self):
assert [str(ti_id) for ti_id in body.task_instance_ids.root] ==
[UUID_A, UUID_B]
assert [str(ti_id) for ti_id in body.whole_expansion_ids] == [UUID_A]
+ def test_validate_datamodel_returns_model_for_valid_params(self):
+ """Test _validate_datamodel returns the validated datamodel when all
required fields are given."""
+ command_factory = CommandFactory()
+ body = command_factory._validate_datamodel(
+ ConnectionBody, {"connection_id": "my_conn", "conn_type": "http"}
+ )
+
+ assert isinstance(body, ConnectionBody)
+ assert body.connection_id == "my_conn"
+ assert body.conn_type == "http"
+
+ def test_validate_datamodel_reports_missing_required_fields_as_flags(self):
+ """Test missing required fields are reported as CLI flags instead of a
pydantic traceback."""
+ command_factory = CommandFactory()
+ with pytest.raises(SystemExit) as ctx:
+ command_factory._validate_datamodel(ConnectionBody,
{"connection_id": None, "conn_type": None})
+
+ message = str(ctx.value)
+ assert "the following arguments are required: --connection-id,
--conn-type" in message
+ assert "ValidationError" not in message
+
+ def
test_validate_datamodel_does_not_report_optional_fields_as_missing(self):
+ """Test an unset optional field is not reported as a missing
argument."""
+ command_factory = CommandFactory()
+ with pytest.raises(SystemExit) as ctx:
+ command_factory._validate_datamodel(
+ ConnectionBody, {"connection_id": "my_conn", "conn_type":
None, "host": None}
+ )
+
+ message = str(ctx.value)
+ assert "--conn-type" in message
+ assert "--connection-id" not in message
+ assert "--host" not in message
+
+ def test_validate_datamodel_reports_invalid_values_with_flag_name(self):
+ """Test a value of the wrong type is reported against its flag, not as
a missing argument."""
+ command_factory = CommandFactory()
+ with pytest.raises(SystemExit) as ctx:
+ command_factory._validate_datamodel(
+ ConnectionBody, {"connection_id": "my_conn", "conn_type":
"http", "port": "not-a-port"}
+ )
+
+ message = str(ctx.value)
+ assert "--port" in message
+ assert "required" not in message
+
+ def
test_create_command_without_required_option_exits_with_friendly_message(self):
+ """Test ``connections create`` without --conn-type exits cleanly and
never calls the API."""
+ parser = cli_parser.get_parser()
+ args = parser.parse_args(
+ ["connections", "create", "--api-token", "token",
"--connection-id", "my_conn"]
+ )
+
+ with mock.patch.object(ConnectionsOperations, "create") as mock_create:
Review Comment:
I'm working on it !
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]