Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #84

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[bumpversion]
commit = True
current_version = 0.8.4
current_version = 0.8.5
files = django_markdown/__init__.py
tag = True
tag_name = {new_version}
Expand Down
12 changes: 9 additions & 3 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[report]
source=django_markdown

[run]
branch=True
source=django_markdown

[report]
precision = 2
omit = *migrations*
ignore_errors = True

[html]
directory = coverage_html_report
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/
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ branches:
- master
- develop

install: pip install --quiet --use-mirrors tox
install: pip install --quiet tox

script: tox

after_script:
- if [ $TOXENV == "cov" ]; then
pip install --quiet --use-mirrors coveralls;
pip install --quiet coveralls;
coveralls;
fi
4 changes: 3 additions & 1 deletion CONTRIBUTORS
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Contributors:

* Kirill Klenov (https://github.com/klen)

* Alexey Kalinin (https://github.com/Alkalit)
* Alexey Sveshnikov (https://github.com/alexey-sveshnikov)
* Aliaksei Harabchuk (https://github.com/harabchuk)
* Andrew Grigorev (https://github.com/ei-grad)
Expand All @@ -13,5 +15,5 @@ Contributors:
* Rolf Håvard Blindheim (https://github.com/rhblind)
* Sergii Iavorskyi (https://github.com/yavorskiy)
* Tom O'onnor' (https://github.com/tomoconnor)
* dfeinzeig (https://github.com/dfeinzeig)
* Wellington Cordeiro (https://github.com/wldcordeiro)
* dfeinzeig (https://github.com/dfeinzeig)
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Django-Markdown v. 0.8.4
Django-Markdown v. 0.8.5
########################

.. _description:
Expand Down
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>')