Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'test_zen' into develop

  • Loading branch information...
commit 0a7a630899aef3d2223295c143e940ee60de53ed 2 parents a163601 + a0ead21
@dduan authored
View
44 runtests.py
@@ -0,0 +1,44 @@
+#!/usr/bin/env python
+
+from django.conf import settings
+
+if not settings.configured:
+ settings.configure(
+ DATABASE_ENGINE = 'sqlite3',
+ TEMPLATE_LOADERS = (
+ 'django.template.loaders.filesystem.Loader',
+ 'django.template.loaders.app_directories.Loader',
+ ),
+ MIDDLEWARE_CLASSES = (
+ 'django.middleware.common.CommonMiddleware',
+ 'django.middleware.csrf.CsrfViewMiddleware',
+ ),
+ INSTALLED_APPS = (
+ 'django.contrib.auth',
+ 'django.contrib.contenttypes',
+ 'django.contrib.sites',
+ 'django.contrib.sitemaps',
+ 'sophie',
+ ),
+ ROOT_URLCONF = 'sophie.tests.base_urls',
+ SOPHIE_ENABLES_MULTIBLOG = True,
+ SITE_ID = 1,
+ )
+
+from os.path import dirname, abspath
+import sys
+
+from django.test.simple import run_tests
+
+def runtests(*test_args):
+ if not test_args:
+ test_args = ['sophie']
+ parent = dirname(abspath(__file__))
+ sys.path.insert(0, parent)
+ failures = run_tests(test_args, verbosity=1)
+ sys.exit(failures)
+
+if __name__ == '__main__':
+ runtests(*sys.argv[1:])
+
+
View
290 sophie/fixtures/integrity.json
@@ -0,0 +1,290 @@
+[
+ {
+ "pk": 1,
+ "model": "sites.site",
+ "fields": {
+ "domain": "localhost:8000",
+ "name": "local"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "sophie.blog",
+ "fields": {
+ "feed_length": 15,
+ "disqus_shortname": "",
+ "description": "Description of Blog 1",
+ "title": "Blog 1",
+ "highlight_code": true,
+ "full_entry_in_page": true,
+ "feed_service": "",
+ "g_analytics_tracking_id": "",
+ "page_length": 3,
+ "slug": "blog-1",
+ "full_entry_in_feed": true
+ }
+ },
+ {
+ "pk": 10,
+ "model": "sophie.blog",
+ "fields": {
+ "feed_length": 15,
+ "disqus_shortname": "",
+ "description": "Description of Blog 2.",
+ "title": "Blog 2",
+ "highlight_code": true,
+ "full_entry_in_page": true,
+ "feed_service": "",
+ "g_analytics_tracking_id": "",
+ "page_length": 5,
+ "slug": "blog-2",
+ "full_entry_in_feed": true
+ }
+ },
+ {
+ "pk": 13,
+ "model": "sophie.category",
+ "fields": {
+ "shown": false,
+ "description": "Description of Category 1.",
+ "title": "Category 1",
+ "blog": 1,
+ "entry_count": 2,
+ "slug": "category-1"
+ }
+ },
+ {
+ "pk": 15,
+ "model": "sophie.category",
+ "fields": {
+ "shown": true,
+ "description": "Description of Category 2.",
+ "title": "Category 2",
+ "blog": 1,
+ "entry_count": 6,
+ "slug": "category-2"
+ }
+ },
+ {
+ "pk": 17,
+ "model": "sophie.category",
+ "fields": {
+ "shown": true,
+ "description": "Description of Category 3.",
+ "title": "Category 3",
+ "blog": 1,
+ "entry_count": 0,
+ "slug": "category-3"
+ }
+ },
+ {
+ "pk": 19,
+ "model": "sophie.category",
+ "fields": {
+ "shown": true,
+ "description": "Description of Category 4.",
+ "title": "Category 4",
+ "blog": 10,
+ "entry_count": 1,
+ "slug": "category-4"
+ }
+ },
+ {
+ "pk": 38,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 19,
+ "body": "Body of Essay 9.",
+ "title": "Essay 9",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 9.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 10,
+ "teaser": "Description of Essay 9.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:51:18",
+ "slug": "essay-9",
+ "teaser_html": "<p>Description of Essay 9.</p>"
+ }
+ },
+ {
+ "pk": 36,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Body of Essay 8.",
+ "title": "Essay 8",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 8.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 8.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:50:28",
+ "slug": "essay-8",
+ "teaser_html": "<p>Description of Essay 8.</p>"
+ }
+ },
+ {
+ "pk": 34,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Body of Essay 7.",
+ "title": "Essay 7",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 7.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 7.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:49:52",
+ "slug": "essay-7",
+ "teaser_html": "<p>Description of Essay 7.</p>"
+ }
+ },
+ {
+ "pk": 32,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Body of Essay 6.",
+ "title": "Essay 6",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 6.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 6.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:49:11",
+ "slug": "essay-6",
+ "teaser_html": "<p>Description of Essay 6.</p>"
+ }
+ },
+ {
+ "pk": 30,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Description of Essay 5.",
+ "title": "Essay 5",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Description of Essay 5.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 5.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:48:47",
+ "slug": "essay-5",
+ "teaser_html": "<p>Description of Essay 5.</p>"
+ }
+ },
+ {
+ "pk": 28,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Body of Essay 4.",
+ "title": "Essay 4",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 4.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 4.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:48:08",
+ "slug": "essay-4",
+ "teaser_html": "<p>Description of Essay 4.</p>"
+ }
+ },
+ {
+ "pk": 26,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 15,
+ "body": "Body of Essay 3.",
+ "title": "Essay 3",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 3.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 3.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:47:31",
+ "slug": "essay-3",
+ "teaser_html": "<p>Description of Essay 3.</p>"
+ }
+ },
+ {
+ "pk": 24,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 13,
+ "body": "Body of Essay 2.",
+ "title": "Essay 2",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 2.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 2.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:47:06",
+ "slug": "essay-2",
+ "teaser_html": "<p>Description of Essay 2.</p>"
+ }
+ },
+ {
+ "pk": 22,
+ "model": "sophie.entry",
+ "fields": {
+ "category": 13,
+ "body": "Body of Essay 1.",
+ "title": "Essay 1",
+ "markup": 1,
+ "author": 1,
+ "body_html": "<p>Body of Essay 1.</p>",
+ "last_update": "2010-08-12 00:14:53",
+ "blog": 1,
+ "teaser": "Description of Essay 1.",
+ "status": 1,
+ "allow_comment": true,
+ "pub_date": "2010-08-12 04:46:31",
+ "slug": "essay-1",
+ "teaser_html": "<p>Description of Essay 1.</p>"
+ }
+ },
+ {
+ "pk": 1,
+ "model": "auth.user",
+ "fields": {
+ "username": "dan",
+ "first_name": "DaNmarner",
+ "last_name": "",
+ "is_active": true,
+ "is_superuser": true,
+ "is_staff": true,
+ "last_login": "2010-08-12 00:11:02",
+ "groups": [],
+ "user_permissions": [],
+ "password": "sha1$e16e7$fd1a23d90ef504cfb4cac6104faa69151495c9e6",
+ "email": "dan@test.com",
+ "date_joined": "2010-08-12 00:10:17"
+ }
+ }
+]
View
3  sophie/tests/__init__.py
@@ -0,0 +1,3 @@
+from integrity_tests import *
+from utils_tests import *
+from model_tests import *
View
7 sophie/tests/base_urls.py
@@ -0,0 +1,7 @@
+from django.conf.urls.defaults import *
+from django.conf import settings
+
+urlpatterns = patterns('',
+ (r'', include('sophie.urls')),
+)
+
View
37 sophie/tests/integrity_tests.py
@@ -0,0 +1,37 @@
+from django.test import TestCase
+
+class MultiBlogIntegrityTest(TestCase):
+
+ fixtures = ['integrity']
+
+ def test_home_page_integrity(self):
+ response = self.client.get('/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_blog_index_integrity(self):
+ response = self.client.get('/blog-2/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_entry_list_integrity(self):
+ response = self.client.get('/blog-1/entries/1/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_entry_details_integrity(self):
+ response = self.client.get('/blog-1/entry/essay-1/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_category_details_integrity(self):
+ response = self.client.get('/blog-1/category/category-1/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_original_feed_integrity(self):
+ response = self.client.get('/blog-2/feed/')
+ self.assertEquals(response.status_code, 200)
+
+ def test_root_sitemap_integrity(self):
+ response = self.client.get('/sitemap.xml')
+ self.assertEquals(response.status_code, 200)
+
+ def test_blog_sitemap_integrity(self):
+ response = self.client.get('/blog-2/sitemap.xml')
+ self.assertEquals(response.status_code, 200)
View
36 sophie/tests/model_tests.py
@@ -0,0 +1,36 @@
+from django.test import TestCase
+from django.contrib.auth.models import User
+from sophie.models import Blog, Category, Entry
+
+class EntrySaveTest(TestCase):
+ def setUp(self):
+ self.user = User(username='DaN',password='DaN@gmail.com')
+ self.user.save()
+ self.blog = Blog(
+ title = "Test Blog",
+ slug = "test-blog",
+ description = "Testing is cool",
+ )
+ self.blog.save()
+ self.category = Category(
+ title = "Test Category",
+ slug = "test-category",
+ blog = self.blog
+ )
+ self.category.save()
+ self.entry = Entry(
+ category = self.category,
+ blog = self.blog,
+ slug = "test-entry",
+ title = "test entry",
+ author = self.user,
+ body = 'code goes like this:\n\n'
+ ' #!python \n'
+ ' from django import http \n'
+ )
+ self.target_body = u'<p>code goes like this:</p>\n<table class="codehilitetable"><tr><td class="linenos"><div class="linenodiv"><pre>1</pre></div></td><td class="code"><div class="codehilite"><pre><span class="kn">from</span> <span class="nn">django</span> <span class="kn">import</span> <span class="n">http</span>\n</pre></div>\n</td></tr></table>'
+ self.entry.save()
+
+ def test_that_markdown_works(self):
+ self.failUnlessEqual(self.entry.body_html, self.target_body)
+
View
88 sophie/tests/utils_tests.py
@@ -0,0 +1,88 @@
+from django.test import TestCase
+
+from sophie.utils import route_template, LaidbackPaginator
+
+class UtilRouteTemplateTest(TestCase):
+
+ def setUp(self):
+ self.base = 'testbase'
+ self.extra = 'xxx_yyy'
+ self.blog = 'test_slug'
+ def test_routing_with_full_args(self):
+ expected_result = [
+ r'sophie/test_slug/testbase_xxx_yyy.html',
+ r'sophie/test_slug/testbase.html',
+ r'sophie/default/testbase_xxx_yyy.html',
+ r'sophie/default/testbase.html'
+ ]
+
+ tested_result = route_template(self.base, self.extra, self.blog)
+ self.assertEqual(tested_result, expected_result)
+
+ def test_routing_fails_without_args_basename(self):
+ # With 0 args, should raise a TypeError
+ self.assertRaises(TypeError, route_template, ())
+ # basename is a must have!
+ self.assertRaises(
+ TypeError,
+ route_template,
+ (),
+ { 'basename': self.base, 'blog_slug': self.blog }
+ )
+ self.assertRaises(
+ TypeError,
+ route_template,
+ (),
+ { 'blog_slug':self.blog }
+ )
+ self.assertRaises(
+ TypeError,
+ route_template,
+ (),
+ { 'basename': self.base, }
+ )
+
+ def test_routing_with_only_basename(self):
+ expected_result = [
+ r'sophie/default/testbase_.html',
+ r'sophie/default/testbase.html',
+ r'sophie/default/testbase_.html',
+ r'sophie/default/testbase.html'
+ ]
+
+ tested_result = route_template(self.base)
+ self.assertEqual(tested_result, expected_result)
+
+ def test_routing_without_extraname_args(self):
+ expected_result = [
+ r'sophie/test_slug/testbase_.html',
+ r'sophie/test_slug/testbase.html',
+ r'sophie/default/testbase_.html',
+ r'sophie/default/testbase.html'
+ ]
+
+ tested_result = route_template(self.base, blog_slug=self.blog)
+ self.assertEqual(tested_result, expected_result)
+
+class UtilLaidbackPaginatorPageMethodTest(TestCase):
+ def setUp(self):
+ self.dummy_data = range(0,20)
+ self.PAGE_BY = 5
+ self.pages = LaidbackPaginator(self.dummy_data, self.PAGE_BY)
+
+ def test_should_return_normally(self):
+ p = self.pages.page('2').object_list
+ self.assertEquals(p, [5, 6, 7, 8, 9])
+
+ def test_should_tolerate_nonsense_arg(self):
+ p = self.pages.page(None).object_list
+ self.assertEquals(p, [0, 1, 2, 3, 4])
+
+ def test_should_accept_over_ranged_arg(self):
+ p = self.pages.page(10).object_list
+ self.assertEquals(p, [15, 16, 17, 18, 19])
+
+ def test_should_accept_under_ranged_arg(self):
+ p = self.pages.page(0).object_list
+ self.assertEquals(p, [15, 16, 17, 18, 19])
+
View
3  sophie/utils.py
@@ -16,6 +16,7 @@ def route_template(basename, extraname='', blog_slug='default'):
basename: the file name of the template.
extraname: the extra infomation about a template, usually a slug of an
entry, category or tag.
+ blog_slug: the slug of the blog being accessed
The given basename is looked for in the following order:
@@ -24,7 +25,7 @@ def route_template(basename, extraname='', blog_slug='default'):
3. sophie/default/[basename]_[extraname].html
4. sophie/default/[basename].html
- returns a compiled template instance as well as its path
+ returns a list of candidiates of the requested template.
'''
return [
r'sophie/%s/%s_%s.html' % (blog_slug, basename, extraname),
Please sign in to comment.
Something went wrong with that request. Please try again.