import json
import os

import pytest

from utils import login, get_table


def pytest_generate_tests(metafunc):
    if hasattr(metafunc, 'function'):
        fcode = metafunc.function.func_code
        if 'visualization' in fcode.co_varnames[:fcode.co_argcount]:
            tables = json.load(
                open(
                    os.path.join(
                        os.path.dirname(__file__),
                        'fixtures',
                        'schema2',
                        'tables.json')))
            metafunc.parametrize(['visualization'], [[x] for x in tables])


@pytest.fixture(autouse=True)
def freezetime(freezer):
    freezer.move_to('2018-12-07 16:53:00')


def test_simple(schema2, app, admin, visualization):
    login(app, admin)
    response = app.get('/')

    visualization_page = response.click(lambda x: x == visualization)
    assert 'big-msg-info' not in visualization_page
    assert schema2['tables'][visualization] == get_table(visualization_page)
