Commits

magik_cypress  committed 12d62c6 Draft

add test and fix

  • Participants
  • Parent commits 4bf1bbc

Comments (0)

Files changed (20)

File README.markdown

     $ python manage.py syncdb
     $ python manage.py runserver
 
+## UnitTest
+    # dump data
+    $ python manage.py dumpdata --natural > fixtures/initial_data.json
+    # load fixtures
+    $ python manage.py loaddata fixtures/initial_data.json
+    # Test with coverage
+    $ coverage report -m
+    $ coverage html -d coverage_html
+    # https://github.com/jbalogh/django-nose/issues/2
+    $ python manage.py test --with-coverage --cover-package=rubriques.models --verbosity 2
+
 ## Production: (pythonanywhere.com)
 
     $ export WORKON_HOME=~/minicms
 
     pep8
         https://github.com/jcrocholl/pep8/
+    coverage
+        http://pypi.python.org/pypi/coverage/3.5.2
+    django-nose
+        https://github.com/jbalogh/django-nose
 
 
 ## ChangeLog:

File articles/models.py

         ('month', _('1 Month')),
         ('half_year', _('6 Monthes')))
     comments_expiry = models.CharField(choices=choices, max_length=9)
-    comments_expiry_date = models.DateTimeField('Comment expiry data')
+    comments_expiry_date = models.DateTimeField('Comment expiry data', default=datetime.now)
 
     # custom label templates
     required_css_class = 'required'

File articles/tests.py

-
-
-# -*- coding: utf-8 -*-
-
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase, Client

File articles/tests/__init__.py

+from articles.tests.models import *
+from articles.tests.views import *

File articles/tests/models.py

+
+
+# -*- coding: utf-8 -*-
+
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django_nose.testcases import FastFixtureTestCase
+from datetime import datetime
+from django.utils.timezone import utc
+from django.contrib.auth.models import User
+from django.conf import settings
+from rubriques.models import Rubrique
+from articles.models import Article
+from comments.models import Comment
+
+urls = 'minicms.urls'
+
+
+class ModelsTest(FastFixtureTestCase):
+    """ All test
+    """
+    def setUp(self):
+        self.user = User.objects.create_user(
+            'test1',
+            'test@example.com',
+            'test')
+        self.user.is_active = True
+        self.user.save()
+
+        # Create rubrique
+        self.rubrique = Rubrique(
+            title='premiere rubrique',
+            slug='premiere-rubrique')
+        self.rubrique.content = 'Content lipsum hein!'
+        self.rubrique.published = True
+        self.rubrique.author = self.user
+
+        self.rubrique.save()
+
+        # Create article
+        self.article = Article(title='Premier Article')
+        self.article.rubrique = self.rubrique
+        self.article.tags = 'tests'
+        self.article.author = self.user
+        self.article.content = 'some-test-content'
+        self.article.published = True
+        self.article.publish_date = datetime.now()
+        self.article.expired_date = datetime.now()
+        self.article.comments_enabled = True
+        self.article.comments_expiry = 'week'
+        self.article.comment_expiry_date = datetime.now()
+
+        # Create test comment
+        self.comment = Comment(
+            article_id=self.article.id,
+            author='Mr Test',
+            author_ip='127.0.0.2',
+            email='admin@admin.com',
+            content='test comment',
+            rendered_content='<p>test comment</p>',
+            published=True,
+            publish_date=datetime.now()
+        )
+        self.article.comments = [self.comment]
+
+        self.article.save()

File articles/tests/views.py

