Corrected philo tests and removed all use of penfield models in those tests - resolve...
authorStephen Burrows <stephen.r.burrows@gmail.com>
Tue, 31 May 2011 17:16:36 +0000 (13:16 -0400)
committerStephen Burrows <stephen.r.burrows@gmail.com>
Tue, 31 May 2011 17:16:36 +0000 (13:16 -0400)
philo/fixtures/test_fixtures.json
philo/models/base.py
philo/tests.py

index 4c55372..2bda0d1 100644 (file)
@@ -91,8 +91,8 @@
             "rght": 143, 
             "view_object_id": 1, 
             "view_content_type": [
-                "penfield", 
-                "blogview"
+                "philo", 
+                "page"
             ], 
             "parent": 1, 
             "level": 1, 
         "model": "philo.redirect", 
         "fields": {
             "status_code": 302, 
-            "target": "second"
+            "url_or_subpath": "second"
         }
     }, 
     {
             "template": 6, 
             "title": "Tag Archive Page"
         }
-    }, 
-    {
-        "pk": 1, 
-        "model": "penfield.blog", 
-        "fields": {
-            "slug": "free-lovin", 
-            "title": "Free lovin'"
-        }
-    }, 
-    {
-        "pk": 1, 
-        "model": "penfield.blogentry", 
-        "fields": {
-            "content": "Lorem ipsum.\r\n\r\nDolor sit amet.", 
-            "author": 1, 
-            "title": "First Entry", 
-            "excerpt": "", 
-            "blog": 1, 
-            "date": "2010-10-20 10:38:58", 
-            "slug": "first-entry", 
-            "tags": [
-                1
-            ]
-        }
-    }, 
-    {
-        "pk": 1, 
-        "model": "penfield.blogview", 
-        "fields": {
-            "entry_archive_page": 5, 
-            "tag_page": 4, 
-            "feed_suffix": "feed", 
-            "entry_permalink_style": "D", 
-            "tag_permalink_base": "tags", 
-            "feeds_enabled": true, 
-            "entries_per_page": null, 
-            "tag_archive_page": 6, 
-            "blog": 1, 
-            "entry_permalink_base": "entries", 
-            "index_page": 2, 
-            "entry_page": 3
-        }
     }
 ]
index 9ba1ff6..b41a00e 100644 (file)
@@ -467,6 +467,9 @@ class TreeModel(MPTTModel):
                if root == self:
                        return ''
                
+               if root is None and self.is_root_node():
+                       return self.slug
+               
                if root is not None and not self.is_descendant_of(root):
                        raise AncestorDoesNotExist(root)
                
index a0e0184..5a9a5ba 100644 (file)
@@ -3,15 +3,14 @@ import traceback
 
 from django import template
 from django.conf import settings
-from django.db import connection
+from django.db import connection, models
 from django.template import loader
 from django.template.loaders import cached
 from django.test import TestCase
-from django.test.utils import setup_test_template_loader
+from django.test.utils import setup_test_template_loader, restore_template_loaders
 
-from philo.contrib.penfield.models import Blog, BlogView, BlogEntry
 from philo.exceptions import AncestorDoesNotExist
-from philo.models import Node, Page, Template
+from philo.models import Node, Page, Template, Tag
 
 
 class TemplateTestCase(TestCase):
@@ -56,7 +55,7 @@ class TemplateTestCase(TestCase):
                # Cleanup
                settings.TEMPLATE_DEBUG = old_td
                settings.TEMPLATE_STRING_IF_INVALID = old_invalid
-               loader.template_source_loaders = old_template_loaders
+               restore_template_loaders()
                
                self.assertEqual(failures, [], "Tests failed:\n%s\n%s" % ('-'*70, ("\n%s\n" % ('-'*70)).join(failures)))
        
@@ -64,43 +63,43 @@ class TemplateTestCase(TestCase):
        def get_template_tests(self):
                # SYNTAX --
                # 'template_name': ('template contents', 'context dict', 'expected string output' or Exception class)
