Hi Hackers,
Please find attached a patch including new python test that checks the
transaction status after executing queries and saving data when auto-commit
is on/off. It also includes some refactoring of previously written python
tests.
Please review !
Thanks. Regards.
--
*Yosry Muhammad Yosry*
Computer Engineering student,
The Faculty of Engineering,
Cairo University (2021).
Class representative of CMP 2021.
https://www.linkedin.com/in/yosrym93/
diff --git a/web/pgadmin/tools/sqleditor/tests/execute_query_utils.py b/web/pgadmin/tools/sqleditor/tests/execute_query_test_utils.py
similarity index 100%
rename from web/pgadmin/tools/sqleditor/tests/execute_query_utils.py
rename to web/pgadmin/tools/sqleditor/tests/execute_query_test_utils.py
diff --git a/web/pgadmin/tools/sqleditor/tests/test_transaction_status.py b/web/pgadmin/tools/sqleditor/tests/test_transaction_status.py
new file mode 100644
index 0..b18dcdc62
--- /dev/null
+++ b/web/pgadmin/tools/sqleditor/tests/test_transaction_status.py
@@ -0,0 +1,336 @@
+##
+#
+# pgAdmin 4 - PostgreSQL Tools
+#
+# Copyright (C) 2013 - 2019, The pgAdmin Development Team
+# This software is released under the PostgreSQL Licence
+#
+##
+
+import json
+import random
+
+from pgadmin.browser.server_groups.servers.databases.tests import utils as \
+database_utils
+from pgadmin.utils.route import BaseTestGenerator
+from regression import parent_node_dict
+from regression.python_test_utils import test_utils as utils
+from pgadmin.tools.sqleditor.tests.execute_query_test_utils import execute_query
+
+from pgadmin.tools.sqleditor.utils.constant_definition \
+import TX_STATUS_IDLE, TX_STATUS_INTRANS
+
+
+class TestTransactionControl(BaseTestGenerator):
+""" This class will test the transaction status after various operations """
+scenarios = [
+('When auto-commit is enabled, and save is successful', dict(
+is_auto_commit_enabled=True,
+transaction_status=TX_STATUS_IDLE,
+save_payload={
+"updated": {},
+"added": {
+"2": {
+"err": False,
+"data": {
+"pk_col": "3",
+"__temp_PK": "2",
+"normal_col": "three"
+}
+}
+},
+"staged_rows": {},
+"deleted": {},
+"updated_index": {},
+"added_index": {"2": "2"},
+"columns": [
+{
+"name": "pk_col",
+"display_name": "pk_col",
+"column_type": "[PK] integer",
+"column_type_internal": "integer",
+"pos": 0,
+"label": "pk_col[PK] integer",
+"cell": "number",
+"can_edit": True,
+"type": "integer",
+"not_null": True,
+"has_default_val": False,
+"is_array": False},
+{"name": "normal_col",
+ "display_name": "normal_col",
+ "column_type": "character varying",
+ "column_type_internal": "character varying",
+ "pos": 1,
+ "label": "normal_colcharacter varying",
+ "cell": "string",
+ "can_edit": True,
+ "type": "character varying",
+ "not_null": False,
+ "has_default_val": False,
+ "is_array": False}
+]
+}
+)),
+('When auto-commit is disabled and save is successful', dict(
+is_auto_commit_enabled=False,
+transaction_status=TX_STATUS_INTRANS,
+save_payload={
+"updated": {},
+"added": {
+"2": {
+"err": False,
+"data": {
+"pk_col": "3",
+"__temp_PK": "2",
+"normal_col": "three"
+}
+}
+},
+"staged_rows": {},
+"deleted": {},
+"updated_index": {},
+"added_index": {"2": "2"},
+"columns": [
+{
+"name": "pk_col",
+"display_name": "pk_col",
+"column_type": "[PK] integer",
+"column_type_internal": "integer",
+"pos": 0,
+"label": "pk_col[PK] in