Commits

Anonymous committed f7e57d2

Fixed tests for r9e9afbc54dbb.

Comments (0)

Files changed (6)

markupmirror/fields.py

                 'mode': markup_pool[self.default_markup_type].codemirror_mode,
                 'markup_type': self.default_markup_type,
             }
-            widget_attrs['data-mm-settings'] = json.dumps(mm_settings)
+            widget_attrs['data-mm-settings'] = json.dumps(mm_settings,
+                                                          sort_keys=True)
 
         defaults = {
             'widget': widgets.MarkupMirrorTextarea(attrs=widget_attrs),

markupmirror/widgets.py

 
         # provide mm_settings as data attribute in widget
         default_attrs = {
-            'data-mm-settings': json.dumps(mm_settings),
+            'data-mm-settings': json.dumps(mm_settings, sort_keys=True),
         }
         if attrs:
             default_attrs.update(attrs)

tests/settings.py

 
 NOSE_ARGS = [
     '--detailed-errors',
-    '--verbose',
+    # '--verbose',
     '--with-coverage',
     '--cover-html',
     '--cover-html-dir=' + tests_path_to(os.path.pardir, 'docs', '_coverage'),

tests/tests/fields.py

 import textwrap
 
-from django import forms
 from django.core import serializers
 from django.core.exceptions import ImproperlyConfigured
 from django.test import TestCase
             self.assertTrue(hasattr(rendered, '__str__'))
 
     def test_formfield(self):
-        """Form fields for ``MarkupMirrorFields`` always have three additional
+        """Form fields for ``MarkupMirrorFields`` always have two additional
         attributes:
 
         * ``class=item-markupmirror``.
-        * ``data-mode``: ``codemirror_mode`` of the assigned markup converter.
-        * ``data-markuptype``: the field's ``default_markup_type`` or the
-          assigned value's ``Markup.markup_type``.
+        * ``data-mm-settings``: a JSON dictionary containing the init settings
+          for CodeMirror and the URLs and parameters required for the preview
+          view.
 
         """
         form = PostForm()
         comment = form.fields['comment']
         self.assertEqual(
             sorted(comment.widget.attrs.keys()),
-            ['class', 'cols', 'data-markuptype', 'data-mode', 'rows'])
+            ['class', 'cols', 'data-mm-settings', 'rows'])
         self.assertTrue('item-markupmirror' in comment.widget.attrs['class'])
         self.assertEqual(
-            comment.widget.attrs['data-markuptype'],
-            self.mp.comment.markup_type)
-        self.assertEqual(
-            comment.widget.attrs['data-mode'],
-            markup_pool[self.mp.comment.markup_type].codemirror_mode)
+            comment.widget.attrs['data-mm-settings'],
+            '{{"markup_type": "{0}", "mode": "{1}"}}'.format(
+                self.mp.comment.markup_type,
+                markup_pool[self.mp.comment.markup_type].codemirror_mode)
+            )
 
 
 __all__ = ('MarkupMirrorFieldTests',)

tests/tests/views.py

         the preview URL can be resolved correctly.
 
         """
-        self.assertEqual(
-            reverse('markupmirror:preview',
-                    kwargs={'markup_type': 'plaintext'}),
-            '/markupmirror/preview/plaintext/')
+        self.assertEqual(reverse('markupmirror:preview'),
+                         '/markupmirror/preview/')
 
     def test_post_only(self):
         """The preview view may only be used via POST to make sure text won't
         be truncated or the like.
 
         """
-        url = reverse('markupmirror:preview',
-                      kwargs={'markup_type': 'plaintext'})
+        url = reverse('markupmirror:preview')
         self.assertIsInstance(self.client.get(url), HttpResponseNotAllowed)
-        self.assertIsInstance(self.client.post(url, {'text': "**markup**"}),
-                              HttpResponse)
+        self.assertIsInstance(self.client.post(url, {
+                'text': "**markup**",
+                'markup_type': 'plaintext'
+            }), HttpResponse)
 
 
 __all__ = ('MarkupPreviewViewTests',)

tests/tests/widgets.py

 import textwrap
 
+from django.core.urlresolvers import reverse
 from django.test import TestCase
+from django.utils import simplejson as json
 
+from markupmirror import settings as mm_settings
 from markupmirror.markup.base import markup_pool
 from markupmirror.widgets import AdminMarkupMirrorTextareaWidget
 
     ``..AdminMarkupMirrorTextareaWidget`` implementations.
 
     """
+
+    maxDiff = None
+
     def setUp(self):
         """Creates three ``Post`` objects with different field settings."""
 
                        body="**markdown**", body_markup_type='markdown')
         self.mp.save()
 
+        # default data attribute values for textareas:
+        self.mm_settings = mm_settings.MARKUPMIRROR_CODEMIRROR_SETTINGS.copy()
+        self.mm_settings.update({
+            'preview_url': reverse('markupmirror:preview'),
+            'base_url': reverse('markupmirror:base'),
+        })
+
     def test_widget_media(self):
         """Tests that the CSS and JS files required by the
         ``MarkupMirrorTextarea`` and the corresponding admin widget are used
         """
         form = PostForm(instance=self.mp)
         comment = form.fields['comment']
+
+        attrs = self.mm_settings.copy()
+        attrs.update({
+            'mode': 'text/x-markdown',
+            'markup_type': 'markdown',
+        })
         self.assertHTMLEqual(
             comment.widget.render('comment', self.mp.comment),
             textwrap.dedent(u"""\
                 <textarea rows="10" cols="40" name="comment"
                           class="item-markupmirror"
-                          data-markuptype="markdown"
-                          data-mode="text/x-markdown"></textarea>"""))
+                          data-mm-settings='{0}'></textarea>""").format(
+                    json.dumps(attrs, sort_keys=True))
+            )
 
     def test_widget_additional_attributes(self):
         """Tests that additional attributes passed to the widget's ``render``
         """
         form = PostForm(instance=self.mp)
         comment = form.fields['comment']