+
+
+# -*- coding: utf-8 -*-
+
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django_nose.testcases import FastFixtureTestCase
+from datetime import datetime
+from django.utils.timezone import utc
+from django.contrib.auth.models import User
+from django.conf import settings
+from rubriques.models import Rubrique
+from articles.models import Article
+from comments.models import Comment
+import re
+
+urls = 'minicms.urls'
+
+
+class ViewsTest(FastFixtureTestCase):
+    """ Views test
+    """
+    def setUp(self):
+        self.user = User.objects.create_user(
+            'test1',
+            'test@example.com',
+            'test')
+        self.user.is_active = True
+        self.user.save()
+        response = self.client.post('/admin/', {
+            'username': 'test2',
+            'password': 'test',
+        })
+        self.assertEqual(response.status_code, 200)
+        self.client.login(username='test_other', password='test')
+
+        # Create rubrique
+        self.rubrique = Rubrique(
+            title='premiere rubrique',
+            slug='premiere-rubrique')
+        self.rubrique.content = 'Content lipsum hein!'
+        self.rubrique.published = True
+        self.rubrique.author = self.user
+
+        self.rubrique.save()
+
+        # Create article
+        self.article = Article(title='Premier Article')
+        self.article.rubrique = self.rubrique
+        self.article.tags = 'tests'
+        self.article.author = self.user
+        self.article.content = 'some-test-content'
+        self.article.published = True
+        self.article.publish_date = datetime.now()
+        self.article.expired_date = datetime.now()
+        self.article.comments_enabled = True
+        self.article.comments_expiry = 'week'
+        self.article.comment_expiry_date = datetime.now()
+
+        self.article.save()
+
+    def get_csrf_token(self):
+        # Scrap CSRF token
+        response = self.client.get('/admin/login/')
+        csrf_regex = r'csrfmiddlewaretoken\'\s+value=\'(\w+)\''
+        csrf_regex = r'value=\'(\w+)\''
+        return re.search(csrf_regex, response.content).groups()[0]
+
+    """
+    def test_tags_article(self):
+        response = self.client.get('/tags/test/')
+        self.assertContains(response, self.article.content,
+            status_code=200)
+
+        response = self.client.get('/tags/doublerainbos/')
+        self.assertContains(response, self.article.content,
+            status_code=200)
+
+    def test_tags(self):
+        response = self.client('/tags/')
+        self.assetContains(response, 'test', status_code=200)
+    """
+
+    def test_add_comment(self):
+        # Test add comment
+        add_url = self.article.get_absolute_url() + '#comments'
+
+        comment_data = {
+            'article': self.article,
+            'author': self.user,
+            'author_ip': '127.0.0.1',
+            'email': 'admin@admin.com',
+            'content': 'text of content',
+            'rendered_content': '<p>text of content</p>',
+            'published': True,
+            'publish_date': datetime.now(),
+            'csrfmiddlewaretoken': self.get_csrf_token(),
+        }
+
+        # Check invalid form fails
+        response = self.client.post(add_url, {
+            'content': 'test',
+            'csrfmiddlewaretoken': self.get_csrf_token(),
+        })
+        response = self.client.post(add_url, comment_data)
+        self.assertRedirects(response, add_url, target_status_code=200)
+
+        response = self.client.get(add_url)
+        self.assertContains(response, comment_data['rendered_content'])

File articles/views.py

     # Check for comment expiry
     published = False
     if entry.published and entry.expiry_date:
-        expiry_date = entry.expiry_date.replace(microsecond=0)
+        expiry_date = entry.expiry_date.replace(
+            microsecond=0).replace(tzinfo=utc)
         datetime_now = datetime.utcnow().replace(
             microsecond=0).replace(tzinfo=utc)
         if expiry_date > datetime_now:
     comments_enabled = False
     if entry.comments_enabled and entry.comments_expiry_date:
         comments_expiry_date = entry.comments_expiry_date.replace(
-            microsecond=0)
+            microsecond=0).replace(tzinfo=utc)
         datetime_now = datetime.utcnow().replace(
             microsecond=0).replace(tzinfo=utc)
         if comments_expiry_date > datetime_now:

File minicms/fixtures/initial_data.json