-               blog = Blog.objects.all()[0]
+               embedded = Tag.objects.get(pk=1)
                return {
                        # EMBED INCLUSION HANDLING
                        
-                       'embed01': ('{{ embedded.title|safe }}', {'embedded': blog}, blog.title),
-                       'embed02': ('{{ embedded.title|safe }}{{ var1 }}{{ var2 }}', {'embedded': blog}, blog.title),
-                       'embed03': ('{{ embedded.title|safe }} is a lie!', {'embedded': blog}, '%s is a lie!' % blog.title),
+                       'embed01': ('{{ embedded.name|safe }}', {'embedded': embedded}, embedded.name),
+                       'embed02': ('{{ embedded.name|safe }}{{ var1 }}{{ var2 }}', {'embedded': embedded}, embedded.name),
+                       'embed03': ('{{ embedded.name|safe }} is a lie!', {'embedded': embedded}, '%s is a lie!' % embedded.name),
                        
                        # Simple template structure with embed
-                       'simple01': ('{% embed penfield.blog with "embed01" %}{% embed penfield.blog 1 %}Simple{% block one %}{% endblock %}', {'blog': blog}, '%sSimple' % blog.title),
-                       'simple02': ('{% extends "simple01" %}', {}, '%sSimple' % blog.title),
-                       'simple03': ('{% embed penfield.blog with "embed000" %}', {}, settings.TEMPLATE_STRING_IF_INVALID),
-                       'simple04': ('{% embed penfield.blog 1 %}', {}, settings.TEMPLATE_STRING_IF_INVALID),
-                       'simple05': ('{% embed penfield.blog with "embed01" %}{% embed blog %}', {'blog': blog}, blog.title),
+                       'simple01': ('{% embed philo.tag with "embed01" %}{% embed philo.tag 1 %}Simple{% block one %}{% endblock %}', {'embedded': embedded}, '%sSimple' % embedded.name),
+                       'simple02': ('{% extends "simple01" %}', {}, '%sSimple' % embedded.name),
+                       'simple03': ('{% embed philo.tag with "embed000" %}', {}, settings.TEMPLATE_STRING_IF_INVALID),
+                       'simple04': ('{% embed philo.tag 1 %}', {}, settings.TEMPLATE_STRING_IF_INVALID),
+                       'simple05': ('{% embed philo.tag with "embed01" %}{% embed embedded %}', {'embedded': embedded}, embedded.name),
                        
                        # Kwargs
-                       'kwargs01': ('{% embed penfield.blog with "embed02" %}{% embed penfield.blog 1 var1="hi" var2=lo %}', {'lo': 'lo'}, '%shilo' % blog.title),
+                       'kwargs01': ('{% embed philo.tag with "embed02" %}{% embed philo.tag 1 var1="hi" var2=lo %}', {'lo': 'lo'}, '%shilo' % embedded.name),
                        
                        # Filters/variables
-                       'filters01': ('{% embed penfield.blog with "embed02" %}{% embed penfield.blog 1 var1=hi|first var2=lo|slice:"3" %}', {'hi': ["These", "words"], 'lo': 'lower'}, '%sTheselow' % blog.title),
-                       'filters02': ('{% embed penfield.blog with "embed01" %}{% embed penfield.blog entry %}', {'entry': 1}, blog.title),
+                       'filters01': ('{% embed philo.tag with "embed02" %}{% embed philo.tag 1 var1=hi|first var2=lo|slice:"3" %}', {'hi': ["These", "words"], 'lo': 'lower'}, '%sTheselow' % embedded.name),
+                       'filters02': ('{% embed philo.tag with "embed01" %}{% embed philo.tag entry %}', {'entry': 1}, embedded.name),
                        
                        # Blocky structure
                        'block01': ('{% block one %}Hello{% endblock %}', {}, 'Hello'),
-                       'block02': ('{% extends "simple01" %}{% block one %}{% embed penfield.blog 1 %}{% endblock %}', {}, "%sSimple%s" % (blog.title, blog.title)),
-                       'block03': ('{% extends "simple01" %}{% embed penfield.blog with "embed03" %}{% block one %}{% embed penfield.blog 1 %}{% endblock %}', {}, "%sSimple%s is a lie!" % (blog.title, blog.title)),
+                       'block02': ('{% extends "simple01" %}{% block one %}{% embed philo.tag 1 %}{% endblock %}', {}, "%sSimple%s" % (embedded.name, embedded.name)),
+                       'block03': ('{% extends "simple01" %}{% embed philo.tag with "embed03" %}{% block one %}{% embed philo.tag 1 %}{% endblock %}', {}, "%sSimple%s is a lie!" % (embedded.name, embedded.name)),
                        
                        # Blocks and includes
-                       'block-include01': ('{% extends "simple01" %}{% embed penfield.blog with "embed03" %}{% block one %}{% include "simple01" %}{% embed penfield.blog 1 %}{% endblock %}', {}, "%sSimple%sSimple%s is a lie!" % (blog.title, blog.title, blog.title)),
-                       'block-include02': ('{% extends "simple01" %}{% block one %}{% include "simple04" %}{% embed penfield.blog with "embed03" %}{% include "simple04" %}{% embed penfield.blog 1 %}{% endblock %}', {}, "%sSimple%s%s is a lie!%s is a lie!" % (blog.title, blog.title, blog.title, blog.title)),
+                       'block-include01': ('{% extends "simple01" %}{% embed philo.tag with "embed03" %}{% block one %}{% include "simple01" %}{% embed philo.tag 1 %}{% endblock %}', {}, "%sSimple%sSimple%s is a lie!" % (embedded.name, embedded.name, embedded.name)),
+                       'block-include02': ('{% extends "simple01" %}{% block one %}{% include "simple04" %}{% embed philo.tag with "embed03" %}{% include "simple04" %}{% embed philo.tag 1 %}{% endblock %}', {}, "%sSimple%s%s is a lie!%s is a lie!" % (embedded.name, embedded.name, embedded.name, embedded.name)),
                        
                        # Tests for more complex situations...
                        'complex01': ('{% block one %}{% endblock %}complex{% block two %}{% endblock %}', {}, 'complex'),
                        'complex02': ('{% extends "complex01" %}', {}, 'complex'),
-                       'complex03': ('{% extends "complex02" %}{% embed penfield.blog with "embed01" %}', {}, 'complex'),
-                       'complex04': ('{% extends "complex03" %}{% block one %}{% embed penfield.blog 1 %}{% endblock %}', {}, '%scomplex' % blog.title),
-                       'complex05': ('{% extends "complex03" %}{% block one %}{% include "simple04" %}{% endblock %}', {}, '%scomplex' % blog.title),
+                       'complex03': ('{% extends "complex02" %}{% embed philo.tag with "embed01" %}', {}, 'complex'),
+                       'complex04': ('{% extends "complex03" %}{% block one %}{% embed philo.tag 1 %}{% endblock %}', {}, '%scomplex' % embedded.name),
+                       'complex05': ('{% extends "complex03" %}{% block one %}{% include "simple04" %}{% endblock %}', {}, '%scomplex' % embedded.name),
                }
 
 
