Skip to content

Commit 14bd125

Browse files
committed
Update naming of db methods
1 parent 7ff6baf commit 14bd125

File tree

4 files changed

+21
-23
lines changed

4 files changed

+21
-23
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -630,9 +630,9 @@ def write_data_to_db(self, the_id, the_value, the_url):
630630
db = DatabaseManager()
631631
query = """INSERT INTO myTable(the_id,the_value,the_url)
632632
VALUES (%(the_id)s,%(the_value)s,%(the_url)s)"""
633-
db.execute_query_and_close(query, {"the_id":the_id,
634-
"the_value":the_value,
635-
"the_url":the_url})
633+
db.execute_query(query, {"the_id":the_id,
634+
"the_value":the_value,
635+
"the_url":the_url})
636636
```
637637

638638
Access credentials are stored in [settings.py](https://github.com/seleniumbase/SeleniumBase/blob/master/seleniumbase/config/settings.py) for your convenience (you have to add them first).
@@ -650,7 +650,7 @@ def get_delayed_test_data(self, test_address, is_done=0):
650650
FROM delayed_test_data
651651
WHERE test_address=%(test_address)s
652652
AND is_done=%(is_done)s"""
653-
data = db.fetchall_query_and_close(query, {"test_address":test_address, "is_done":is_done})
653+
data = db.fetchall_query(query, {"test_address":test_address, "is_done":is_done})
654654
if data:
655655
return data
656656
else:

seleniumbase/core/mysql.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,25 @@
11
"""
2-
Wrapper for MySQL functions to make life easier
3-
Due to compatibility issues, might only work for Python 2.7 right now
2+
Wrapper for MySQL DB functions to make life easier.
43
"""
54

65
import time
6+
from seleniumbase.core import mysql_conf as conf
77

88

99
class DatabaseManager():
1010
"""
1111
This class wraps MySQL database methods for easy use.
12-
It connects to the testcase database.
1312
"""
1413

1514
def __init__(self, database_env='test', conf_creds=None):
1615
"""
1716
Gets database information from mysql_conf.py and creates a connection.
1817
"""
19-
from seleniumbase.core import mysql_conf as conf
2018
import MySQLdb
2119
db_server, db_user, db_pass, db_schema = \
2220
conf.APP_CREDS[conf.Apps.TESTCASE_REPOSITORY][database_env]
2321
retry_count = 3
24-
backoff = 1.2 # Time to wait (in seconds) between retries
22+
backoff = 1.2 # Time to wait (in seconds) between retries.
2523
count = 0
2624
while count < retry_count:
2725
try:
@@ -38,27 +36,27 @@ def __init__(self, database_env='test', conf_creds=None):
3836
if retry_count == 3:
3937
raise Exception("Unable to connect to Database after 3 retries.")
4038

41-
def fetchall_query_and_close(self, query, values):
39+
def query_fetch_all(self, query, values):
4240
"""
43-
Executes a query, gets all the values, and closes the connection.
41+
Executes a db query, gets all the values, and closes the connection.
4442
"""
4543
self.cursor.execute(query, values)
4644
retval = self.cursor.fetchall()
4745
self.__close_db()
4846
return retval
4947

50-
def fetchone_query_and_close(self, query, values):
48+
def query_fetch_one(self, query, values):
5149
"""
52-
Executes a query, gets the first value, and closes the connection.
50+
Executes a db query, gets the first value, and closes the connection.
5351
"""
5452
self.cursor.execute(query, values)
5553
retval = self.cursor.fetchone()
5654
self.__close_db()
5755
return retval
5856

59-
def execute_query_and_close(self, query, values):
57+
def execute_query(self, query, values):
6058
"""
61-
Executes a query and closes the connection.
59+
Executes a query to the test_db and closes the connection afterwards.
6260
"""
6361
retval = self.cursor.execute(query, values)
6462
self.__close_db()

seleniumbase/core/testcase_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def insert_execution_data(self, execution_query_payload):
1616
(guid, execution_start, total_execution_time, username)
1717
VALUES (%(guid)s,%(execution_start_time)s,
1818
%(total_execution_time)s,%(username)s)"""
19-
DatabaseManager(self.database_env).execute_query_and_close(
19+
DatabaseManager(self.database_env).execute_query(
2020
query,
2121
execution_query_payload.get_params())
2222
return execution_query_payload.guid
@@ -26,7 +26,7 @@ def update_execution_data(self, execution_guid, execution_time):
2626
query = """UPDATE execution
2727
SET total_execution_time=%(execution_time)s
2828
WHERE guid=%(execution_guid)s """
29-
DatabaseManager(self.database_env).execute_query_and_close(
29+
DatabaseManager(self.database_env).execute_query(
3030
query,
3131
{"execution_guid": execution_guid,
3232
"execution_time": execution_time})
@@ -48,7 +48,7 @@ def insert_testcase_data(self, testcase_run_payload):
4848
%(retry_count)s,
4949
%(message)s,
5050
%(stack_trace)s) """
51-
DatabaseManager(self.database_env).execute_query_and_close(
51+
DatabaseManager(self.database_env).execute_query(
5252
query, testcase_run_payload.get_params())
5353

5454
def update_testcase_data(self, testcase_payload):
@@ -60,14 +60,14 @@ def update_testcase_data(self, testcase_payload):
6060
stack_trace=%(stack_trace)s,
6161
message=%(message)s
6262
WHERE guid=%(guid)s """
63-
DatabaseManager(self.database_env).execute_query_and_close(
63+
DatabaseManager(self.database_env).execute_query(
6464
query, testcase_payload.get_params())
6565

6666
def update_testcase_log_url(self, testcase_payload):
6767
query = """UPDATE test_run_data
6868
SET log_url=%(log_url)s
6969
WHERE guid=%(guid)s """
70-
DatabaseManager(self.database_env).execute_query_and_close(
70+
DatabaseManager(self.database_env).execute_query(
7171
query, testcase_payload.get_params())
7272

7373

seleniumbase/fixtures/delayed_data_manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def get_delayed_test_data(self, test_address, is_done=0):
2222
FROM delayed_test_data
2323
WHERE test_address=%(test_address)s
2424
AND is_done=%(is_done)s"""
25-
data = db.fetchall_query_and_close(
25+
data = db.query_fetch_all(
2626
query, {"test_address": test_address,
2727
"is_done": is_done})
2828
if data:
@@ -57,7 +57,7 @@ def insert_delayed_test_data(self, guid_, test_address,
5757
VALUES (%(guid)s,%(test_address)s,%(inserted_at)s,
5858
%(expected_result)s,%(is_done)s,%(expires_at)s)"""
5959

60-
db.execute_query_and_close(
60+
db.execute_query(
6161
query, {"guid": guid_,
6262
"test_address": test_address,
6363
"inserted_at": inserted_at,
@@ -79,7 +79,7 @@ def set_delayed_test_to_done(self, guid_):
7979
SET is_done=TRUE
8080
WHERE guid=%(guid)s
8181
AND is_done=FALSE"""
82-
db.execute_query_and_close(query, {"guid": guid_})
82+
db.execute_query(query, {"guid": guid_})
8383
return True
8484

8585

0 commit comments

Comments
 (0)