bugraoz93 commented on code in PR #43396:
URL: https://github.com/apache/airflow/pull/43396#discussion_r1825159918
##########
tests/api_fastapi/core_api/routes/public/test_connections.py:
##########
@@ -169,3 +169,83 @@ def test_should_respond_200(
body = response.json()
assert body["total_entries"] == expected_total_entries
assert [connection["connection_id"] for connection in
body["connections"]] == expected_ids
+
+
+class TestPostConnection(TestConnectionEndpoint):
+ @pytest.mark.parametrize(
+ "body",
+ [
+ {"connection_id": "test-connection-id", "conn_type": "test_type"},
+ {"connection_id": "test-connection-id", "conn_type": "test_type",
"extra": None},
+ {"connection_id": "test-connection-id", "conn_type": "test_type",
"extra": "{}"},
+ {"connection_id": "test-connection-id", "conn_type": "test_type",
"extra": '{"key": "value"}'},
+ {
+ "connection_id": "test-connection-id",
+ "conn_type": "test_type",
+ "description": "test_description",
+ "host": "test_host",
+ "login": "test_login",
+ "schema": "test_schema",
+ "port": 8080,
+ "extra": '{"key": "value"}',
+ },
+ ],
+ )
+ def test_post_should_respond_200(self, test_client, session, body):
+ response = test_client.post("/public/connections/", json=body)
+ assert response.status_code == 201
+ connection = session.query(Connection).all()
+ assert len(connection) == 1
+
+ @pytest.mark.parametrize(
+ "body",
+ [
+ {"connection_id": "****", "conn_type": "test_type"},
+ {"connection_id": "test()", "conn_type": "test_type"},
+ {"connection_id": "this_^$#is_invalid", "conn_type": "test_type"},
+ {"connection_id": "iam_not@#$_connection_id", "conn_type":
"test_type"},
+ ],
+ )
+ def test_post_should_respond_400_for_invalid_conn_id(self, test_client,
body):
+ response = test_client.post("/public/connections/", json=body)
+ assert response.status_code == 400
+ connection_id = body["connection_id"]
+ assert response.json() == {
+ "detail": f"The key '{connection_id}' has to be made of "
+ "alphanumeric characters, dashes, dots and underscores
exclusively",
+ }
+
+ @pytest.mark.parametrize(
+ "body",
+ [
+ {"connection_id": "test-connection-id", "conn_type": "test_type"},
+ ],
+ )
+ def test_post_should_respond_already_exist(self, test_client, body):
+ response = test_client.post("/public/connections/", json=body)
+ assert response.status_code == 201
+ # Another request
+ response = test_client.post("/public/connections/", json=body)
+ assert response.status_code == 409
+ assert response.json() == {
+ "detail": "Connection with connection_id: `test-connection-id`
already exists",
+ }
+
+ @pytest.mark.parametrize(
+ "body",
+ [
+ {"connection_id": "test-connection-id", "conn_type": "test_type",
"password": "test-password"},
+ {"connection_id": "test-connection-id", "conn_type": "test_type",
"password": "?>@#+!_%()#"},
+ {
+ "connection_id": "test-connection-id",
+ "conn_type": "test_type",
+ "password": "A!rF|0wi$aw3s0m3",
+ "extra": '{"password": "test-password"}',
+ },
+ ],
+ )
+ def test_post_should_response_201_redacted_password(self, test_client,
body):
+ response = test_client.post("/public/connections/", json=body)
+ assert response.status_code == 201
+ connection = response.json()
+ assert "password" not in connection
Review Comment:
Included the password to the response as redacted and adjusted the tests
accordingly. Followed up a similar approach with variables. I thi. I will apply
the same update to the patch. Many thanks! :)
--
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]