@@ -110,35 +109,19 @@ class NodeURLTestCase(TestCase):
        fixtures = ['test_fixtures.json']
        
        def setUp(self):
-               if 'south' in settings.INSTALLED_APPS:
-                       from south.management.commands.migrate import Command
-                       command = Command()
-                       command.handle(all_apps=True)
-               
                self.templates = [
-                               ("{% node_url %}", "/root/second/"),
-                               ("{% node_url for node2 %}", "/root/second2/"),
-                               ("{% node_url as hello %}<p>{{ hello|slice:'1:' }}</p>", "<p>root/second/</p>"),
-                               ("{% node_url for nodes|first %}", "/root/"),
-                               ("{% node_url with entry %}", settings.TEMPLATE_STRING_IF_INVALID),
-                               ("{% node_url with entry for node2 %}", "/root/second2/2010/10/20/first-entry"),
-                               ("{% node_url with tag for node2 %}", "/root/second2/tags/test-tag/"),
-                               ("{% node_url with date for node2 %}", "/root/second2/2010/10/20"),
-                               ("{% node_url entries_by_day year=date|date:'Y' month=date|date:'m' day=date|date:'d' for node2 as goodbye %}<em>{{ goodbye|upper }}</em>", "<em>/ROOT/SECOND2/2010/10/20</em>"),
-                               ("{% node_url entries_by_month year=date|date:'Y' month=date|date:'m' for node2 %}", "/root/second2/2010/10"),
-                               ("{% node_url entries_by_year year=date|date:'Y' for node2 %}", "/root/second2/2010/"),
+                               ("{% node_url %}", "/root/second"),
+                               ("{% node_url for node2 %}", "/root/second2"),
+                               ("{% node_url as hello %}<p>{{ hello|slice:'1:' }}</p>", "<p>root/second</p>"),
+                               ("{% node_url for nodes|first %}", "/root"),
                ]
                
                nodes = Node.objects.all()
