Browse files

Merge branch 'master' of ssh://githany/projects/content/GIT/django-ma…

…rkup
  • Loading branch information...
2 parents 98ec7ce + 1479340 commit fce6e47e64212bcbe4af2bcc096fbd6b8ff3f82d @alaif alaif committed Jun 24, 2009
View
6 djangomarkup/urls.py
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import patterns, url
+
+urlpatterns = patterns('djangomarkup.views',
+ url(r'^transform/(?P<syntax_processor_name>[a-z\-]+)?/$', 'transform', name="markup-transform"),
+)
+
View
12 djangomarkup/views.py
@@ -2,18 +2,21 @@
from django import template
from django.conf import settings
-from django.http import HttpResponse
+from django.http import HttpResponse, HttpResponseNotAllowed
from django.utils.translation import ugettext
from djangomarkup.models import TextProcessor
log = logging.getLogger('djangomarkup')
-def preview(request, var_name="text", syntax_processor_name=None):
+def transform(request, syntax_processor_name=None, var_name="text"):
"""
Returns rendered HTML for source text
"""
- source = request.REQUEST.get(var_name)
+ if request.method != 'POST':
+ return HttpResponseNotAllowed("Only POST allowed")
+
+ source = request.POST.get(var_name)
if not source:
return HttpResponse('')
@@ -28,3 +31,6 @@ def preview(request, var_name="text", syntax_processor_name=None):
output = '<h3 style="color:red">%s</h3><p>%s</p>' % (ugettext('You have an errors in source text!'), e)
return HttpResponse(output)
+
+# backward compatibility
+preview = transform
View
26 tests/unit_project/test_preview.py
@@ -0,0 +1,26 @@
+# -*- coding: utf-8 -*-
+from djangosanetesting import DatabaseTestCase
+from django.core.urlresolvers import reverse
+
+class TestPreview(DatabaseTestCase):
+ def setUp(self):
+ super(TestPreview, self).setUp()
+ self.processor_name = "markdown"
+ self.mock_text = u"beer - 啤酒"
+ self.czechtile_text = u"= Text =\n češťoučký texďýčšek"
+ self.czechtile_text_transformed = u"<h1>Text</h1><p>češťoučký texďýčšek</p>"
+
+ def test_success_default_markdown(self):
+ self.assert_equals(u"<p>%s</p>" % self.mock_text, self.client.post(reverse("markup-transform"), {'text' : self.mock_text}).content.strip().decode('utf-8'))
+
+ def test_get_returns_bad_method(self):
+ self.assert_equals(405, self.client.get(reverse("markup-transform")).status_code)
+
+ def test_empty_(self):
+ self.assert_equals(u"<p>%s</p>" % self.mock_text, self.client.post(reverse("markup-transform"), {'text' : self.mock_text}).content.strip().decode('utf-8'))
+
+ def test_success_czechtile(self):
+ self.assert_equals(self.czechtile_text_transformed,
+ self.client.post(reverse("markup-transform", kwargs={'syntax_processor_name' : "czechtile"}),
+ {'text' : self.czechtile_text}).content.decode('utf-8')
+ )
View
1 tests/unit_project/test_processing.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
from djangosanetesting.cases import UnitTestCase
from djangomarkup.models import TextProcessor
from djangomarkup.processors import ProcessorConfigurationError, ProcessorError
View
6 tests/unit_project/urls.py
@@ -0,0 +1,6 @@
+from django.conf.urls.defaults import patterns, url, include
+
+urlpatterns = patterns('',
+ url(r'^', include('djangomarkup.urls')),
+)
+

0 comments on commit fce6e47

Please sign in to comment.