import pytest
from oaa.app_runners.custom_app import CustomAppRunner
from oaa.hooks.decorators import HOOK_EVENTS, OAAHookEvent
import logging
logging.basicConfig(log_level=logging.debug)
logger = logging.getLogger(__name__)


@pytest.fixture
def _config(config):
    HOOK_EVENTS[OAAHookEvent.PRE_TRANSFORM]['results'] = []
    config.update(config_file='./tests/config-with-hooks.yaml')

    yield config
    config.reset()

# If hooks are defined in a logic module, then we should be able to find them
# in oaa.app_runners.decorators.HOOK_EVENTS


def test_pre_transform_in_hooks(_config):
    assert _config.sources
    assert HOOK_EVENTS[OAAHookEvent.PRE_TRANSFORM]
    import myhooks
    assert myhooks.do_something in HOOK_EVENTS[OAAHookEvent.PRE_TRANSFORM]['hooks']
    assert HOOK_EVENTS[OAAHookEvent.PRE_TRANSFORM]['results'] == []


def test_hooks_run(_config):
    assert _config.sources
    runner = CustomAppRunner()
    runner.run(push_to_oaa=False)

    assert 'wacka' in HOOK_EVENTS[OAAHookEvent.PRE_TRANSFORM]['results']