-               blog = Blog.objects.all()[0]
                
                self.context = template.Context({
                        'node': nodes.get(slug='second'),
                        'node2': nodes.get(slug='second2'),
                        'nodes': nodes,
-                       'entry': BlogEntry.objects.all()[0],
-                       'tag': blog.entry_tags.all()[0],
-                       'date': blog.entry_dates['day'][0]
                })
        
        def test_nodeurl(self):
@@ -149,12 +132,6 @@ class TreePathTestCase(TestCase):
        urls = 'philo.urls'
        fixtures = ['test_fixtures.json']
        
-       def setUp(self):
-               if 'south' in settings.INSTALLED_APPS:
-                       from south.management.commands.migrate import Command
-                       command = Command()
-                       command.handle(all_apps=True)
-       
        def assertQueryLimit(self, max, expected_result, *args, **kwargs):
                # As a rough measure of efficiency, limit the number of queries required for a given operation.
                settings.DEBUG = True
@@ -193,7 +170,7 @@ class TreePathTestCase(TestCase):
                
                # Non-absolute result (binary search)
                self.assertQueryLimit(2, (second2, 'sub/path/tail'), 'root/second2/sub/path/tail', absolute_result=False)
-               self.assertQueryLimit(3, (second2, 'sub/'), 'root/second2/sub/', absolute_result=False)
+               self.assertQueryLimit(3, (second2, 'sub'), 'root/second2/sub/', absolute_result=False)
                self.assertQueryLimit(2, e, 'invalid/path/1/2/3/4/5/6/7/8/9/1/2/3/4/5/6/7/8/9/0', absolute_result=False)
                self.assertQueryLimit(1, (root, None), 'root', absolute_result=False)
                self.assertQueryLimit(2, (second2, None), 'root/second2', absolute_result=False)
@@ -203,8 +180,8 @@ class TreePathTestCase(TestCase):
                self.assertQueryLimit(1, (second2, None), 'second2', root=root, absolute_result=False)
                self.assertQueryLimit(2, (third, None), 'second/third', root=root, absolute_result=False)
                
-               # Preserve trailing slash
-               self.assertQueryLimit(2, (second2, 'sub/path/tail/'), 'root/second2/sub/path/tail/', absolute_result=False)
+               # Eliminate trailing slash
+               self.assertQueryLimit(2, (second2, 'sub/path/tail'), 'root/second2/sub/path/tail/', absolute_result=False)
                
                # Speed increase for leaf nodes - should this be tested?
                self.assertQueryLimit(1, (fifth, 'sub/path/tail/len/five'), 'root/second/third/fourth/fifth/sub/path/tail/len/five', absolute_result=False)