forked from servee/servee
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/replace_frontendadmin' of http://github.com/ser…
…vee/servee into feature/replace_frontendadmin
- Loading branch information
Showing
9 changed files
with
241 additions
and
9 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
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 @@ | ||
from tests import * |
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 @@ | ||
from django.contrib.flatpages.models import FlatPage | ||
from django.contrib.flatpages.admin import FlatPageAdmin | ||
|
||
import frontendadmin | ||
|
||
class FlatPageFrontendadminAdmin(FlatPageAdmin, frontendadmin.ServeeModelAdmin): | ||
""" | ||
This class extends from the normal FlatPageAdmin, as well as frontendadmin.ServeeModelAdmin | ||
The later simply adds to the templates that should be processed when looking | ||
for the templates to render this page. | ||
""" | ||
pass | ||
|
||
frontendadmin.site.register(FlatPage, FlatPageFrontendadminAdmin) |
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,50 @@ | ||
from django.test import Client | ||
from django.core.handlers.wsgi import WSGIRequest | ||
from django.core.handlers.base import BaseHandler | ||
|
||
# From: http://djangosnippets.org/snippets/2231/ | ||
# Adapted from Simon Willison's snippet: http://djangosnippets.org/snippets/963/ | ||
class RequestFactory(Client): | ||
""" | ||
Class that lets you create mock Request objects for use in testing. | ||
Usage: | ||
rf = RequestFactory() | ||
get_request = rf.get('/hello/') | ||
post_request = rf.post('/submit/', {'foo': 'bar'}) | ||
This class re-uses the django.test.client.Client interface, docs here: | ||
http://www.djangoproject.com/documentation/testing/#the-test-client | ||
Once you have a request object you can pass it to any view function, | ||
just as if that view had been hooked up using a URLconf. | ||
""" | ||
def request(self, **request): | ||
""" | ||
Similar to parent class, but returns the request object as soon as it | ||
has created it. | ||
""" | ||
environ = { | ||
'HTTP_COOKIE': self.cookies, | ||
'PATH_INFO': '/', | ||
'QUERY_STRING': '', | ||
'REQUEST_METHOD': 'GET', | ||
'SCRIPT_NAME': '', | ||
'SERVER_NAME': 'testserver', | ||
'SERVER_PORT': 80, | ||
'SERVER_PROTOCOL': 'HTTP/1.1', | ||
} | ||
environ.update(self.defaults) | ||
environ.update(request) | ||
request = WSGIRequest(environ) | ||
|
||
handler = BaseHandler() | ||
handler.load_middleware() | ||
for middleware_method in handler._request_middleware: | ||
if middleware_method(request): | ||
raise Exception("Couldn't create request object - " | ||
"request middleware returned a response") | ||
|
||
return request |
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 @@ | ||
# Django models go here |
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,22 @@ | ||
#!/usr/bin/env python | ||
|
||
import os, sys | ||
|
||
os.environ["DJANGO_SETTINGS_MODULE"] = "test_settings" | ||
|
||
parent = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..") | ||
root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "..", "..", "..") | ||
sys.path.insert(0, parent) | ||
sys.path.insert(0, root) | ||
|
||
from django.test.simple import DjangoTestSuiteRunner | ||
from django.conf import settings | ||
|
||
def runtests(): | ||
runner = DjangoTestSuiteRunner() | ||
failures = runner.run_tests(["frontendadmin"], verbosity=1, interactive=True) | ||
sys.exit(failures) | ||
|
||
if __name__ == "__main__": | ||
runtests() | ||
|
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,39 @@ | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(__file__) | ||
|
||
INSTALLED_APPS = ( | ||
"django.contrib.admin", | ||
"django.contrib.auth", | ||
"django.contrib.flatpages", | ||
"django.contrib.sessions", | ||
"django.contrib.contenttypes", | ||
"frontendadmin", | ||
"servee", | ||
) | ||
|
||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.sqlite3", | ||
} | ||
} | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
"django.middleware.common.CommonMiddleware", | ||
"django.middleware.csrf.CsrfViewMiddleware", | ||
"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware", | ||
"django.contrib.sessions.middleware.SessionMiddleware", | ||
"django.contrib.auth.middleware.AuthenticationMiddleware", | ||
) | ||
|
||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
"django.contrib.auth.context_processors.auth", | ||
"django.core.context_processors.debug", | ||
"django.core.context_processors.i18n", | ||
"django.core.context_processors.media", | ||
'django.core.context_processors.request', | ||
) | ||
|
||
ROOT_URLCONF = "frontendadmin.tests.urls" | ||
|
||
SITE_ID = 1 |
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,100 @@ | ||
from django.contrib.auth import authenticate, login | ||
from django.contrib.auth.models import User | ||
from django.contrib.flatpages.models import FlatPage | ||
from django.template import RequestContext, Template | ||
from django.test import Client, TestCase | ||
|
||
# Django 1.3's RequestFactory doesn't run requests through MiddleWare | ||
from helpers import RequestFactory | ||
|
||
|
||
class TestTemplateTags(TestCase): | ||
def setUp(self): | ||
self.user = User.objects.create(username="test") | ||
self.user.set_password("secret") | ||
self.user.is_staff = True | ||
self.user.is_superuser = True | ||
self.user.save() | ||
|
||
self.factory = RequestFactory() | ||
|
||
FlatPage.objects.create( | ||
url="/", | ||
title="Test", | ||
content="This is a test.", | ||
) | ||
|
||
def tearDown(self): | ||
pass | ||
|
||
def get_request_for_url(self, url): | ||
request = self.factory.get(url) | ||
user = authenticate(username=self.user.username, password="secret") | ||
login(request, user) | ||
return request | ||
|
||
def test_frontendadmin_add(self): | ||
frontendadmin_add_html = """<a class="frontendadmin frontendadmin_add" href="/servee/flatpages/flatpage/add/">Add a Flatpage</a>""" | ||
frontendadmin_add_plain_html = """<a class="frontendadmin frontendadmin_add" href="/servee/flatpages/flatpage/add/">Add</a>""" | ||
template = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_add flatpages "Add a Flatpage" %}\ | ||
""" ) | ||
template_plain = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_add flatpages %}\ | ||
""" ) | ||
request = self.get_request_for_url("/frontendadmin_add/") | ||
|
||
flatpages = FlatPage.objects.all() | ||
context = RequestContext(request, {"flatpages": flatpages}) | ||
# Test with custom label | ||
content = template.render(context) | ||
self.assertEqual(content, frontendadmin_add_html) | ||
# Test without custom label | ||
content = template_plain.render(context) | ||
self.assertEqual(content, frontendadmin_add_plain_html) | ||
|
||
def test_frontendadmin_change(self): | ||
frontendadmin_change_html = """<a class="frontendadmin frontendadmin_edit" href="/servee/flatpages/flatpage/1/">Edit This Flatpage</a>""" | ||
frontendadmin_change_plain_html = """<a class="frontendadmin frontendadmin_edit" href="/servee/flatpages/flatpage/1/">Change</a>""" | ||
template = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_change flatpage "Edit This Flatpage" %}\ | ||
""" ) | ||
template_plain = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_change flatpage %}\ | ||
""" ) | ||
request = self.get_request_for_url("/frontendadmin_change/") | ||
|
||
flatpage = FlatPage.objects.get(pk=1) | ||
context = RequestContext(request, {"flatpage": flatpage}) | ||
# Test with custom label | ||
content = template.render(context) | ||
self.assertEqual(content, frontendadmin_change_html) | ||
# Test without custom label | ||
content = template_plain.render(context) | ||
self.assertEqual(content, frontendadmin_change_plain_html) | ||
|
||
def test_frontendadmin_delete(self): | ||
frontendadmin_delete_html = """<a class="frontendadmin frontendadmin_delete" href="/servee/flatpages/flatpage/1/delete/">Delete This Flatpage</a>""" | ||
frontendadmin_delete_plain_html = """<a class="frontendadmin frontendadmin_delete" href="/servee/flatpages/flatpage/1/delete/">Delete</a>""" | ||
template = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_delete flatpage "Delete This Flatpage" %}\ | ||
""" ) | ||
template_plain = Template("""\ | ||
{% load frontendadmin_tags %}\ | ||
{% frontendadmin_delete flatpage %}\ | ||
""" ) | ||
request = self.get_request_for_url("/frontendadmin_delete/") | ||
|
||
flatpage = FlatPage.objects.get(pk=1) | ||
context = RequestContext(request, {"flatpage": flatpage}) | ||
# Test with custom label | ||
content = template.render(context) | ||
self.assertEqual(content, frontendadmin_delete_html) | ||
# Test without custom label | ||
content = template_plain.render(context) | ||
self.assertEqual(content, frontendadmin_delete_plain_html) |
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,9 @@ | ||
from django.conf.urls.defaults import * | ||
import frontendadmin | ||
import frontendadmin_registry | ||
|
||
|
||
urlpatterns = patterns("", | ||
url(r"^servee/", include("servee.urls")), | ||
url(r"^servee/", include(frontendadmin.site.urls)), | ||
) |