From cefbcda91d6f9d5a0fce97c7b72844f8dcb8d8cf Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 28 May 2014 12:51:44 +0200 Subject: [PATCH] Load tags sql on connection is created on tests. --- tests/conftest.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/conftest.py b/tests/conftest.py index 4fdb93c7..3c075a3d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,4 +1,8 @@ import pytest +import os.path +from functools import lru_cache + +from django.conf import settings from .fixtures import * @@ -10,3 +14,18 @@ def pytest_addoption(parser): def pytest_runtest_setup(item): if "slow" in item.keywords and not item.config.getoption("--runslow"): pytest.skip("need --runslow option to run") + +@lru_cache(maxsize=4) +def _get_sql(): + path = os.path.join(settings.BASE_DIR, "sql", "tags.sql") + with open(path, "r") as f: + return f.read() + + +def on_db_connect(sender, connection, **kwargs): + cursor = connection.cursor() + cursor.execute(_get_sql()) + + +from django.db.backends import signals +signals.connection_created.connect(on_db_connect)