+[{"pk": 9, "model": "contenttypes.contenttype", "fields": {"model": "article", "name": "article", "app_label": "articles"}}, {"pk": 10, "model": "contenttypes.contenttype", "fields": {"model": "comment", "name": "comment", "app_label": "comments"}}, {"pk": 4, "model": "contenttypes.contenttype", "fields": {"model": "contenttype", "name": "content type", "app_label": "contenttypes"}}, {"pk": 2, "model": "contenttypes.contenttype", "fields": {"model": "group", "name": "group", "app_label": "auth"}}, {"pk": 7, "model": "contenttypes.contenttype", "fields": {"model": "logentry", "name": "log entry", "app_label": "admin"}}, {"pk": 1, "model": "contenttypes.contenttype", "fields": {"model": "permission", "name": "permission", "app_label": "auth"}}, {"pk": 8, "model": "contenttypes.contenttype", "fields": {"model": "rubrique", "name": "rubrique", "app_label": "rubriques"}}, {"pk": 5, "model": "contenttypes.contenttype", "fields": {"model": "session", "name": "session", "app_label": "sessions"}}, {"pk": 6, "model": "contenttypes.contenttype", "fields": {"model": "site", "name": "site", "app_label": "sites"}}, {"pk": 3, "model": "contenttypes.contenttype", "fields": {"model": "user", "name": "user", "app_label": "auth"}}, {"pk": 1, "model": "sites.site", "fields": {"domain": "example.com", "name": "example.com"}}, {"pk": 19, "model": "auth.permission", "fields": {"codename": "add_logentry", "name": "Can add log entry", "content_type": 7}}, {"pk": 20, "model": "auth.permission", "fields": {"codename": "change_logentry", "name": "Can change log entry", "content_type": 7}}, {"pk": 21, "model": "auth.permission", "fields": {"codename": "delete_logentry", "name": "Can delete log entry", "content_type": 7}}, {"pk": 25, "model": "auth.permission", "fields": {"codename": "add_article", "name": "Can add article", "content_type": 9}}, {"pk": 26, "model": "auth.permission", "fields": {"codename": "change_article", "name": "Can change article", "content_type": 9}}, {"pk": 27, "model": "auth.permission", "fields": {"codename": "delete_article", "name": "Can delete article", "content_type": 9}}, {"pk": 1, "model": "auth.permission", "fields": {"codename": "add_group", "name": "Can add group", "content_type": 2}}, {"pk": 4, "model": "auth.permission", "fields": {"codename": "change_group", "name": "Can change group", "content_type": 2}}, {"pk": 7, "model": "auth.permission", "fields": {"codename": "delete_group", "name": "Can delete group", "content_type": 2}}, {"pk": 2, "model": "auth.permission", "fields": {"codename": "add_permission", "name": "Can add permission", "content_type": 1}}, {"pk": 5, "model": "auth.permission", "fields": {"codename": "change_permission", "name": "Can change permission", "content_type": 1}}, {"pk": 8, "model": "auth.permission", "fields": {"codename": "delete_permission", "name": "Can delete permission", "content_type": 1}}, {"pk": 3, "model": "auth.permission", "fields": {"codename": "add_user", "name": "Can add user", "content_type": 3}}, {"pk": 6, "model": "auth.permission", "fields": {"codename": "change_user", "name": "Can change user", "content_type": 3}}, {"pk": 9, "model": "auth.permission", "fields": {"codename": "delete_user", "name": "Can delete user", "content_type": 3}}, {"pk": 28, "model": "auth.permission", "fields": {"codename": "add_comment", "name": "Can add comment", "content_type": 10}}, {"pk": 29, "model": "auth.permission", "fields": {"codename": "change_comment", "name": "Can change comment", "content_type": 10}}, {"pk": 30, "model": "auth.permission", "fields": {"codename": "delete_comment", "name": "Can delete comment", "content_type": 10}}, {"pk": 10, "model": "auth.permission", "fields": {"codename": "add_contenttype", "name": "Can add content type", "content_type": 4}}, {"pk": 11, "model": "auth.permission", "fields": {"codename": "change_contenttype", "name": "Can change content type", "content_type": 4}}, {"pk": 12, "model": "auth.permission", "fields": {"codename": "delete_contenttype", "name": "Can delete content type", "content_type": 4}}, {"pk": 22, "model": "auth.permission", "fields": {"codename": "add_rubrique", "name": "Can add rubrique", "content_type": 8}}, {"pk": 23, "model": "auth.permission", "fields": {"codename": "change_rubrique", "name": "Can change rubrique", "content_type": 8}}, {"pk": 24, "model": "auth.permission", "fields": {"codename": "delete_rubrique", "name": "Can delete rubrique", "content_type": 8}}, {"pk": 13, "model": "auth.permission", "fields": {"codename": "add_session", "name": "Can add session", "content_type": 5}}, {"pk": 14, "model": "auth.permission", "fields": {"codename": "change_session", "name": "Can change session", "content_type": 5}}, {"pk": 15, "model": "auth.permission", "fields": {"codename": "delete_session", "name": "Can delete session", "content_type": 5}}, {"pk": 16, "model": "auth.permission", "fields": {"codename": "add_site", "name": "Can add site", "content_type": 6}}, {"pk": 17, "model": "auth.permission", "fields": {"codename": "change_site", "name": "Can change site", "content_type": 6}}, {"pk": 18, "model": "auth.permission", "fields": {"codename": "delete_site", "name": "Can delete site", "content_type": 6}}, {"pk": 1, "model": "auth.user", "fields": {"username": "test", "first_name": "", "last_name": "", "is_active": true, "is_superuser": true, "is_staff": true, "last_login": "2012-07-20T13:55:47.796", "groups": [], "user_permissions": [], "password": "pbkdf2_sha256$10000$bHVUosEZ7gbb$17W+aeE7wdZxyH2tYjreXLEBhW76fGJHP0Q+5XN4nNc=", "email": "test@test.com", "date_joined": "2012-07-20T13:55:47.796"}}]

