jason810496 commented on code in PR #48706:
URL: https://github.com/apache/airflow/pull/48706#discussion_r2027970956


##########
providers/mysql/tests/unit/mysql/hooks/test_mysql.py:
##########
@@ -86,12 +86,89 @@ def test_dummy_connection_setter(self, mock_connect):
         assert kwargs["db"] == "schema"
 
     @mock.patch("MySQLdb.connect")
-    def test_get_uri(self, mock_connect):
-        self.connection.extra = json.dumps({"charset": "utf-8"})
-        self.db_hook.get_conn()
-        assert mock_connect.call_count == 1
-        args, kwargs = mock_connect.call_args
-        assert self.db_hook.get_uri() == 
"mysql://login:password@host/schema?charset=utf-8"
+    @pytest.mark.parametrize(
+        "connection_params, expected_uri",
+        [
+            (
+                {
+                    "login": "login",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"charset": "utf-8"}),
+                },
+                "mysql://login:password@host/schema?charset=utf-8",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "pass/word!",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"charset": "utf-8"}),
+                },
+                
"mysql://user%40domain:pass%2Fword%21@host/schema?charset=utf-8",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                "mysql+mysqlconnector://user%40domain:password@host/schema",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": 3307,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/schema",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "db/name",
+                    "port": 3307,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/db%2Fname",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": 3307,
+                    "extra": json.dumps(
+                        {
+                            "client": "mysql-connector-python",
+                            "ssl_ca": "/path/to/ca",
+                            "ssl_cert": "/path/to/cert with space",
+                        }
+                    ),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/schema?ssl_ca=%2Fpath%2Fto%2Fca&ssl_cert=%2Fpath%2Fto%2Fcert+with+space",
+            ),
+        ],
+    )

Review Comment:
   How about using "pytest.param" with the "id" argument to improve test 
readability and make it easier to identify each case?



##########
providers/mysql/tests/unit/mysql/hooks/test_mysql.py:
##########
@@ -86,12 +86,89 @@ def test_dummy_connection_setter(self, mock_connect):
         assert kwargs["db"] == "schema"
 
     @mock.patch("MySQLdb.connect")
-    def test_get_uri(self, mock_connect):
-        self.connection.extra = json.dumps({"charset": "utf-8"})
-        self.db_hook.get_conn()
-        assert mock_connect.call_count == 1
-        args, kwargs = mock_connect.call_args
-        assert self.db_hook.get_uri() == 
"mysql://login:password@host/schema?charset=utf-8"
+    @pytest.mark.parametrize(
+        "connection_params, expected_uri",
+        [
+            (
+                {
+                    "login": "login",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"charset": "utf-8"}),
+                },
+                "mysql://login:password@host/schema?charset=utf-8",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "pass/word!",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"charset": "utf-8"}),
+                },
+                
"mysql://user%40domain:pass%2Fword%21@host/schema?charset=utf-8",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": None,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                "mysql+mysqlconnector://user%40domain:password@host/schema",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": 3307,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/schema",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "db/name",
+                    "port": 3307,
+                    "extra": json.dumps({"client": "mysql-connector-python"}),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/db%2Fname",
+            ),
+            (
+                {
+                    "login": "user@domain",
+                    "password": "password",
+                    "host": "host",
+                    "schema": "schema",
+                    "port": 3307,
+                    "extra": json.dumps(
+                        {
+                            "client": "mysql-connector-python",
+                            "ssl_ca": "/path/to/ca",
+                            "ssl_cert": "/path/to/cert with space",
+                        }
+                    ),
+                },
+                
"mysql+mysqlconnector://user%40domain:password@host:3307/schema?ssl_ca=%2Fpath%2Fto%2Fca&ssl_cert=%2Fpath%2Fto%2Fcert+with+space",
+            ),
+        ],
+    )
+    def test_get_uri_parametrized(self, mock_connect, connection_params, 
expected_uri):

Review Comment:
   ```suggestion
       def test_get_uri(self, mock_connect, connection_params, expected_uri):
   ```
   
   Leave it as "test_get_uri" is fine, we don't need to mention "parameterize" 
in method name.



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