Commits

Josh VanderLinden committed 3de06fe

More test cases... 43% coverage...

Comments (0)

Files changed (4)

articles/fixtures/tags.json

         }
     }
 ]
-
-

articles/fixtures/users.json

 [
     {
-        "pk": 1, 
-        "model": "auth.user", 
+        "pk": 1,
+        "model": "auth.user",
         "fields": {
             "username": "superuser",
             "is_superuser": 1
         }
+    },
+    {
+        "pk": 2,
+        "model": "auth.user",
+        "fields": {
+            "username": "jim",
+            "password": "bob",
+            "first_name": "Jim",
+            "last_name": "Bob"
+        }
     }
 ]

articles/models.py

 
     class Meta:
         ordering = ('-publish_date', 'title')
+        get_latest_by = 'publish_date'
 
 class Attachment(models.Model):
     upload_to = lambda inst, fn: 'attach/%s/%s/%s' % (datetime.now().year, inst.article.slug, fn)

articles/tests.py

 # -*- coding: utf-8 -*-
 
+from datetime import datetime, timedelta
+
 from django.contrib.auth.models import User, Permission
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 from django.test.client import Client
 
-from forms import ArticleAdminForm
-from models import Article, ArticleStatus, Tag, MARKUP_HTML
+from models import Article, ArticleStatus, Tag, get_name, MARKUP_HTML, MARKUP_MARKDOWN, MARKUP_REST, MARKUP_TEXTILE
 
 class ArticleUtilMixin(object):
 
         response = self.client.get(t2.get_absolute_url())
         self.assertEqual(response.status_code, 200)
 
+    def test_tag_save(self):
+        """Makes sure the overridden save method works for Tags"""
+
+        t = Tag.objects.create(name='wasabi')
+        t.name = 'DERP'
+        t.save()
+
+        self.assertEqual(t.slug, 'derp')
+
+    def test_get_absolute_url(self):
+        name = 'Hi There'
+        t = Tag.objects.create(name=name)
+        self.assertEqual(t.get_absolute_url(), reverse('articles_display_tag', args=[Tag.clean_tag(name)]))
+
+class ArticleStatusTestCase(TestCase):
+
+    def setUp(self):
+        pass
+
+    def test_instantiation(self):
+        _as = ArticleStatus(name='Fake', ordering=5, is_live=True)
+        self.assertEqual(unicode(_as), u'Fake (live)')
+
+        _as.is_live = False
+        self.assertEqual(unicode(_as), u'Fake')
+
 class ArticleTestCase(TestCase, ArticleUtilMixin):
     fixtures = ['users']
 
         self.assertEquals(Article.objects.live().count(), 2)
         self.assertEquals(Article.objects.live(self.superuser).count(), 3)
 
-class ArticleAdminTest(TestCase, ArticleUtilMixin):
+    def test_auto_expire(self):
+        """
+        Makes sure that articles set to expire will actually be marked inactive
+        """
+
+        one_second_ago = datetime.now() - timedelta(seconds=1)
+        a = self.new_article('Expiring Article', 'I expired one second ago', is_active=True, expiration_date=one_second_ago)
+
+        self.assertTrue(a.is_active)
+
+        b = Article.objects.latest()
+        self.assertFalse(b.is_active)
+
+    def test_markup_markdown(self):
+        """Makes sure markdown works"""
+
+        a = self.new_article('Demo', '''A First Level Header
+====================
+
+A Second Level Header
+---------------------
+
+Now is the time for all good men to come to
+the aid of their country. This is just a
+regular paragraph.''', markup=MARKUP_MARKDOWN)
+        a.do_render_markup()
+
+        print a.rendered_content
+
+    def test_markup_rest(self):
+        """Makes sure reStructuredText works"""
+
+        a = self.new_article('Demo', '''A First Level Header
+====================
+
+A Second Level Header
+---------------------
+
+Now is the time for all good men to come to
+the aid of their country. This is just a
+regular paragraph.''', markup=MARKUP_REST)
+        a.do_render_markup()
+
+        print a.rendered_content
+
+    def test_markup_textile(self):
+        """Makes sure textile works"""
+
+        a = self.new_article('Demo', '''A First Level Header
+====================
+
+A Second Level Header
+---------------------
+
+Now is the time for all good men to come to
+the aid of their country. This is just a
+regular paragraph.''', markup=MARKUP_TEXTILE)
+        a.do_render_markup()
+
+        print a.rendered_content
+
+    def test_markup_html(self):
+        """Makes sure HTML works (derp)"""
+
+        html = '''<h1>A First Level Header</h1>
+<h2>A Second Level Header</h2>
+
+<p>Now is the time for all good men to come to
+the aid of their country. This is just a
+regular paragraph.</p>'''
+
+        a = self.new_article('Demo', html, markup=MARKUP_HTML)
+        a.do_render_markup()
+        self.assertEqual(html, a.rendered_content)
+
+class ArticleAdminTestCase(TestCase, ArticleUtilMixin):
     fixtures = ['users']
 
     def setUp(self):
         res = self.client.get(reverse('admin:articles_article_changelist'))
         self.assertEqual(res.content.count('_selected_action'), 10)
 
-class FeedTest(TestCase, ArticleUtilMixin):
+class FeedTestCase(TestCase, ArticleUtilMixin):
     fixtures = ['tags', 'users']
 
     def setUp(self):
         res = self.client.get(reverse('articles_feed_atom', args=['tags/demo/']))
         self.assertEqual(res.status_code, 404)
 
-class FormTest(TestCase, ArticleUtilMixin):
+class FormTestCase(TestCase, ArticleUtilMixin):
     fixtures = ['users',]
 
     def setUp(self):
         a = self.new_article('Sample', 'sample')
         res = self.client.get(reverse('admin:articles_article_change', args=[a.id]))
         self.assertEqual(res.status_code, 200)
+
+class ListenerTestCase(TestCase, ArticleUtilMixin):
+    fixtures = ['users', 'tags']
+
+    def test_apply_new_tag(self):
+        """Makes sure auto-tagging works"""
+
+        a = self.new_article('Yay', 'This is just a demonstration of how awesome Django and Python are.', auto_tag=True)
+        self.assertEqual(a.tags.count(), 0)
+
+        Tag.objects.create(name='awesome')
+        Tag.objects.create(name='Python')
+        t = Tag.objects.create(name='Django')
+
+        # make sure the tags were actually applied to our new article
+        self.assertEqual(a.tags.count(), 3)
+
+class MiscTestCase(TestCase):
+    fixtures = ['users',]
+
+    def test_get_name(self):
+        u1 = User.objects.get(pk=1)
+        u2 = User.objects.get(pk=2)
+
+        self.assertEqual(get_name(u1), 'superuser')
+        self.assertEqual(get_name(u2), 'Jim Bob')
+
+        self.assertEqual(u1.get_name(), 'superuser')
+        self.assertEqual(u2.get_name(), 'Jim Bob')
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.