# Path: tkp/testutil/decorators.py
# def requires_test_db_managed():
#     """
#     This decorator is used to disable tests that do potentially low level
#     database management operations like destroy and create. You can enable
#     these tests by setting the TKP_TESTDBMANAGEMENT environment variable.
#     """
# 
#     if os.environ.get("TKP_TESTDBMANAGEMENT", False):
#         return lambda func: func
#     return unittest.skip("DB management tests disabled, TKP_TESTDBMANAGEMENT"
#                          " not set")


import unittest
import tkp.db.sql.populate
import os
import getpass
from tkp.testutil.decorators import requires_test_db_managed
config = {
    'engine':  os.environ.get('TKP_DBENGINE', 'postgresql'),
    'database': 'test_management',
    'user': os.environ.get('TKP_DBUSER', getpass.getuser()),
    'password': os.environ.get('TKP_DBPASSWORD', getpass.getuser()),
    'host': os.environ.get('TKP_DBHOST', 'localhost'),
    'port': os.environ.get('TKP_DBPORT', '5432'),
    'yes': True,
    'destroy': True,
}


class TestPopulate(unittest.TestCase):
    """
    To run these tests you need to enable TKP_TESTDBMANAGMENT.

    This is potentially dangerous, since it will create and destroy databases.

    This test expects a test_management db, other connection parameters can be
    set using TKP_DBUSER, TKP_DBPASSWORD, TKP_DBHOST and TKP_DBPORT.


    """
    def test_verify(self):
        tkp.db.sql.populate.get_input = lambda x: "N"
        with self.assertRaises(SystemExit):
            tkp.db.sql.populate.verify(config)
        tkp.db.sql.populate.get_input = lambda x: "y"
        tkp.db.sql.populate.verify(config)


# Path: tkp/testutil/decorators.py
# def requires_test_db_managed():
#     """
#     This decorator is used to disable tests that do potentially low level
#     database management operations like destroy and create. You can enable
#     these tests by setting the TKP_TESTDBMANAGEMENT environment variable.
#     """
# 
#     if os.environ.get("TKP_TESTDBMANAGEMENT", False):
#         return lambda func: func
#     return unittest.skip("DB management tests disabled, TKP_TESTDBMANAGEMENT"
#                          " not set")


# Path: tests/test_database/test_sql/test_populate.py
import unittest
import tkp.db.sql.populate
import os
import getpass
from tkp.testutil.decorators import requires_test_db_managed

config = {
    'engine':  os.environ.get('TKP_DBENGINE', 'postgresql'),
    'database': 'test_management',
    'user': os.environ.get('TKP_DBUSER', getpass.getuser()),
    'password': os.environ.get('TKP_DBPASSWORD', getpass.getuser()),
    'host': os.environ.get('TKP_DBHOST', 'localhost'),
    'port': os.environ.get('TKP_DBPORT', '5432'),
    'yes': True,
    'destroy': True,
}


class TestPopulate(unittest.TestCase):
    """
    To run these tests you need to enable TKP_TESTDBMANAGMENT.

    This is potentially dangerous, since it will create and destroy databases.

    This test expects a test_management db, other connection parameters can be
    set using TKP_DBUSER, TKP_DBPASSWORD, TKP_DBHOST and TKP_DBPORT.


    """
    def test_verify(self):
        tkp.db.sql.populate.get_input = lambda x: "N"
        with self.assertRaises(SystemExit):
            tkp.db.sql.populate.verify(config)
        tkp.db.sql.populate.get_input = lambda x: "y"
        tkp.db.sql.populate.verify(config)


    @requires_test_db_managed()