initial
This commit is contained in:
24
testproject/README.md
Normal file
24
testproject/README.md
Normal file
@@ -0,0 +1,24 @@
|
||||
Testing
|
||||
===========
|
||||
|
||||
This project can be run directly with the manage.py script, provided
|
||||
that you have checked out the root of the Git repository.
|
||||
|
||||
It comes with a prepopulated SQLite database.
|
||||
|
||||
Running
|
||||
-------
|
||||
|
||||
You should be able to immediately run it like this:
|
||||
|
||||
python manage.py runserver
|
||||
|
||||
The settings come in a package to administer several test scenarios. For simple purposes, simply edit `local.py`.
|
||||
|
||||
Login
|
||||
-----
|
||||
|
||||
Django admin:
|
||||
|
||||
Username: admin
|
||||
Password: admin
|
||||
10
testproject/manage.py
Normal file
10
testproject/manage.py
Normal file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env python
|
||||
import os
|
||||
import sys
|
||||
|
||||
if __name__ == "__main__":
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
|
||||
|
||||
from django.core.management import execute_from_command_line
|
||||
|
||||
execute_from_command_line(sys.argv)
|
||||
0
testproject/testproject/__init__.py
Normal file
0
testproject/testproject/__init__.py
Normal file
408
testproject/testproject/fixtures/fixtures.json
Normal file
408
testproject/testproject/fixtures/fixtures.json
Normal file
File diff suppressed because one or more lines are too long
33
testproject/testproject/middleware.py
Normal file
33
testproject/testproject/middleware.py
Normal file
@@ -0,0 +1,33 @@
|
||||
from django.contrib import messages
|
||||
|
||||
|
||||
MSG = (
|
||||
"This is a Django-Wiki demo, every 2 hours all data is removed from the server. "
|
||||
"If you want to test something try login with admin:admin - "
|
||||
"Please be respectful with the other visitors."
|
||||
)
|
||||
|
||||
|
||||
class DemoMiddleware:
|
||||
def __init__(self, get_response):
|
||||
self.get_response = get_response
|
||||
|
||||
def __call__(self, request):
|
||||
|
||||
# Code to be executed for each request before
|
||||
# the view (and later middleware) are called.
|
||||
demo_message_exists = False
|
||||
storage = messages.get_messages(request)
|
||||
for message in storage:
|
||||
if str(message) == MSG:
|
||||
demo_message_exists = True
|
||||
storage.used = False
|
||||
if not demo_message_exists:
|
||||
messages.add_message(request, messages.WARNING, MSG)
|
||||
|
||||
response = self.get_response(request)
|
||||
|
||||
# Code to be executed for each request/response after
|
||||
# the view is called.
|
||||
|
||||
return response
|
||||
4
testproject/testproject/settings/__init__.py
Normal file
4
testproject/testproject/settings/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
try:
|
||||
from .local import *
|
||||
except ImportError:
|
||||
from .base import *
|
||||
130
testproject/testproject/settings/base.py
Normal file
130
testproject/testproject/settings/base.py
Normal file
@@ -0,0 +1,130 @@
|
||||
import os
|
||||
|
||||
from django.urls import reverse_lazy
|
||||
|
||||
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
BASE_DIR = os.path.dirname(PROJECT_DIR)
|
||||
|
||||
# Quick-start development settings - unsuitable for production
|
||||
# See https://docs.djangoproject.com/en/stable/howto/deployment/checklist/
|
||||
|
||||
# SECURITY WARNING: keep the secret key used in production secret!
|
||||
SECRET_KEY = "b^fv_)t39h%9p40)fnkfblo##jkr!$0)lkp6bpy!fi*f$4*92!"
|
||||
|
||||
# SECURITY WARNING: don't run with debug turned on in production!
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = []
|
||||
|
||||
|
||||
INSTALLED_APPS = [
|
||||
"django.contrib.humanize.apps.HumanizeConfig",
|
||||
"django.contrib.auth.apps.AuthConfig",
|
||||
"django.contrib.contenttypes.apps.ContentTypesConfig",
|
||||
"django.contrib.sessions.apps.SessionsConfig",
|
||||
"django.contrib.sites.apps.SitesConfig",
|
||||
"django.contrib.messages.apps.MessagesConfig",
|
||||
"django.contrib.staticfiles.apps.StaticFilesConfig",
|
||||
"django.contrib.admin.apps.AdminConfig",
|
||||
"django.contrib.admindocs.apps.AdminDocsConfig",
|
||||
"sekizai",
|
||||
"sorl.thumbnail",
|
||||
"django_nyt.apps.DjangoNytConfig",
|
||||
"wiki.apps.WikiConfig",
|
||||
"wiki.plugins.images.apps.ImagesConfig",
|
||||
"wiki.plugins.links.apps.LinksConfig",
|
||||
"wiki.plugins.macros.apps.MacrosConfig",
|
||||
"wiki.plugins.attachments.apps.AttachmentsConfig",
|
||||
"wiki.plugins.notifications.apps.NotificationsConfig",
|
||||
"wiki.plugins.editsection.apps.EditSectionConfig",
|
||||
"wiki.plugins.globalhistory.apps.GlobalHistoryConfig",
|
||||
"wiki.plugins.pymdown.apps.PyMdownConfig",
|
||||
"wiki.plugins.help.apps.HelpConfig",
|
||||
"mptt",
|
||||
]
|
||||
|
||||
TEST_RUNNER = "django.test.runner.DiscoverRunner"
|
||||
|
||||
MIDDLEWARE = [
|
||||
"django.middleware.security.SecurityMiddleware",
|
||||
"django.contrib.sessions.middleware.SessionMiddleware",
|
||||
"django.middleware.common.CommonMiddleware",
|
||||
"django.middleware.csrf.CsrfViewMiddleware",
|
||||
"django.contrib.auth.middleware.AuthenticationMiddleware",
|
||||
"django.contrib.messages.middleware.MessageMiddleware",
|
||||
"django.middleware.clickjacking.XFrameOptionsMiddleware",
|
||||
]
|
||||
|
||||
|
||||
ROOT_URLCONF = "testproject.urls"
|
||||
|
||||
TEMPLATES = [
|
||||
{
|
||||
"BACKEND": "django.template.backends.django.DjangoTemplates",
|
||||
"DIRS": [
|
||||
os.path.join(PROJECT_DIR, "templates"),
|
||||
],
|
||||
"APP_DIRS": True,
|
||||
"OPTIONS": {
|
||||
"context_processors": [
|
||||
"django.contrib.auth.context_processors.auth",
|
||||
"django.template.context_processors.debug",
|
||||
"django.template.context_processors.i18n",
|
||||
"django.template.context_processors.request",
|
||||
"django.template.context_processors.tz",
|
||||
"django.contrib.messages.context_processors.messages",
|
||||
"sekizai.context_processors.sekizai",
|
||||
],
|
||||
"debug": DEBUG,
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
WSGI_APPLICATION = "testproject.wsgi.application"
|
||||
|
||||
|
||||
LOGIN_REDIRECT_URL = reverse_lazy("wiki:get", kwargs={"path": ""})
|
||||
|
||||
|
||||
# Database
|
||||
# https://docs.djangoproject.com/en/stable/ref/settings/#databases
|
||||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join(PROJECT_DIR, "db.sqlite3"),
|
||||
}
|
||||
}
|
||||
|
||||
# Internationalization
|
||||
# https://docs.djangoproject.com/en/stable/topics/i18n/
|
||||
|
||||
TIME_ZONE = "Europe/Berlin"
|
||||
|
||||
# Language code for this installation. All choices can be found here:
|
||||
# http://www.i18nguy.com/unicode/language-identifiers.html
|
||||
LANGUAGE_CODE = "en-US"
|
||||
|
||||
SITE_ID = 1
|
||||
|
||||
USE_I18N = True
|
||||
|
||||
USE_L10N = True
|
||||
|
||||
USE_TZ = True
|
||||
|
||||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/stable/howto/static-files/
|
||||
|
||||
STATIC_URL = "/static/"
|
||||
STATIC_ROOT = os.path.join(PROJECT_DIR, "static")
|
||||
MEDIA_ROOT = os.path.join(PROJECT_DIR, "media")
|
||||
MEDIA_URL = "/media/"
|
||||
|
||||
|
||||
WIKI_ANONYMOUS_WRITE = True
|
||||
WIKI_ANONYMOUS_CREATE = False
|
||||
|
||||
SESSION_COOKIE_SECURE = True
|
||||
|
||||
DEFAULT_AUTO_FIELD = "django.db.models.AutoField"
|
||||
14
testproject/testproject/settings/codehilite.py
Normal file
14
testproject/testproject/settings/codehilite.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from testproject.settings import *
|
||||
from testproject.settings.local import *
|
||||
|
||||
# Test codehilite with pygments
|
||||
|
||||
WIKI_MARKDOWN_KWARGS = {
|
||||
"extensions": [
|
||||
"codehilite",
|
||||
"footnotes",
|
||||
"attr_list",
|
||||
"headerid",
|
||||
"extra",
|
||||
]
|
||||
}
|
||||
25
testproject/testproject/settings/customauthuser.py
Normal file
25
testproject/testproject/settings/customauthuser.py
Normal file
@@ -0,0 +1,25 @@
|
||||
import os # noqa @UnusedImport
|
||||
import sys
|
||||
|
||||
from .base import * # noqa @UnusedWildImport
|
||||
from .dev import *
|
||||
|
||||
# Append testdata path
|
||||
|
||||
sys.path.append(os.path.join(os.path.dirname(os.path.dirname(PROJECT_DIR)), "tests"))
|
||||
|
||||
DATABASES = {
|
||||
"default": {
|
||||
# Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
# Or path to database file if using sqlite3.
|
||||
"NAME": os.path.join(PROJECT_DIR, "prepopulated-customauthuser.sqlite3"),
|
||||
}
|
||||
}
|
||||
|
||||
INSTALLED_APPS = INSTALLED_APPS + [
|
||||
# Test application for testing custom users
|
||||
"testdata",
|
||||
]
|
||||
|
||||
AUTH_USER_MODEL = "testdata.CustomUser"
|
||||
9
testproject/testproject/settings/demo.py
Normal file
9
testproject/testproject/settings/demo.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from .base import * # noqa
|
||||
|
||||
DEBUG = False
|
||||
|
||||
ALLOWED_HOSTS = [".demo.django-wiki.org"]
|
||||
SESSION_COOKIE_DOMAIN = ".demo.django-wiki.org"
|
||||
SESSION_COOKIE_SECURE = True
|
||||
|
||||
MIDDLEWARE += ["testproject.middleware.DemoMiddleware"]
|
||||
35
testproject/testproject/settings/dev.py
Normal file
35
testproject/testproject/settings/dev.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from .base import * # noqa @UnusedWildImport
|
||||
from .demo import * # noqa @UnusedWildImport
|
||||
|
||||
DEBUG = True
|
||||
|
||||
for template_engine in TEMPLATES:
|
||||
template_engine["OPTIONS"]["debug"] = True
|
||||
|
||||
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
|
||||
|
||||
# Used by debug_toolbar
|
||||
INTERNAL_IPS = ["127.0.0.1"]
|
||||
|
||||
ALLOWED_HOSTS = [
|
||||
"localhost",
|
||||
"0.0.0.0",
|
||||
"127.0.0.1",
|
||||
]
|
||||
|
||||
# Removed.
|
||||
# See: https://forum.djangoproject.com/t/why-are-cookie-secure-settings-defaulted-to-false/1133/4
|
||||
# and https://github.com/django-wiki/django-wiki/pull/1325
|
||||
# SESSION_COOKIE_DOMAIN = ".localhost"
|
||||
SESSION_COOKIE_SECURE = False
|
||||
|
||||
try:
|
||||
import debug_toolbar # @UnusedImport
|
||||
|
||||
MIDDLEWARE = list(MIDDLEWARE) + [
|
||||
"debug_toolbar.middleware.DebugToolbarMiddleware",
|
||||
]
|
||||
INSTALLED_APPS = list(INSTALLED_APPS) + ["debug_toolbar"]
|
||||
DEBUG_TOOLBAR_CONFIG = {"INTERCEPT_REDIRECTS": False}
|
||||
except ImportError:
|
||||
pass
|
||||
10
testproject/testproject/settings/sendfile.py
Normal file
10
testproject/testproject/settings/sendfile.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from .base import * # noqa @UnusedWildImport
|
||||
|
||||
INSTALLED_APPS += ["sendfile"]
|
||||
|
||||
WIKI_ATTACHMENTS_USE_SENDFILE = True
|
||||
|
||||
|
||||
SENDFILE_BACKEND = "sendfile.backends.development"
|
||||
# SENDFILE_URL = None #Not needed
|
||||
# SENDFILE_ROOT = None #Not needed
|
||||
16
testproject/testproject/templates/404.html
Normal file
16
testproject/testproject/templates/404.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% extends "wiki/base.html" %}
|
||||
{% load wiki_tags i18n %}
|
||||
|
||||
{% block pagetitle %}{% trans "404" %}{% endblock %}
|
||||
|
||||
{% block wiki_breadcrumbs %}{% endblock %}
|
||||
|
||||
{% block wiki_contents %}
|
||||
|
||||
<h1 class="page-header">{% trans "404 - it's not here!" %}</h1>
|
||||
|
||||
<div class="error">
|
||||
<p>{% trans "Sorry, keep looking. Good luck!" %}</p>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
20
testproject/testproject/templates/500.html
Normal file
20
testproject/testproject/templates/500.html
Normal file
@@ -0,0 +1,20 @@
|
||||
{% extends "wiki/base.html" %}
|
||||
{% load wiki_tags i18n %}
|
||||
|
||||
{% block pagetitle %}{% trans "500 Server error" %}{% endblock %}
|
||||
|
||||
{% block wiki_breadcrumbs %}{% endblock %}
|
||||
|
||||
{% block wiki_contents %}
|
||||
|
||||
<h1 class="page-header">{% trans "500 - ERROR" %}</h1>
|
||||
|
||||
<div class="error">
|
||||
<p>{% blocktrans trimmed %}
|
||||
Oh god no the demo has failed. Please rest assured that an open source developer is reading the
|
||||
logs to resolve this, because it's fun!!
|
||||
{% endblocktrans %}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{% endblock %}
|
||||
44
testproject/testproject/urls.py
Normal file
44
testproject/testproject/urls.py
Normal file
@@ -0,0 +1,44 @@
|
||||
from django.conf import settings
|
||||
from django.contrib import admin
|
||||
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
|
||||
from django.http.response import HttpResponse
|
||||
from django.urls import include
|
||||
from django.urls import re_path
|
||||
from django.views.static import serve as static_serve
|
||||
|
||||
admin.autodiscover()
|
||||
|
||||
urlpatterns = [
|
||||
re_path(r"^admin/", admin.site.urls),
|
||||
re_path(r"^robots.txt", lambda _: HttpResponse("User-agent: *\nDisallow: /")),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += staticfiles_urlpatterns()
|
||||
urlpatterns += [
|
||||
re_path(
|
||||
r"^media/(?P<path>.*)$",
|
||||
static_serve,
|
||||
{"document_root": settings.MEDIA_ROOT},
|
||||
),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
try:
|
||||
import debug_toolbar
|
||||
|
||||
urlpatterns = [
|
||||
re_path("__debug__/", include(debug_toolbar.urls)),
|
||||
# For django versions before 2.0:
|
||||
# url(r'^__debug__/', include(debug_toolbar.urls)),
|
||||
] + urlpatterns
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
urlpatterns += [
|
||||
re_path(r"^notify/", include("django_nyt.urls")),
|
||||
re_path(r"", include("wiki.urls")),
|
||||
]
|
||||
|
||||
handler500 = "testproject.views.server_error"
|
||||
handler404 = "testproject.views.page_not_found"
|
||||
23
testproject/testproject/views.py
Normal file
23
testproject/testproject/views.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.conf import settings
|
||||
from django.shortcuts import render
|
||||
from django.views.decorators.csrf import requires_csrf_token
|
||||
|
||||
|
||||
@requires_csrf_token
|
||||
def server_error(request, template_name="500.html", **param_dict):
|
||||
return render(
|
||||
request,
|
||||
template_name,
|
||||
context={
|
||||
"MEDIA_URL": settings.MEDIA_URL,
|
||||
"STATIC_URL": settings.STATIC_URL,
|
||||
"request": request,
|
||||
},
|
||||
status=500,
|
||||
)
|
||||
|
||||
|
||||
def page_not_found(request, template_name="404.html", exception=None):
|
||||
response = server_error(request, template_name=template_name, exception=exception)
|
||||
response.status_code = 404
|
||||
return response
|
||||
36
testproject/testproject/wsgi.py
Normal file
36
testproject/testproject/wsgi.py
Normal file
@@ -0,0 +1,36 @@
|
||||
"""
|
||||
WSGI config for testproject project.
|
||||
|
||||
This module contains the WSGI application used by Django's development server
|
||||
and any production WSGI deployments. It should expose a module-level variable
|
||||
named ``application``. Django's ``runserver`` and ``runfcgi`` commands discover
|
||||
this application via the ``WSGI_APPLICATION`` setting.
|
||||
|
||||
Usually you will have the standard Django WSGI application here, but it also
|
||||
might make sense to replace the whole Django WSGI application with a custom one
|
||||
that later delegates to the Django one. For example, you could introduce WSGI
|
||||
middleware here, or combine a Django application with an application of another
|
||||
framework.
|
||||
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
|
||||
from django.core.wsgi import get_wsgi_application
|
||||
|
||||
# This application object is used by any WSGI server configured to use this
|
||||
# file. This includes Django's development server, if the WSGI_APPLICATION
|
||||
# setting points here.
|
||||
|
||||
PROJECT_PATH = os.path.abspath(os.path.split(__file__)[0])
|
||||
PROJECT_PARENT = os.path.abspath(os.path.split(PROJECT_PATH)[0])
|
||||
sys.path.append(PROJECT_PATH)
|
||||
sys.path.append(PROJECT_PARENT)
|
||||
|
||||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "testproject.settings")
|
||||
|
||||
application = get_wsgi_application()
|
||||
|
||||
# Apply WSGI middleware here.
|
||||
# from helloworld.wsgi import HelloWorldApplication
|
||||
# application = HelloWorldApplication(application)
|
||||
Reference in New Issue
Block a user