+
+        attrs = self.mm_settings.copy()
+        attrs.update({
+            'mode': 'text/x-markdown',
+            'markup_type': 'markdown',
+        })
         self.assertHTMLEqual(
             comment.widget.render('comment', self.mp.comment, attrs={
                 'data-something': "else",
             textwrap.dedent(u"""\
                 <textarea rows="10" cols="40" name="comment"
                           class="item-markupmirror"
-                          data-markuptype="markdown"
-                          data-mode="text/x-markdown"
-                          data-something="else"></textarea>"""))
+                          data-mm-settings='{0}'
+                          data-something="else"></textarea>""").format(
+                    json.dumps(attrs, sort_keys=True))
+            )
 
     def test_widget_default_mode_and_markuptype(self):
         """Widgets initialized without data (create model forms) should
         comment = form.fields['comment']
 
         default = settings.MARKUPMIRROR_DEFAULT_MARKUP_TYPE
+        attrs = self.mm_settings.copy()
+        attrs.update({
+            'mode': markup_pool[default].codemirror_mode,
+            'markup_type': default,
+        })
         self.assertHTMLEqual(
             comment.widget.render('comment', u""),
             textwrap.dedent(u"""\
                 <textarea rows="10" cols="40" name="comment"
                           class="item-markupmirror"
-                          data-markuptype="{default_markup_type}"
-                          data-mode="{default_mode}"></textarea>""".format(
-                default_markup_type=default,
-                default_mode=markup_pool[default].codemirror_mode)))
+                          data-mm-settings='{0}'></textarea>""").format(
+                json.dumps(attrs, sort_keys=True))
+            )
 
     def test_admin_widget_render(self):
         """Tests that the ``AdminMarkupMirrorTextareaWidget`` renders
 
         """
         admin_widget = AdminMarkupMirrorTextareaWidget()
+        attrs = self.mm_settings.copy()
+        attrs.update({
+            'mode': 'text/x-markdown',
+            'markup_type': 'markdown',
+        })
         self.assertHTMLEqual(
             admin_widget.render('comment', self.mp.comment),
             textwrap.dedent(u"""\
                 <textarea rows="10" cols="40" name="comment"
                           class="vLargeTextField item-markupmirror"
-                          data-markuptype="markdown"
-                          data-mode="text/x-markdown"></textarea>"""))
+                          data-mm-settings='{0}' />""").format(
+                json.dumps(attrs, sort_keys=True))
+            )
 
 __all__ = ('MarkupMirrorWidgetTests',)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.