Skip to content

Commit

Permalink
Merge pull request #47 from Alkalit/develop
Browse files Browse the repository at this point in the history
Refactoring of unit tests.
  • Loading branch information
klen committed Mar 25, 2015
2 parents 9050d2e + f6f0c66 commit ce495d9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 22 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ dist
docs/_*
sitegen.egg-info
todo.txt
_

.coverage
.tox/
django_markdown.egg-info/
91 changes: 70 additions & 21 deletions django_markdown/tests.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,90 @@
from django.test import TestCase
from django_markdown.utils import markdown as markdown_util

from django_markdown.templatetags.django_markdown import (
markdown as markdown_tag
)

class DjangoMarkdownTestCase(TestCase):
from django.contrib.auth import models

def test_base(self):
from django_markdown.utils import markdown
self.assertEqual(markdown('**test**'), '<p><strong>test</strong></p>')

def test_filters(self):
from django_markdown.templatetags.django_markdown import markdown
self.assertEqual(
markdown('| header |\n| ---- |\n| data |', 'tables'),
'<table>\n<thead>\n<tr>\n<th>header</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>data</td>\n</tr>\n</tbody>\n</table>')
class DjangoMarkdownTagsTest(TestCase):

def test_markdown_tag(self):
html = markdown_tag('| header |\n| ---- |\n| data |', 'tables')

expected = ('<table>\n<thead>\n<tr>\n<th>header</th>'
'\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>data'
'</td>\n</tr>\n</tbody>\n</table>')

self.assertEqual(html, expected)


class DjangoMarkdownUtilsTest(TestCase):

def test_markdown_util(self):
html = markdown_util('**test**')
expected = '<p><strong>test</strong></p>'

self.assertEqual(html, expected)


class DjangoMarkdownViewsTest(TestCase):

def setUp(self):

self.data = {'data': "# header \n *test*"}

def test_preview_get_empty_request(self):

def test_preview_view(self):
response = self.client.get('/markdown/preview/')

self.assertEqual(response.status_code, 200)
self.assertContains(response, 'No content posted')
self.assertContains(response, 'preview.css')

response = self.client.get('/markdown/preview/', data=dict(
data="# header \n *test*"))
def test_preview_get_markdown_request(self):

response = self.client.get('/markdown/preview/', data=self.data)

self.assertEqual(response.status_code, 200)
self.assertContains(response, '<h1>header</h1>')

response = self.client.post('/markdown/preview/', data=dict(
data="# header \n *test*"))
def test_preview_post_markdown_request(self):

data = {'data': "# header \n *test*"}

response = self.client.post('/markdown/preview/', data=self.data)

self.assertEqual(response.status_code, 200)
self.assertContains(response, '<h1>header</h1>')

def test_preview_MARKDOWN_PROTECT_PREVIEW(self):
# monkey patching
from . import settings
settings.MARKDOWN_PROTECT_PREVIEW = True
response = self.client.get('/markdown/preview/', data=dict(data="# header \n *test*"))

response = self.client.get('/markdown/preview/', data=self.data)

self.assertEqual(response.status_code, 302)

from django.contrib.auth import models
user = models.User.objects.create(username='test', is_staff=True)
user.set_password('test')
user.save()
self.client.login(username='test', password='test')
# for tests isolation reasons
settings.MARKDOWN_PROTECT_PREVIEW = False

def test_preview_get_markdown_for_admin_user_registered(self):

username = 'test'
password = 'test',

user = models.User.objects.create(
username=username,
password=password,
is_staff=True
)

self.client.login(username=username, password=password)

response = self.client.get('/markdown/preview/', data=self.data)

response = self.client.get('/markdown/preview/', data=dict(data="# header \n *test*"))
self.assertEqual(response.status_code, 200)
self.assertContains(response, '<h1>header</h1>')

0 comments on commit ce495d9

Please sign in to comment.