claudevdm commented on code in PR #34398:
URL: https://github.com/apache/beam/pull/34398#discussion_r2096165875


##########
sdks/python/apache_beam/transforms/enrichment_handlers/cloudsql_it_test.py:
##########
@@ -0,0 +1,437 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#    http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+import functools
+import logging
+import unittest
+from dataclasses import dataclass
+from typing import Optional
+from unittest.mock import MagicMock
+
+import pytest
+
+import apache_beam as beam
+from apache_beam.coders import coders
+from apache_beam.testing.test_pipeline import TestPipeline
+from apache_beam.testing.util import assert_that
+from apache_beam.testing.util import equal_to
+
+# pylint: disable=ungrouped-imports
+try:
+  from testcontainers.core.generic import DbContainer
+  from testcontainers.postgres import PostgresContainer
+  from testcontainers.redis import RedisContainer
+  from sqlalchemy import (
+      create_engine, MetaData, Table, Column, Integer, String, Engine)
+  from apache_beam.transforms.enrichment import Enrichment
+  from apache_beam.transforms.enrichment_handlers.cloudsql import (
+      CloudSQLEnrichmentHandler,
+      DatabaseTypeAdapter,
+  )
+except ImportError:
+  raise unittest.SkipTest('Google Cloud SQL dependencies are not installed.')
+
+_LOGGER = logging.getLogger(__name__)
+
+
+def where_clause_value_fn(row: beam.Row):
+  return [row.id]  # type: ignore[attr-defined]
+
+
+def query_fn(table, row: beam.Row):
+  return f"SELECT * FROM `{table}` WHERE id = {row.id}"  # type: 
ignore[attr-defined]
+
+
+@dataclass
+class SQLDBContainerInfo:
+  adapter: DatabaseTypeAdapter
+  container: DbContainer
+  host: str
+  port: int
+  user: str
+  password: str
+  id: str
+
+  @property
+  def address(self) -> str:
+    return f"{self.host}:{self.port}"
+
+  @property
+  def url(self) -> str:
+    dialect = self.adapter.to_sqlalchemy_dialect()
+    return f"{dialect}://{self.user}:{self.password}@{self.address}/{self.id}"
+
+
+class CloudSQLEnrichmentTestHelper:
+  @staticmethod
+  def start_sql_db_container(
+      sql_client_retries=3) -> Optional[SQLDBContainerInfo]:
+    info = None
+    for i in range(sql_client_retries):
+      try:
+        database_type_adapter = DatabaseTypeAdapter.POSTGRESQL

Review Comment:
   Can we also have these tests run for mysql and sql server? Here is an 
example for setting up the containers 
https://github.com/apache/beam/blob/5a78cdbcf01f8a1d6c712517f149470b6741c23a/sdks/python/apache_beam/yaml/integration_tests.py



-- 
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: github-unsubscr...@beam.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to