| 1 |
# -*- coding: utf-8 -*- |
| 2 |
|
| 3 |
from __future__ import absolute_import, unicode_literals |
| 4 |
|
| 5 |
import os |
| 6 |
from django.core.exceptions import ImproperlyConfigured |
| 7 |
|
| 8 |
test_runner = None |
| 9 |
old_config = None |
| 10 |
|
| 11 |
os.environ["DJANGO_SETTINGS_MODULE"] = "tests.settings" |
| 12 |
|
| 13 |
import django |
| 14 |
if hasattr(django, "setup"): |
| 15 |
django.setup() |
| 16 |
|
| 17 |
|
| 18 |
def _geospatial_support(): |
| 19 |
try: |
| 20 |
import geopy |
| 21 |
from haystack.utils.geo import Point |
| 22 |
except (ImportError, ImproperlyConfigured): |
| 23 |
return False |
| 24 |
else: |
| 25 |
return True |
| 26 |
geospatial_support = _geospatial_support() |
| 27 |
|
| 28 |
|
| 29 |
def _restframework_version(): |
| 30 |
import rest_framework |
| 31 |
return tuple(map(int, rest_framework.VERSION.split("."))) |
| 32 |
restframework_version = _restframework_version() |
| 33 |
|
| 34 |
|
| 35 |
def _elasticsearch_version(): |
| 36 |
import elasticsearch |
| 37 |
return elasticsearch.VERSION |
| 38 |
elasticsearch_version = _elasticsearch_version() |
| 39 |
|
| 40 |
|
| 41 |
def setup(): |
| 42 |
from django.test.runner import DiscoverRunner |
| 43 |
global test_runner |
| 44 |
global old_config |
| 45 |
|
| 46 |
test_runner = DiscoverRunner() |
| 47 |
test_runner.setup_test_environment() |
| 48 |
old_config = test_runner.setup_databases() |
| 49 |
|
| 50 |
|
| 51 |
def teardown(): |
| 52 |
test_runner.teardown_databases(old_config) |
| 53 |
test_runner.teardown_test_environment() |
| 54 |
|