зеркало из https://github.com/mozilla/treeherder.git
Bug 1193836 - Use a dedicated settings file for testing
This commit is contained in:
Родитель
987f803732
Коммит
247cc3de64
|
@ -14,6 +14,7 @@ env:
|
|||
- DATABASE_URL='mysql://root@localhost/treeherder'
|
||||
- DATABASE_URL_RO='mysql://root@localhost/treeherder'
|
||||
- TREEHERDER_DJANGO_SECRET_KEY='secretkey-1234'
|
||||
- DJANGO_SETTINGS_MODULE='tests.settings'
|
||||
services:
|
||||
- rabbitmq
|
||||
- memcached
|
||||
|
|
|
@ -8,4 +8,4 @@ isort --check-only --diff --quiet \
|
|||
|| { echo "isort errors found! Run 'isort' with no options to fix."; exit 1; }
|
||||
|
||||
echo "Running Python tests"
|
||||
py.test tests/
|
||||
DJANGO_SETTINGS_MODULE=tests.settings py.test tests/
|
||||
|
|
|
@ -6,6 +6,7 @@ from os.path import dirname
|
|||
import kombu
|
||||
import pytest
|
||||
import responses
|
||||
from django.conf import settings
|
||||
from django.core.management import call_command
|
||||
from requests import Request
|
||||
from requests_hawk import HawkAuth
|
||||
|
@ -33,29 +34,13 @@ def pytest_sessionstart(session):
|
|||
|
||||
"""
|
||||
sys.path.append(dirname(dirname(__file__)))
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "treeherder.config.settings")
|
||||
from django.conf import settings
|
||||
from django.test.runner import DiscoverRunner
|
||||
|
||||
# we don't actually let Django run the tests, but we need to use some
|
||||
# methods of its runner for setup/teardown of dbs and some other things
|
||||
session.django_runner = DiscoverRunner()
|
||||
# this provides templates-rendered debugging info and locmem mail storage
|
||||
session.django_runner.setup_test_environment()
|
||||
|
||||
settings.DATABASES["default"]["TEST_NAME"] = "test_treeherder"
|
||||
|
||||
# this makes celery calls synchronous, useful for unit testing
|
||||
settings.CELERY_ALWAYS_EAGER = True
|
||||
settings.CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
|
||||
|
||||
# Don't attempt to submit bug associations to Elasticsearch.
|
||||
settings.MIRROR_CLASSIFICATIONS = False
|
||||
|
||||
# Reconfigure pulse to operate on default vhost of rabbitmq
|
||||
settings.PULSE_URI = settings.BROKER_URL
|
||||
settings.PULSE_EXCHANGE_NAMESPACE = 'test'
|
||||
|
||||
|
||||
def pytest_sessionfinish(session):
|
||||
"""Tear down the test environment, including databases."""
|
||||
|
@ -118,9 +103,8 @@ def initial_data():
|
|||
@pytest.fixture(scope='function')
|
||||
def jm(request):
|
||||
""" Give a test access to a JobsModel instance. """
|
||||
from django.conf import settings
|
||||
from treeherder.model.derived.jobs import JobsModel
|
||||
model = JobsModel.create(settings.DATABASES["default"]["TEST_NAME"])
|
||||
model = JobsModel.create(settings.DATABASES["default"]["TEST"]["NAME"])
|
||||
|
||||
# patch in additional test-only procs on the datasources
|
||||
add_test_procs_file(
|
||||
|
@ -153,9 +137,8 @@ def add_test_procs_file(dhub, key, filename):
|
|||
|
||||
@pytest.fixture()
|
||||
def jobs_ds():
|
||||
from django.conf import settings
|
||||
from treeherder.model.models import Datasource
|
||||
return Datasource.objects.create(project=settings.DATABASES["default"]["TEST_NAME"])
|
||||
return Datasource.objects.create(project=settings.DATABASES["default"]["TEST"]["NAME"])
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
|
@ -178,12 +161,11 @@ def sample_resultset(sample_data):
|
|||
@pytest.fixture
|
||||
def test_project():
|
||||
from django.conf import settings
|
||||
return settings.DATABASES["default"]["TEST_NAME"]
|
||||
return settings.DATABASES["default"]["TEST"]["NAME"]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def test_repository():
|
||||
from django.conf import settings
|
||||
from treeherder.model.models import Repository, RepositoryGroup
|
||||
|
||||
RepositoryGroup.objects.create(
|
||||
|
@ -194,7 +176,7 @@ def test_repository():
|
|||
|
||||
return Repository.objects.create(
|
||||
dvcs_type="hg",
|
||||
name=settings.DATABASES["default"]["TEST_NAME"],
|
||||
name=settings.DATABASES["default"]["TEST"]["NAME"],
|
||||
url="https://hg.mozilla.org/mozilla-central",
|
||||
active_status="active",
|
||||
codebase="gecko",
|
||||
|
@ -392,8 +374,6 @@ def activate_responses(request):
|
|||
|
||||
|
||||
def pulse_consumer(exchange, request):
|
||||
from django.conf import settings
|
||||
|
||||
exchange_name = 'exchange/{}/v1/{}'.format(
|
||||
settings.PULSE_EXCHANGE_NAMESPACE,
|
||||
exchange
|
||||
|
|
|
@ -16,7 +16,7 @@ def test_get_revision_hash_none(mock_get_remote_content,
|
|||
initial_data, result_set_stored):
|
||||
"""Test that none is returned if the revision doesn't exist"""
|
||||
from treeherder.etl import common
|
||||
project = settings.DATABASES["default"]["TEST_NAME"]
|
||||
project = settings.DATABASES["default"]["TEST"]["NAME"]
|
||||
revision = "fakerevision"
|
||||
resultset = common.lookup_revisions({project: [revision]})
|
||||
assert len(resultset) == 0
|
||||
|
|
|
@ -173,6 +173,6 @@ def result_set(**kwargs):
|
|||
# same name as the db test name in settings. If this is not
|
||||
# the same, the tests will not pass.
|
||||
for rev in defaults["revisions"]:
|
||||
rev["repository"] = settings.DATABASES["default"]["TEST_NAME"]
|
||||
rev["repository"] = settings.DATABASES["default"]["TEST"]["NAME"]
|
||||
|
||||
return defaults
|
||||
|
|
|
@ -83,7 +83,7 @@ class SampleData(object):
|
|||
# the same, the tests will not pass.
|
||||
for rs in self.resultset_data:
|
||||
for rev in rs["revisions"]:
|
||||
rev["repository"] = settings.DATABASES["default"]["TEST_NAME"]
|
||||
rev["repository"] = settings.DATABASES["default"]["TEST"]["NAME"]
|
||||
|
||||
def get_log_path(self, name):
|
||||
"""Returns the full path to a log file"""
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
from treeherder.config.settings import *
|
||||
|
||||
DATABASES["default"]["TEST"] = {"NAME": "test_treeherder"}
|
||||
|
||||
# this makes celery calls synchronous, useful for unit testing
|
||||
CELERY_ALWAYS_EAGER = True
|
||||
CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
|
||||
|
||||
# Don't attempt to submit bug associations to Bugzilla & Elasticsearch.
|
||||
MIRROR_CLASSIFICATIONS = False
|
||||
|
||||
# Reconfigure pulse to operate on default vhost of rabbitmq
|
||||
PULSE_URI = BROKER_URL
|
||||
PULSE_EXCHANGE_NAMESPACE = 'test'
|
Загрузка…
Ссылка в новой задаче