Commits

Anonymous committed 890b85b

More tests.

Comments (0)

Files changed (9)

markupmirror/feincms_/__init__.py

+try:
+    import feincms
+except ImportError:
+    raise ImportError(
+        "FeinCMS is required to use markupmirror.feincms.MarkupMirrorContent.")

markupmirror/feincms_/models.py

+from django.db import models
+from django.template.loader import render_to_string
+from django.utils.translation import ugettext_lazy as _
+
+from markupmirror import settings
+from markupmirror.fields import MarkupMirrorField
+
+
+class MarkupMirrorContent(models.Model):
+    """FeinCMS Page contenttype that stores markup in a MarkupMirrorField.
+
+    """
+    # TODO: find a way to include a button like richtext content
+    # __name__ = 'richtextcontent'
+
+    feincms_item_editor_context_processors = (
+        lambda x: settings.FEINCMS_INIT_CONTEXT,
+    )
+    feincms_item_editor_includes = {
+        'head': [settings.FEINCMS_INIT_TEMPLATE],
+    }
+
+    content = MarkupMirrorField(
+        verbose_name=_(u"Markup content"),
+        markup_type=settings.DEFAULT_MARKUP_TYPE,
+        blank=True)
+
+    class Meta:
+        abstract = True
+        app_label = 'wienfluss'
+        verbose_name = _(u"Markup content")
+        verbose_name_plural = _(u"Markup content")
+
+    def render(self, **kwargs):
+        request = kwargs.get('request')
+        return render_to_string('content/markupmirror/default.html', {
+            'content': self,
+            'request': request
+        })
+
+
+__all__ = ('MarkupMirrorContent',)
 Django == 1.4
 coverage == 3.5.1
+django-mptt == 0.5.2
 django-nose == 1.0
 docutils == 0.8.1
 ipython == 0.12

tests/requirements.txt

 coverage == 3.5.1
+django-mptt == 0.5.2
 django-nose == 1.0
 docutils == 0.8.1
 ipython == 0.12

tests/tests/__init__.py

+from tests.tests.feincms_ import *
 from tests.tests.fields import *
 from tests.tests.markup_base import *
 from tests.tests.markup_html import *

tests/tests/feincms_.py

+from django.test import TestCase
+
+from markupmirror.feincms.models import MarkupMirrorContent
+
+
+class FeinCMSTests(TestCase):
+    """Tests the ``markupmirror.feincms`` module that provides integration
+    into FeinCMS as page content-type.
+
+    """
+    def test_import(self):
+        """The ``markupmirror.feincms`` app can only be installed when
+        FeinCMS is installed.
+
+        """
+        # returns True if feincms is installed or False otherwise
+        def import_markupmirror_feincms():
+            try:
+                import markupmirror.feincms
+                return True
+            except ImportError:
+                return False
+
+        # unregister previous imports
+        import sys
+        to_delete = [module for module in sys.modules
+            if (module.startswith('markupmirror.feincms') or
+                module.startswith('feincms'))]
+        for module in to_delete:
+            del sys.modules[module]
+        self.assertFalse('markupmirror.feincms' in sys.modules)
+        self.assertFalse('feincms' in sys.modules)
+
+        # save original import
+        import __builtin__
+        original_import = __builtin__.__import__
+
+        # patch and test the import
+        def import_hook(name, *args, **kwargs):
+            if name in 'feincms':
+                raise ImportError("TestCase ImportError")
+            else:
+                original_import(name, *args, **kwargs)
+        __builtin__.__import__ = import_hook
+
+        # without FeinCMS, the import should fail
+        self.assertFalse(import_markupmirror_feincms())
+
+        # with FeinCMS installed, the import should work
+        # restore import
+        __builtin__.__import__ = original_import
+        self.assertTrue(import_markupmirror_feincms())
+
+        # restore normal import
+        from markupmirror.feincms import models
+        self.assertTrue('markupmirror.feincms' in sys.modules)
+        self.assertTrue('markupmirror.feincms.models' in sys.modules)
+
+    def test_markupmirror_content(self):
+        """
+        """
+        from feincms.module.page.models import Page
+        from markupmirror.feincms.models import MarkupMirrorContent
+        Page.register_templates({
+            'key': 'page',
+            'title': 'Page template',
+            'path': 'feincms_page.html',
+            'regions': (
+                ('main', 'Main region'),
+                ),
+        })
+        Page.create_content_type(MarkupMirrorContent)

tests/tests/templates/feincms_base.html

+{% load feincms_tags %}
+<html>
+<head>
+    <title>{{ feincms_page.title }}</title>
+</head>
+<body>
+    <h1>{{ feincms_page.title }}</h1>
+    {% block 'content' %}{% endblock %}
+</body>
+</html>

tests/tests/templates/feincms_page.html

+{% load feincms_tags %}
+
+{% block 'content' %}
+    {% feincms_render_region feincms_page 'main' request %}
+{% endblock %}

tests/tests/version.py

     def tearDown(self):
         markupmirror.VERSION_INFO = self.original_version
 
+    def test_definitions(self):
+        """Tests that the module-level definitions in ``markupmirror.__ini__``
+        work. (This is mainly for coverage)
+
+        """
+        import sys
+        del sys.modules['markupmirror']
+        import markupmirror
+        self.assertTrue(hasattr(markupmirror, 'VERSION_INFO'))
+        self.assertTrue(hasattr(markupmirror, 'get_version'))
+        self.assertTrue(hasattr(markupmirror, '__version__'))
+
     def test_get_version(self):
         """Tests if ``markupmirror.get_version`` returns the correct dotted
         version string depending on the settings in ``VERSION_INFO``.
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.