hussein-awala commented on code in PR #32292:
URL: https://github.com/apache/airflow/pull/32292#discussion_r1254911180


##########
tests/www/views/test_views_connection.py:
##########
@@ -58,16 +58,23 @@ def test_create_connection(admin_client, session):
     _check_last_log(session, dag_id=None, event="connection.create", 
execution_date=None)
 
 
-def test_invalid_connection_id_trailing_blanks(admin_client, session):
-    invalid_conn_id = "conn_id_with_trailing_blanks   "
-    invalid_connection = {**CONNECTION, "conn_id": invalid_conn_id}
-    resp = admin_client.post("/connection/add", data=invalid_connection, 
follow_redirects=True)
-    check_content_in_response(
-        f"The key '{invalid_conn_id}' has to be made of alphanumeric 
characters, "
-        + "dashes, dots and underscores exclusively",
-        resp,
+def test_connection_id_with_trailing_blanks(admin_client, session):
+    conn_id_with_blanks = "conn_id_with_trailing_blanks   "
+
+    conn = Connection(
+        conn_id=conn_id_with_blanks,
+        conn_type="Google Cloud",
     )
 
+    with create_session() as session:
+        session.query(Connection).delete()
+        session.add(conn)
+        session.commit()
+
+    response = {conn[0] for conn in session.query(Connection.conn_id).all()}
+    assert len(response) == 1
+    assert "conn_id_with_trailing_blanks" in list(response)[0]
+

Review Comment:
   How creating a connection via the Connection model could test test 
connection form?
   IMO this test is useless, you need to create a connection using the 
connection form, to do that you can sens a post request to the route 
`/connection/add` as we did in the test you are replacing...
   
   Another remark, you **should** use `=` when you can in the assert 
statements, where your current is the following:
   ```python
   assert "conn_id_with_trailing_blanks" in "conn_id_with_trailing_blanks "
   ```
   which is `True`



-- 
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]

Reply via email to