From c0682e43089bcbcff6966c077581230383732ae6 Mon Sep 17 00:00:00 2001
From: Astha Mohta <asthamohta@google.com>
Date: Thu, 23 Feb 2023 07:35:27 +0530
Subject: [PATCH 1/3] fgac-pg testing

---
 tests/system/test_database_api.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/tests/system/test_database_api.py b/tests/system/test_database_api.py
index 364c159da5..56346e5f0d 100644
--- a/tests/system/test_database_api.py
+++ b/tests/system/test_database_api.py
@@ -226,7 +226,6 @@ def test_iam_policy(
     not_emulator,
     shared_instance,
     databases_to_delete,
-    not_postgres,
 ):
     pool = spanner_v1.BurstyPool(labels={"testcase": "iam_policy"})
     temp_db_id = _helpers.unique_id("iam_db", separator="_")
@@ -410,7 +409,6 @@ def test_create_role_grant_access_success(
     not_emulator,
     shared_instance,
     databases_to_delete,
-    not_postgres,
 ):
     creator_role_parent = _helpers.unique_id("role_parent", separator="_")
     creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")
@@ -459,7 +457,6 @@ def test_list_database_role_success(
     not_emulator,
     shared_instance,
     databases_to_delete,
-    not_postgres,
 ):
     creator_role_parent = _helpers.unique_id("role_parent", separator="_")
     creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")

From 6449835456032e6cc9118bfb1a1bc7edf6e496ba Mon Sep 17 00:00:00 2001
From: Astha Mohta <asthamohta@google.com>
Date: Tue, 6 Jun 2023 11:05:32 +0530
Subject: [PATCH 2/3] changes

---
 tests/system/test_database_api.py | 40 +++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/tests/system/test_database_api.py b/tests/system/test_database_api.py
index 56346e5f0d..4d3ff1a86c 100644
--- a/tests/system/test_database_api.py
+++ b/tests/system/test_database_api.py
@@ -24,6 +24,7 @@
 from google.type import expr_pb2
 from . import _helpers
 from . import _sample_data
+from google.cloud.spanner_admin_database_v1 import DatabaseDialect
 
 
 DBAPI_OPERATION_TIMEOUT = 240  # seconds
@@ -406,9 +407,7 @@ def test_update_ddl_w_default_leader_success(
 
 
 def test_create_role_grant_access_success(
-    not_emulator,
-    shared_instance,
-    databases_to_delete,
+    not_emulator, shared_instance, databases_to_delete, database_dialect
 ):
     creator_role_parent = _helpers.unique_id("role_parent", separator="_")
     creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")
@@ -421,11 +420,19 @@ def test_create_role_grant_access_success(
     create_op.result(DBAPI_OPERATION_TIMEOUT)  # raises on failure / timeout.
 
     # Create role and grant select permission on table contacts for parent role.
-    ddl_statements = _helpers.DDL_STATEMENTS + [
-        f"CREATE ROLE {creator_role_parent}",
-        f"CREATE ROLE {creator_role_orphan}",
-        f"GRANT SELECT ON TABLE contacts TO ROLE {creator_role_parent}",
-    ]
+    if database_dialect == DatabaseDialect.GOOGLE_STANDARD_SQL:
+        ddl_statements = _helpers.DDL_STATEMENTS + [
+            f"CREATE ROLE {creator_role_parent}",
+            f"CREATE ROLE {creator_role_orphan}",
+            f"GRANT SELECT ON TABLE contacts TO ROLE {creator_role_parent}",
+        ]
+    elif database_dialect == DatabaseDialect.POSTGRESQL:
+        ddl_statements = _helpers.DDL_STATEMENTS + [
+            f"CREATE ROLE {creator_role_parent}",
+            f"CREATE ROLE {creator_role_orphan}",
+            f"GRANT SELECT ON TABLE contacts TO {creator_role_parent}",
+        ]
+
     operation = temp_db.update_ddl(ddl_statements)
     operation.result(DBAPI_OPERATION_TIMEOUT)  # raises on failure / timeout.
 
@@ -443,11 +450,18 @@ def test_create_role_grant_access_success(
     with temp_db.snapshot() as snapshot:
         snapshot.execute_sql("SELECT * FROM contacts")
 
-    ddl_remove_roles = [
-        f"REVOKE SELECT ON TABLE contacts FROM ROLE {creator_role_parent}",
-        f"DROP ROLE {creator_role_parent}",
-        f"DROP ROLE {creator_role_orphan}",
-    ]
+    if database_dialect == DatabaseDialect.GOOGLE_STANDARD_SQL:
+        ddl_remove_roles = [
+            f"REVOKE SELECT ON TABLE contacts FROM ROLE {creator_role_parent}",
+            f"DROP ROLE {creator_role_parent}",
+            f"DROP ROLE {creator_role_orphan}",
+        ]
+    elif database_dialect == DatabaseDialect.POSTGRESQL:
+        ddl_remove_roles = [
+            f"REVOKE SELECT ON TABLE contacts FROM {creator_role_parent}",
+            f"DROP ROLE {creator_role_parent}",
+            f"DROP ROLE {creator_role_orphan}",
+        ]
     # Revoke permission and Delete roles.
     operation = temp_db.update_ddl(ddl_remove_roles)
     operation.result(DBAPI_OPERATION_TIMEOUT)  # raises on failure / timeout.

From a6ba8227a69ab15248cf1260b352ee5f6ee2b8d2 Mon Sep 17 00:00:00 2001
From: Astha Mohta <asthamohta@google.com>
Date: Tue, 6 Jun 2023 12:13:40 +0530
Subject: [PATCH 3/3] changes

---
 tests/system/test_database_api.py | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/tests/system/test_database_api.py b/tests/system/test_database_api.py
index 4d3ff1a86c..1faebab7a8 100644
--- a/tests/system/test_database_api.py
+++ b/tests/system/test_database_api.py
@@ -413,12 +413,11 @@ def test_create_role_grant_access_success(
     creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")
 
     temp_db_id = _helpers.unique_id("dfl_ldrr_upd_ddl", separator="_")
-    temp_db = shared_instance.database(temp_db_id)
+    temp_db = shared_instance.database(temp_db_id, database_dialect=database_dialect)
 
     create_op = temp_db.create()
     databases_to_delete.append(temp_db)
     create_op.result(DBAPI_OPERATION_TIMEOUT)  # raises on failure / timeout.
-
     # Create role and grant select permission on table contacts for parent role.
     if database_dialect == DatabaseDialect.GOOGLE_STANDARD_SQL:
         ddl_statements = _helpers.DDL_STATEMENTS + [
@@ -468,15 +467,13 @@ def test_create_role_grant_access_success(
 
 
 def test_list_database_role_success(
-    not_emulator,
-    shared_instance,
-    databases_to_delete,
+    not_emulator, shared_instance, databases_to_delete, database_dialect
 ):
     creator_role_parent = _helpers.unique_id("role_parent", separator="_")
     creator_role_orphan = _helpers.unique_id("role_orphan", separator="_")
 
     temp_db_id = _helpers.unique_id("dfl_ldrr_upd_ddl", separator="_")
-    temp_db = shared_instance.database(temp_db_id)
+    temp_db = shared_instance.database(temp_db_id, database_dialect=database_dialect)
 
     create_op = temp_db.create()
     databases_to_delete.append(temp_db)
