# Path: opentracing_instrumentation/client_hooks/psycopg2.py
# class Psycopg2CursorWrapper(CursorWrapper):
#     def execute(self, sql, params=NO_ARG):
#     def executemany(self, sql, seq_of_parameters):
# def install_patches():
#     def register_type(obj, conn_or_curs=None):
#     def quote_ident(string, scope):
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


import mock
import psycopg2 as psycopg2_client
import pytest
from psycopg2 import extensions as pg_extensions, sql
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import psycopg2
from .sql_common import metadata, User
def patch_postgres():
    psycopg2.install_patches()


@pytest.fixture()
def connection():
    return psycopg2_client.connect(POSTGRES_CONNECTION_STRING)


def is_postgres_running():
    try:
        with psycopg2_client.connect(POSTGRES_CONNECTION_STRING):
            pass
        return True
    except:
        return False


@pytest.mark.skipif(not is_postgres_running(), reason=SKIP_REASON)
def test_db(tracer, engine, session):
    metadata.create_all(engine)
    user1 = User(name='user1', fullname='User 1', password='password')
    user2 = User(name='user2', fullname='User 2', password='password')
    session.add(user1)
    session.add(user2)
    # If the test does not raised an error, it is passing


@pytest.mark.skipif(not is_postgres_running(), reason=SKIP_REASON)
def test_connection_proxy(connection):

# Path: opentracing_instrumentation/client_hooks/psycopg2.py
# class Psycopg2CursorWrapper(CursorWrapper):
#     def execute(self, sql, params=NO_ARG):
#     def executemany(self, sql, seq_of_parameters):
# def install_patches():
#     def register_type(obj, conn_or_curs=None):
#     def quote_ident(string, scope):
# 
# Path: tests/opentracing_instrumentation/sql_common.py
# class User(object):
#     def __init__(self, name, fullname, password):


# Path: tests/opentracing_instrumentation/test_postgres.py
import mock
import psycopg2 as psycopg2_client
import pytest
from psycopg2 import extensions as pg_extensions, sql
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from opentracing_instrumentation.client_hooks import psycopg2
from .sql_common import metadata, User

def patch_postgres():
    psycopg2.install_patches()


@pytest.fixture()
def connection():
    return psycopg2_client.connect(POSTGRES_CONNECTION_STRING)


def is_postgres_running():
    try:
        with psycopg2_client.connect(POSTGRES_CONNECTION_STRING):
            pass
        return True
    except:
        return False


@pytest.mark.skipif(not is_postgres_running(), reason=SKIP_REASON)
def test_db(tracer, engine, session):
    metadata.create_all(engine)
    user1 = User(name='user1', fullname='User 1', password='password')
    user2 = User(name='user2', fullname='User 2', password='password')
    session.add(user1)
    session.add(user2)
    # If the test does not raised an error, it is passing


@pytest.mark.skipif(not is_postgres_running(), reason=SKIP_REASON)
def test_connection_proxy(connection):

    assert isinstance(connection, psycopg2.ConnectionWrapper)