|
1 |
| -""" |
2 |
| -Wrapper for MySQL DB functions to make life easier. |
3 |
| -""" |
4 |
| - |
5 |
| -import sys |
6 |
| -import time |
7 |
| -from seleniumbase import config as sb_config |
8 |
| -from seleniumbase.config import settings |
9 |
| -from seleniumbase.core import settings_parser |
| 1 | +"""Wrapper for MySQL DB functions.""" |
10 | 2 |
|
11 | 3 |
|
12 | 4 | class DatabaseManager:
|
13 |
| - """ |
14 |
| - This class wraps MySQL database methods for easy use. |
15 |
| - """ |
| 5 | + """This class wraps MySQL database methods for easy use.""" |
16 | 6 |
|
17 | 7 | def __init__(self, database_env="test", conf_creds=None):
|
18 |
| - """ |
19 |
| - Create a connection to the MySQL DB. |
20 |
| - """ |
| 8 | + """Create a connection to the MySQL DB.""" |
| 9 | + import fasteners |
| 10 | + import sys |
| 11 | + import time |
| 12 | + from importlib.util import find_spec |
| 13 | + from seleniumbase import config as sb_config |
| 14 | + from seleniumbase.config import settings |
| 15 | + from seleniumbase.core import settings_parser |
| 16 | + from seleniumbase.fixtures import constants |
| 17 | + from seleniumbase.fixtures import shared_utils |
| 18 | + |
| 19 | + pip_find_lock = fasteners.InterProcessLock( |
| 20 | + constants.PipInstall.FINDLOCK |
| 21 | + ) |
| 22 | + with pip_find_lock: # Prevent multi-processes mode issues |
| 23 | + if not find_spec("pymysql"): |
| 24 | + if sys.version_info >= (3, 6): |
| 25 | + shared_utils.pip_install("pymysql", version="1.0.2") |
| 26 | + else: |
| 27 | + shared_utils.pip_install("pymysql", version="0.10.1") |
21 | 28 | import pymysql
|
22 | 29 |
|
23 | 30 | db_server = settings.DB_HOST
|
@@ -70,27 +77,21 @@ def __init__(self, database_env="test", conf_creds=None):
|
70 | 77 | raise Exception("Unable to connect to Database after 3 retries.")
|
71 | 78 |
|
72 | 79 | def query_fetch_all(self, query, values):
|
73 |
| - """ |
74 |
| - Executes a db query, gets all the values, and closes the connection. |
75 |
| - """ |
| 80 | + """Execute db query, get all the values, and close the connection.""" |
76 | 81 | self.cursor.execute(query, values)
|
77 | 82 | retval = self.cursor.fetchall()
|
78 | 83 | self.__close_db()
|
79 | 84 | return retval
|
80 | 85 |
|
81 | 86 | def query_fetch_one(self, query, values):
|
82 |
| - """ |
83 |
| - Executes a db query, gets the first value, and closes the connection. |
84 |
| - """ |
| 87 | + """Execute db query, get the first value, and close the connection.""" |
85 | 88 | self.cursor.execute(query, values)
|
86 | 89 | retval = self.cursor.fetchone()
|
87 | 90 | self.__close_db()
|
88 | 91 | return retval
|
89 | 92 |
|
90 | 93 | def execute_query(self, query, values):
|
91 |
| - """ |
92 |
| - Executes a query to the test_db and closes the connection afterwards. |
93 |
| - """ |
| 94 | + """Execute db query, close the connection, and return the results.""" |
94 | 95 | retval = self.cursor.execute(query, values)
|
95 | 96 | self.__close_db()
|
96 | 97 | return retval
|
|
0 commit comments