-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #47 from Alkalit/develop
Refactoring of unit tests.
- Loading branch information
Showing
2 changed files
with
74 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,7 @@ dist | |
docs/_* | ||
sitegen.egg-info | ||
todo.txt | ||
_ | ||
|
||
.coverage | ||
.tox/ | ||
django_markdown.egg-info/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>') |