File minicms/settings.py

 
 # Django settings for minicms project.
 from .version import __version__
-import os.path, sys
+import os.path
+import sys
 
 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
     DATABASES = {
         'default': {
             'ENGINE': 'django.db.backends.sqlite3',
-            'NAME':'/tmp/minicms.db',
-            'USER'       : '',
-            'PASSWORD' : '',
-            'HOST'     : '',
+            'NAME': '/tmp/minicms.db',
+            'USER': '',
+            'PASSWORD': '',
+            'HOST': '',
         }
     }
 
 PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
 PROJECT_NAME = os.path.basename(PROJECT_ROOT)
 STATIC_ABSPATH = os.path.abspath('static')
+FIXTURE_DIRS = (os.path.join(PROJECT_ROOT, 'fixtures'),)
 
 # Absolute filesystem path to the directory that will hold user-uploaded files.
 # Example: "/home/media/media.lawrence.com/media/"
     'django.contrib.admin',
     'rubriques',
     'articles',
-    'comments'
+    'comments',
+    'django_nose',
+    # 'tests'
 )
 
 MARKUP_LANGUAGE = 'markdown'
 
+TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'
+
 # A sample logging configuration. The only tangible logging
 # performed by this configuration is to send an email to
 # the site admins on every HTTP 500 error when DEBUG=False.

File minicms/templates/base.html

             <ul>
                 <li><a href="https://bitbucket.org/magik_cypress/django-minicms">Fork me</a> &times;</li>
                 <li><a href="/privacy/">{% trans "Privacy Policy" %}</a></li>
+            </ul>
+        </div>
         </div>
     </footer>
 

File minicms/tests.py

-
-
-# -*- coding: utf-8 -*-
-
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase, Client
-from django.utils import unittest
-from datetime import datetime, timedelta
-from django.contrib.auth.models import User
-from rubriques.models import Rubrique
-from articles.models import Article
-
-
-class BasicTest(unittest.TestCase):
-    def setUp(self):
-        self.client = Client()
-
-    def test_home(self):
-        response = self.client.get('/')
-        self.assertEqual(response.status_code, 200)
-
-    def test_privacy(self):
-        response = self.client.get('/privacy/')
-        self.assertEqual(response.status_code, 200)
-
-
-class AllTestCase(TestCase):
-    def setUp(self):
-        # import pytz
-        # paris = datetime.now()
-        # paris_tz = pytz.timezone("Europe/Paris")
-        # paris_date = paris_tz.localize(paris)
-        self.user = User.objects.create_user(
-            username=u'admin',
-            email=u'admin@admin.com',
-            password=u'1234567890')
-        self.rubrique = Rubrique.objects.create(
-            title=u'Rubrique première',
-            content=u'Content lipsum hein!',
-            author=self.user,
-            published=True)
-        self.article = Article.objects.create(
-            title=u'Article premier',
-            rubrique=self.rubrique,
-            author=self.user,
-            content=u'Content lipsum hein!',
-            image=self.client.post('/', {'name': 'test', 'attachment': f}),
-            published=True,
-            expiry_date=timestamp + timedelta(7),
-            comments_enabled=True,
-            comments_expiry='week',
-            comments_expiry_date=timestamp + timedelta(7))
-        f.close()
-
-        self.c = Client()
-
-    def test_rubrique_create(self):
-        """ Rubrique create! You sure? 
-        """
-        self.assertEquals(self.rubrique.title, u'Rubrique première')
-        self.assertEquals(self.rubrique.content, u'Content lipsum hein!')
-        self.assertEquals(self.rubrique.author, self.user)
-
-    def test_rubrique_details(self):
-        self.c.login(username='admin', password='1234567890')
-        response = self.client.get('/rubriques/%s/' % self.rubrique)
-        self.assertEqual(response.status_code, 200)
-        self.assertNotEqual(response.content, '{}')
-        self.assertEqual(len(response.context['title']), 5)
-        self.assertEqual(len(response.context['publish_date']), 5)
-
-    def test_article_create(self):
-        """ Article created! You sure?
-        """
-        self.assertEquals(self.article.title, u'')
-        self.assertEquals(self.article.content, u'Content lipsum hein!')
-        self.assertEquals(self.article.author, self.user)
-
-    def test_article_details(self):
-        response = self.client.get('/articles/%s/' % self.article)
-        self.assertEqual(response.status_code, 200)
-        self.assertNotEqual(response.content, '{}')
-        self.assertEqual(len(response.context['title']), 5)
-        self.assertEqual(len(response.context['publish_date']), 5)

