# Path: voeventdb/server/tests/fixtures/connection.py
# @pytest.fixture(scope='module')
# def empty_db_connection():
#     """
#     Connect to db, create tables and begin connection-level (outer) transaction.
# 
#     Will also create the database first if it does not exist.
# 
#     Maybe overkill, but a neat trick, cf:
#     http://alextechrants.blogspot.co.uk/2013/08/unit-testing-sqlalchemy-apps.html
#     We use a connection-level (non-ORM) transaction that encloses everything
#     **including the table creation**.
#     This ensures that the models and queries are always in sync for testing.
# 
#     Note that the transaction must be explicitly rolled back. An alternative
#     approach would be to delete all tables, but presumably that would
#     take slightly longer than a rollback (be interesting to check).
#     """
#     # Could be parameterized, but then it wouldn't make sense as a session-level fixture
#     # Unless PyTest is smart enough to maintain fixtures in parallel?
#     # test_db_url = getattr(request.module, "test_db_url", testdb_empty_url)
#     test_db_url = testdb_empty_url
#     if not db_utils.check_database_exists(test_db_url):
#         db_utils.create_empty_database(default_admin_db_url, test_db_url.database)
#     engine = create_engine(test_db_url)
#     connection = engine.connect()
#     transaction = connection.begin()
#     # Create tables (will be rolled back to clean)
#     db_utils.create_tables_and_indexes(connection)
#     # Return to test function
#     yield connection
#     # TearDown
#     transaction.rollback()
#     connection.close()
#     engine.dispose()
# 
# @pytest.fixture
# def fixture_db_session(empty_db_connection):
#     """
#     Provide a Session connected to the empty database.
# 
#     We use nested transactions to return the database to empty after each test.
#     """
#     nested_transaction = empty_db_connection.begin_nested()
#     session_factory.configure(bind=empty_db_connection)
#     session = session_registry()
#     yield session
#     session_registry.remove()
#     nested_transaction.rollback()
# 
# @pytest.fixture
# def simple_populated_db(fixture_db_session):
#     s = fixture_db_session
#     packet_info = SimpleDbFixture(s)
#     return packet_info
# 
# Path: voeventdb/server/restapi/app.py
# def shutdown_session(exception=None):
#     def serve_docs_in_debug(filename='index.html'):


import pytest
from voeventdb.server.tests.fixtures.connection import (
    empty_db_connection,
    fixture_db_session,
    simple_populated_db
)
from voeventdb.server.restapi.app import app


@pytest.fixture
def flask_test_client(fixture_db_session):
    # print
    # print "setting up flask client"
    app.testing = True
    client = app.test_client()

# Path: voeventdb/server/tests/fixtures/connection.py
# @pytest.fixture(scope='module')
# def empty_db_connection():
#     """
#     Connect to db, create tables and begin connection-level (outer) transaction.
# 
#     Will also create the database first if it does not exist.
# 
#     Maybe overkill, but a neat trick, cf:
#     http://alextechrants.blogspot.co.uk/2013/08/unit-testing-sqlalchemy-apps.html
#     We use a connection-level (non-ORM) transaction that encloses everything
#     **including the table creation**.
#     This ensures that the models and queries are always in sync for testing.
# 
#     Note that the transaction must be explicitly rolled back. An alternative
#     approach would be to delete all tables, but presumably that would
#     take slightly longer than a rollback (be interesting to check).
#     """
#     # Could be parameterized, but then it wouldn't make sense as a session-level fixture
#     # Unless PyTest is smart enough to maintain fixtures in parallel?
#     # test_db_url = getattr(request.module, "test_db_url", testdb_empty_url)
#     test_db_url = testdb_empty_url
#     if not db_utils.check_database_exists(test_db_url):
#         db_utils.create_empty_database(default_admin_db_url, test_db_url.database)
#     engine = create_engine(test_db_url)
#     connection = engine.connect()
#     transaction = connection.begin()
#     # Create tables (will be rolled back to clean)
#     db_utils.create_tables_and_indexes(connection)
#     # Return to test function
#     yield connection
#     # TearDown
#     transaction.rollback()
#     connection.close()
#     engine.dispose()
# 
# @pytest.fixture
# def fixture_db_session(empty_db_connection):
#     """
#     Provide a Session connected to the empty database.
# 
#     We use nested transactions to return the database to empty after each test.
#     """
#     nested_transaction = empty_db_connection.begin_nested()
#     session_factory.configure(bind=empty_db_connection)
#     session = session_registry()
#     yield session
#     session_registry.remove()
#     nested_transaction.rollback()
# 
# @pytest.fixture
# def simple_populated_db(fixture_db_session):
#     s = fixture_db_session
#     packet_info = SimpleDbFixture(s)
#     return packet_info
# 
# Path: voeventdb/server/restapi/app.py
# def shutdown_session(exception=None):
#     def serve_docs_in_debug(filename='index.html'):


# Path: voeventdb/server/tests/test_rest/conftest.py
import pytest
from voeventdb.server.tests.fixtures.connection import (
    empty_db_connection,
    fixture_db_session,
    simple_populated_db
)
from voeventdb.server.restapi.app import app



@pytest.fixture
def flask_test_client(fixture_db_session):
    # print
    # print "setting up flask client"
    app.testing = True
    client = app.test_client()

    app_context = app.test_request_context()