diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 69b95ed..f21e805 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -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} diff --git a/.coveragerc b/.coveragerc index d80d81c..fad4a8e 100644 --- a/.coveragerc +++ b/.coveragerc @@ -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 diff --git a/.gitignore b/.gitignore index ed10919..b28c97e 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,7 @@ dist docs/_* sitegen.egg-info todo.txt -_ + +.coverage +.tox/ +django_markdown.egg-info/ diff --git a/.travis.yml b/.travis.yml index 53b1684..0b308a2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 84a8fb8..fc9bf12 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -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) @@ -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) diff --git a/README.rst b/README.rst index 396a151..b8ca28b 100644 --- a/README.rst +++ b/README.rst @@ -1,4 +1,4 @@ -Django-Markdown v. 0.8.4 +Django-Markdown v. 0.8.5 ######################## .. _description: diff --git a/django_markdown/tests.py b/django_markdown/tests.py index f1c6ca4..fc597f1 100644 --- a/django_markdown/tests.py +++ b/django_markdown/tests.py @@ -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**'), '

test

') - def test_filters(self): - from django_markdown.templatetags.django_markdown import markdown - self.assertEqual( - markdown('| header |\n| ---- |\n| data |', 'tables'), - '\n\n\n\n\n\n\n\n\n\n\n
header
data
') +class DjangoMarkdownTagsTest(TestCase): + + def test_markdown_tag(self): + html = markdown_tag('| header |\n| ---- |\n| data |', 'tables') + + expected = ('\n\n\n' + '\n\n\n\n\n\n\n\n
header
data' + '
') + + self.assertEqual(html, expected) + + +class DjangoMarkdownUtilsTest(TestCase): + + def test_markdown_util(self): + html = markdown_util('**test**') + expected = '

test

' + + 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, '

header

') - 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, '

header

') + 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, '

header

')