File minicms/tests/__init__.py

+from minicms.tests.tests import *

File minicms/tests/tests.py

+
+
+# -*- coding: utf-8 -*-
+
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django_nose.testcases import FastFixtureTestCase
+from datetime import datetime
+from django.utils.timezone import utc
+from django.contrib.auth.models import User
+from django.conf import settings
+from rubriques.models import Rubrique
+from articles.models import Article
+from comments.models import Comment
+import re
+
+urls = 'urls'
+
+
+class BaseTest(FastFixtureTestCase):
+
+    def test_basic_test_for_learn(self):
+        # these assertions have been in python for a while
+        self.assertTrue(1) # evaluates truthy-ness
+        self.assertFalse(0) # evaluates falsy-ness
+        self.assertEquals(1, 1) # evaluates second (dynamic) value equals the first (known) value;
+        self.assertNotEquals(1, 2)
+
+        # some of the new assertions added in python 2.7
+        o = 1
+        self.assertIs(o, o) # assert evaluate to the same object
+        self.assertIn(1, [1, 2, 3]) # assert first value in second
+        self.assertIsInstance(self, FastFixtureTestCase) # first value is instance of second
+
+
+class ModelsTest(FastFixtureTestCase):
+    """ Authentification tests
+    """
+    backend = 'django.contrib.auth.tests.auth_backends'
+
+    def setUp(self):
+        self.curr_auth = settings.AUTHENTICATION_BACKENDS
+        settings.AUTHENTICATION_BACKENDS = (self.backend,)
+        self.user1 = User.objects.create_user(
+            'test',
+            'test@example.com',
+            'test')
+        self.user1.is_active = True
+        self.user1.save()
+
+    def tearDown(self):
+        settings.AUTHENTICATION_BACKENDS = self.curr_auth
+
+    def true_user(self):
+        login = self.client.login(username='test', password='test')
+        self.failUnlessEqual(login, True)
+        self.assertTrue(login)
+        self.client.logout()
+
+    def false_user(self):
+        login = self.client.login(username='tes', password='test')
+        self.failUnlessEqual(login, False)
+        self.assertFalse(login)
+        self.client.logout()
+
+    def login(self, password='test'):
+        response = self.client.post('/admin/', {
+            'username': 'test',
+            'password': password,
+        })
+        self.assertEqual(response.status_code, 302)
+        self.assertTrue(response['Location'].endswith(
+            settings.LOGIN_REDIRECT_URL))
+        self.assertTrue(SESSION_KEY in self.client.session)
+
+    def assertContainsEscaped(self, response, text, **kwargs):
+        return self.assertContains(
+            response, escape(force_unicode(text)), **kwargs)
+
+
+class ViewsTest(FastFixtureTestCase):
+    """ Views test
+    """
+    def test_home(self):
+        # Simple test home page
+        response = self.client.get('/')
+        self.assertEqual(response.status_code, 200)
+
+    def test_privacy(self):
+        # Simple test privacy page
+        response = self.client.get('/privacy/')
+        self.assertEqual(response.status_code, 200)

