Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Skeleton for pytest tests, so I can at least try and verify the app s…
…till runs under Django version X.Y Because while I don't haystack often anymore, I'd like to keep it working for when I do.
- Loading branch information
Showing
9 changed files
with
223 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,5 @@ haystackbrowser/panels.py | |
dist | ||
django_haystackbrowser.egg-info | ||
*.pickle | ||
.eggs | ||
db.sqlite3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
import django | ||
from django.conf import settings | ||
import os | ||
|
||
|
||
HERE = os.path.realpath(os.path.dirname(__file__)) | ||
|
||
|
||
def pytest_configure(): | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests_settings") | ||
if settings.configured and hasattr(django, 'setup'): | ||
django.setup() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /usr/bin/env python | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
import os | ||
import sys | ||
sys.dont_write_bytecode = True | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "tests_settings") | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
application = get_wsgi_application() | ||
|
||
if __name__ == "__main__": | ||
from django.core.management import execute_from_command_line | ||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import absolute_import | ||
from __future__ import unicode_literals | ||
import pytest | ||
from django.core.urlresolvers import reverse, resolve | ||
from .admin import Search404 | ||
|
||
|
||
def test_app_is_mounted_accessing_changelist_but_no_models_loaded(admin_user, rf): | ||
url = reverse('admin:haystackbrowser_haystackresults_changelist') | ||
request = rf.get(url) | ||
request.user = admin_user | ||
match = resolve(url) | ||
with pytest.raises(Search404): | ||
match.func(request, *match.args, **match.kwargs) | ||
|
||
|
||
def test_app_is_mounted_viewing_details_but_no_models_loaded(admin_user, rf): | ||
url = reverse('admin:haystackbrowser_haystackresults_change', | ||
kwargs={'content_type': 1, 'pk': 1}) | ||
request = rf.get(url) | ||
request.user = admin_user | ||
match = resolve(url) | ||
with pytest.raises(Search404): | ||
match.func(request, *match.args, **match.kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
[pytest] | ||
norecursedirs=.* *.egg .svn _build src bin lib local include | ||
python_files=test_*.py | ||
addopts = --cov haystackbrowser --cov-report term --cov-report html -vvv | ||
|
||
[metadata] | ||
license-file = LICENSE | ||
|
||
[wheel] | ||
universal = 1 | ||
|
||
[flake8] | ||
max-line-length = 80 | ||
|
||
[check-manifest] | ||
ignore-default-rules = true | ||
ignore = | ||
.travis.yml | ||
.bumpversion.cfg | ||
PKG-INFO | ||
.eggs | ||
.idea | ||
.tox | ||
__pycache__ | ||
bin | ||
include | ||
lib | ||
local | ||
share | ||
.Python | ||
*.egg-info | ||
*.egg-info/* | ||
setup.cfg | ||
.hgtags | ||
.hgignore | ||
.gitignore | ||
.bzrignore | ||
*.mo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
# -*- coding: utf-8 -*- | ||
import os | ||
|
||
|
||
DEBUG = os.environ.get('DEBUG', 'on') == 'on' | ||
SECRET_KEY = os.environ.get('SECRET_KEY', 'TESTTESTTESTTESTTESTTESTTESTTEST') | ||
ALLOWED_HOSTS = os.environ.get('ALLOWED_HOSTS', 'localhost,testserver').split(',') | ||
BASE_DIR = os.path.abspath(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
INSTALLED_APPS = [ | ||
'django.contrib.sites', | ||
'django.contrib.contenttypes', | ||
'django.contrib.staticfiles', | ||
'django.contrib.auth', | ||
# need sessions for Client.login() to work | ||
'django.contrib.sessions', | ||
'django.contrib.admin', | ||
'haystack', | ||
'haystackbrowser', | ||
] | ||
|
||
SKIP_SOUTH_TESTS = True | ||
SOUTH_TESTS_MIGRATE = False | ||
|
||
STATIC_URL = '/__static__/' | ||
MEDIA_URL = '/__media__/' | ||
MESSAGE_STORAGE = 'django.contrib.messages.storage.cookie.CookieStorage' | ||
SESSION_ENGINE = 'django.contrib.sessions.backends.signed_cookies' | ||
SESSION_COOKIE_HTTPONLY = True | ||
|
||
|
||
ROOT_URLCONF = 'tests_urls' | ||
|
||
# Use a fast hasher to speed up tests. | ||
PASSWORD_HASHERS = ( | ||
'django.contrib.auth.hashers.MD5PasswordHasher', | ||
) | ||
|
||
SITE_ID = 1 | ||
|
||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
'django.contrib.auth.context_processors.auth', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
) | ||
|
||
STATIC_ROOT = os.path.join(BASE_DIR, 'tests_collectstatic') | ||
MEDIA_ROOT = os.path.join(BASE_DIR, 'tests_media') | ||
|
||
TEMPLATE_DIRS = () | ||
USE_TZ = True | ||
|
||
HAYSTACK_CONNECTIONS = { | ||
'default': { | ||
'ENGINE': 'haystack.backends.whoosh_backend.WhooshEngine', | ||
'PATH': os.path.join(BASE_DIR, 'whoosh_index'), | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf.urls import url, include | ||
from django.contrib import admin | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^admin/', include(admin.site.urls)), | ||
] |