Skip to content

Commit

Permalink
Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
hmstepanek committed Apr 14, 2023
1 parent 930128a commit b1653ec
Showing 1 changed file with 14 additions and 55 deletions.
69 changes: 14 additions & 55 deletions tests/datastore_pyodbc/test_pyodbc.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import pyodbc
import pytest
from testing_support.db_settings import postgresql_settings
from testing_support.validators.validate_database_trace_inputs import (
Expand All @@ -31,45 +30,20 @@
"test_pyodbc:test_execute_via_cursor",
scoped_metrics=[
("Function/pyodbc:connect", 1),
# ("Function/pyodbc:Connection.__enter__", 1),
# ("Function/pyodbc:Connection.__exit__", 1),
("Datastore/statement/ODBC/%s/select" % DB_SETTINGS["table_name"], 1),
("Datastore/statement/ODBC/%s/insert" % DB_SETTINGS["table_name"], 1),
("Datastore/statement/ODBC/%s/update" % DB_SETTINGS["table_name"], 1),
("Datastore/statement/ODBC/%s/delete" % DB_SETTINGS["table_name"], 1),
("Datastore/statement/ODBC/now/call", 1),
("Datastore/statement/ODBC/pg_sleep/call", 1),
("Datastore/operation/ODBC/drop", 1),
("Datastore/operation/ODBC/create", 1),
("Datastore/operation/ODBC/commit", 3),
("Datastore/operation/ODBC/rollback", 1),
],
rollup_metrics=[
("Datastore/all", 13),
("Datastore/allOther", 13),
("Datastore/ODBC/all", 13),
("Datastore/ODBC/allOther", 13),
("Datastore/operation/ODBC/select", 1),
("Datastore/statement/ODBC/%s/select" % DB_SETTINGS["table_name"], 1),
("Datastore/operation/ODBC/insert", 1),
("Datastore/statement/ODBC/%s/insert" % DB_SETTINGS["table_name"], 1),
("Datastore/operation/ODBC/update", 1),
("Datastore/statement/ODBC/%s/update" % DB_SETTINGS["table_name"], 1),
("Datastore/operation/ODBC/delete", 1),
("Datastore/statement/ODBC/%s/delete" % DB_SETTINGS["table_name"], 1),
("Datastore/operation/ODBC/drop", 1),
("Datastore/operation/ODBC/create", 1),
("Datastore/statement/ODBC/now/call", 1),
("Datastore/statement/ODBC/pg_sleep/call", 1),
("Datastore/operation/ODBC/call", 2),
("Datastore/operation/ODBC/commit", 3),
("Datastore/operation/ODBC/rollback", 1),
("Datastore/all", 1),
("Datastore/allOther", 1),
("Datastore/ODBC/all", 1),
("Datastore/ODBC/allOther", 1),
],
background_task=True,
)
@validate_database_trace_inputs(sql_parameters_type=tuple)
@background_task()
def test_execute_via_cursor(pyodbc_driver):
import pyodbc

with pyodbc.connect(
"DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s"
% (
Expand Down Expand Up @@ -109,21 +83,20 @@ def test_execute_via_cursor(pyodbc_driver):
"test_pyodbc:test_rollback_on_exception",
scoped_metrics=[
("Function/pyodbc:connect", 1),
# ("Function/pyodbc:Connection.__enter__", 1),
# ("Function/pyodbc:Connection.__exit__", 1),
("Datastore/operation/ODBC/rollback", 1),
],
rollup_metrics=[
("Datastore/all", 2),
("Datastore/allOther", 2),
("Datastore/ODBC/all", 2),
("Datastore/ODBC/allOther", 2),
("Datastore/all", 1),
("Datastore/allOther", 1),
("Datastore/ODBC/all", 1),
("Datastore/ODBC/allOther", 1),
],
background_task=True,
)
@validate_database_trace_inputs(sql_parameters_type=tuple)
@background_task()
def test_rollback_on_exception(pyodbc_driver):
import pyodbc

with pytest.raises(RuntimeError):
with pyodbc.connect(
"DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s"
Expand All @@ -141,22 +114,8 @@ def test_rollback_on_exception(pyodbc_driver):

@pytest.fixture
def pyodbc_driver():
import pyodbc

driver_name = "PostgreSQL Unicode"
assert driver_name in pyodbc.drivers()
return driver_name


@pytest.fixture
def connection(pyodbc_driver):
connection = pyodbc.connect(
"DRIVER={%s};SERVER=%s;PORT=%s;DATABASE=%s;UID=%s;PWD=%s"
% (
pyodbc_driver,
DB_SETTINGS["host"],
DB_SETTINGS["port"],
DB_SETTINGS["name"],
DB_SETTINGS["user"],
DB_SETTINGS["password"],
)
)
return connection

0 comments on commit b1653ec

Please sign in to comment.