File minicms/urls.py

 from django.conf.urls.static import static
 from django.conf import settings
 from django.views.generic.simple import direct_to_template
-from django.views.generic import ListView
-from minicms.utils import queryset_iterator
 from rubriques.models import Rubrique
 
 from django.contrib import admin

File requirement.txt

 #-e git+https://github.com/django/django.git#egg=django
 django
 pep8
+coverage
+django-nose
+# mock
 
 # various packages that may be usefull
 #gunicorn

File rubriques/admin.py

 
 from .models import Rubrique
 from django.contrib import admin
-from rubriques.models import Rubrique
 
 
 class RubriqueAdmin(admin.ModelAdmin):

File rubriques/tests.py

-
-
-# -*- coding: utf-8 -*-
-
-"""
-This file demonstrates writing tests using the unittest module. These will pass
-when you run "manage.py test".
-
-Replace this with more appropriate tests for your application.
-"""
-
-from django.test import TestCase, Client

File rubriques/tests/__init__.py

+from rubriques.tests.models import *
+from rubriques.tests.views import *

File rubriques/tests/models.py

+
+
+# -*- coding: utf-8 -*-
+
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django_nose.testcases import FastFixtureTestCase
+from django.utils import timezone
+from django.utils.timezone import utc
+from django.contrib.auth.models import User
+from django.conf import settings
+from rubriques.models import Rubrique
+import re
+
+urls = 'minicms.urls'
+
+
+class ModelsTest(FastFixtureTestCase):
+    """ All test
+    """
+    def setUp(self):
+        self.user = User.objects.create_user(
+            'test1',
+            'test@example.com',
+            'test')
+        self.user.is_active = True
+        self.user.save()
+
+        # Create rubrique
+        self.rubrique = Rubrique(
+            title='premiere rubrique',
+            slug='premiere-rubrique')
+        self.rubrique.content = 'Content lipsum hein!'
+        self.rubrique.published = True
+        self.rubrique.author = self.user
+
+        self.rubrique.save()

File rubriques/tests/views.py

+
+
+# -*- coding: utf-8 -*-
+
+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django_nose.testcases import FastFixtureTestCase
+from django.utils import timezone
+from django.utils.timezone import utc
+from django.contrib.auth.models import User
+from django.conf import settings
+from rubriques.models import Rubrique
+import re
+
+urls = 'minicms.urls'
+
+
+class ViewsTest(FastFixtureTestCase):
+    """ Views test
+    """
+    def setUp(self):
+        self.user = User.objects.create_user(
+            'test1',
+            'test@example.com',
+            'test')
+        self.user.is_active = True
+        self.user.save()
+        response = self.client.post('/admin/', {
+            'username': 'test1',
+            'password': 'test',
+        })
+        self.assertEqual(response.status_code, 200)
+        self.client.login(username='test_other', password='test')
+
+        # Create rubrique
+        self.rubrique = Rubrique(
+            title='deuxieme rubrique',
+            slug='deuxieme-rubrique')
+        self.rubrique.content = 'Content lipsum hein!'
+        self.rubrique.published = True
+        self.rubrique.author = self.user
+
+        self.rubrique.save()
+
+    def get_csrf_token(self):
+        # Scrap CSRF token
+        response = self.client.get('/admin/login/')
+        csrf_regex = r'csrfmiddlewaretoken\'\s+value=\'(\w+)\''
+        csrf_regex = r'value=\'(\w+)\''
+        return re.search(csrf_regex, response.content).groups()[0]
+
+    def test_views_recent_rubrique(self):
+        # Get rubrique for home page
+        response = self.client.get('/')
+        self.assertContains(
+            response,
+            self.rubrique.content,
+            status_code=200)
+
+    def test_views_detail_rubrique(self):
+        # Get rubrique for detail
+        response = self.client.get(self.rubrique.get_absolute_url())
+        self.assertContains(
+            response,
+            self.rubrique.content,
+            status_code=200)