Beispiel #1
0
    def test_08_creating_two_content_types_in_same_application(self):
        ExampleCMSBase.create_content_type(RawContent)
        ct = ExampleCMSBase.content_type_for(RawContent)
        self.assertEqual(ct._meta.db_table, "testapp_examplecmsbase_rawcontent")

        ExampleCMSBase2.create_content_type(RawContent, class_name="RawContent2")
        ct2 = ExampleCMSBase2.content_type_for(RawContent)
        self.assertEqual(ct2._meta.db_table, "testapp_examplecmsbase2_rawcontent2")
Beispiel #2
0
    def test_02_rsscontent_creation(self):
        # this test resides in its own method because the required feedparser
        # module is not available everywhere

        from feincms.content.rss.models import RSSContent, feedparser

        # Monkey-patch feedparser.parse to work with a local RSS dump so that
        # the tests run faster.
        _orig_parse = feedparser.parse

        def _new_parse(link):
            filename = os.path.join(os.path.dirname(__file__), "yahoo.rss")
            with open(filename, "rb") as handle:
                return _orig_parse(handle)

        feedparser.parse = _new_parse

        type = ExampleCMSBase.create_content_type(RSSContent)
        obj = type()

        self.assertTrue("yahoo" not in obj.render())

        obj.link = "http://rss.news.yahoo.com/rss/topstories"
        obj.cache_content(save=False)

        self.assertTrue("yahoo" in obj.render())
Beispiel #3
0
    def test_04_mediafilecontent_creation(self):
        # the medialibrary needs to be enabled, otherwise this test fails

        # no TYPE_CHOICES, should raise
        self.assertRaises(
            ImproperlyConfigured,
            lambda: ExampleCMSBase.create_content_type(MediaFileContent))
Beispiel #4
0
    def test_05_non_abstract_content_type(self):
        # Should not be able to create a content type from a non-abstract base
        # type
        class TestContentType(models.Model):
            pass

        self.assertRaises(ImproperlyConfigured, lambda: ExampleCMSBase.create_content_type(TestContentType))
Beispiel #5
0
    def test_05_non_abstract_content_type(self):
        # Should not be able to create a content type from a non-abstract base
        # type
        class TestContentType(models.Model):
            pass

        self.assertRaises(
            ImproperlyConfigured,
            lambda: ExampleCMSBase.create_content_type(TestContentType))
Beispiel #6
0
    def test_04_mediafilecontent_creation(self):
        # the medialibrary needs to be enabled, otherwise this test fails

        from feincms.content.medialibrary.models import MediaFileContent

        # no TYPE_CHOICES, should raise
        self.assertRaises(
            ImproperlyConfigured,
            lambda: ExampleCMSBase.create_content_type(MediaFileContent))
Beispiel #7
0
    def test_09_related_objects_cache(self):
        """
        We need to define a model with relationship to our Base *after* all
        content types have been registered; previously _fill_*_cache methods
        were called during each content type registration, so any new related
        objects added after the last content type time missed the boat. Now we
        delete the cache so hopefully _fill_*_cache* won't be called until all
        related models have been defined.

        TODO that's a dumb test, we should try being less dynamic instead of
        supporting all types of ad-hoc definitions of models etc.

        It also fails on Django 1.7 since the introduction of django.apps
        """
        class Attachment(models.Model):
            base = models.ForeignKey(
                ExampleCMSBase,
                related_name='test_related_name')

        # See issue #323 on Github.
        ExampleCMSBase._meta._fill_related_objects_cache()

        related_models = map(
            lambda x: x.model, ExampleCMSBase._meta.get_all_related_objects())

        self.assertTrue(Attachment in related_models)
        self.assertTrue(hasattr(ExampleCMSBase, 'test_related_name'))
        # self.assertFalse(hasattr(Attachment, 'anycontents'))

        class AnyContent(models.Model):
            attachment = models.ForeignKey(
                Attachment,
                related_name='anycontents')

            class Meta:
                abstract = True

        ExampleCMSBase.create_content_type(AnyContent)

        self.assertTrue(hasattr(ExampleCMSBase, 'test_related_name'))
        self.assertTrue(hasattr(Attachment, 'anycontents'))
Beispiel #8
0
    def test_06_videocontent(self):
        type = ExampleCMSBase.content_type_for(VideoContent)
        obj = type()
        obj.video = 'http://www.youtube.com/watch?v=zmj1rpzDRZ0'

        self.assertTrue('x-shockwave-flash' in obj.render())

        self.assertEqual(getattr(type, 'arbitrary_arg'), 'arbitrary_value')

        obj.video = 'http://www.example.com/'

        self.assertTrue(obj.video in obj.render())
Beispiel #9
0
    def test_06_videocontent(self):
        type = ExampleCMSBase.content_type_for(VideoContent)
        obj = type()
        obj.video = 'http://www.youtube.com/watch?v=zmj1rpzDRZ0'

        self.assertTrue('x-shockwave-flash' in obj.render())

        self.assertEqual(getattr(type, 'arbitrary_arg'), 'arbitrary_value')

        obj.video = 'http://www.example.com/'

        self.assertTrue(obj.video in obj.render())
Beispiel #10
0
    def test_09_related_objects_cache(self):
        """
        We need to define a model with relationship to our Base *after* all
        content types have been registered; previously _fill_*_cache methods
        were called during each content type registration, so any new related
        objects added after the last content type time missed the boat. Now we
        delete the cache so hopefully _fill_*_cache* won't be called until all
        related models have been defined.

        TODO that's a dumb test, we should try being less dynamic instead of
        supporting all types of ad-hoc definitions of models etc.

        It also fails on Django 1.7 since the introduction of django.apps
        """
        class Attachment(models.Model):
            base = models.ForeignKey(ExampleCMSBase,
                                     related_name='test_related_name')

        # See issue #323 on Github.
        ExampleCMSBase._meta._fill_related_objects_cache()

        related_models = map(lambda x: x.model,
                             ExampleCMSBase._meta.get_all_related_objects())

        self.assertTrue(Attachment in related_models)
        self.assertTrue(hasattr(ExampleCMSBase, 'test_related_name'))

        # self.assertFalse(hasattr(Attachment, 'anycontents'))

        class AnyContent(models.Model):
            attachment = models.ForeignKey(Attachment,
                                           related_name='anycontents')

            class Meta:
                abstract = True

        ExampleCMSBase.create_content_type(AnyContent)

        self.assertTrue(hasattr(ExampleCMSBase, 'test_related_name'))
        self.assertTrue(hasattr(Attachment, 'anycontents'))
Beispiel #11
0
    def test_07_default_render_method(self):
        class SomethingElse(models.Model):
            class Meta:
                abstract = True

            def render_region(self):
                return 'hello'

        type = ExampleCMSBase.create_content_type(SomethingElse)
        obj = type()
        self.assertRaises(NotImplementedError, lambda: obj.render())

        obj.region = 'region'
        self.assertEqual(obj.render(), 'hello')
Beispiel #12
0
    def test_07_default_render_method(self):
        class SomethingElse(models.Model):
            class Meta:
                abstract = True

            def render_region(self):
                return 'hello'

        type = ExampleCMSBase.create_content_type(SomethingElse)
        obj = type()
        self.assertRaises(NotImplementedError, lambda: obj.render())

        obj.region = 'region'
        self.assertEqual(obj.render(), 'hello')
Beispiel #13
0
    def test_10_content_type_subclasses(self):
        """
        See:
        https://github.com/feincms/feincms/issues/339
        """
        ExampleCMSBase.create_content_type(SubRawContent)
        ExampleCMSBase.create_content_type(RawContent)

        ct = ExampleCMSBase.content_type_for(RawContent)
        ct2 = ExampleCMSBase.content_type_for(SubRawContent)
        self.assertNotEqual(ct, ct2)
Beispiel #14
0
    def test_10_content_type_subclasses(self):
        """
        See:
        https://github.com/feincms/feincms/issues/339
        """
        ExampleCMSBase.create_content_type(SubRawContent)
        ExampleCMSBase.create_content_type(RawContent)

        ct = ExampleCMSBase.content_type_for(RawContent)
        ct2 = ExampleCMSBase.content_type_for(SubRawContent)
        self.assertNotEqual(ct, ct2)
Beispiel #15
0
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(RawContent), None)

        ExampleCMSBase.create_content_type(RawContent, regions=('main2', ))
        ExampleCMSBase.create_content_type(RichTextContent)

        # content_type_for should return None if it does not have a subclass
        # registered
        self.assertEqual(ExampleCMSBase.content_type_for(Empty), None)

        self.assertTrue('rawcontent' not in dict(
            ExampleCMSBase.template.regions[0].content_types).keys())
Beispiel #16
0
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(RawContent), None)

        ExampleCMSBase.create_content_type(RawContent, regions=('main2',))
        ExampleCMSBase.create_content_type(RichTextContent)

        # content_type_for should return None if it does not have a subclass
        # registered
        self.assertEqual(ExampleCMSBase.content_type_for(Empty), None)

        self.assertTrue(
            'rawcontent' not in dict(
                ExampleCMSBase.template.regions[0].content_types).keys())
Beispiel #17
0
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(FileContent), None)

        ExampleCMSBase.create_content_type(ContactFormContent)
        ExampleCMSBase.create_content_type(FileContent, regions=('region2', ))

        ExampleCMSBase.create_content_type(RawContent)
        ExampleCMSBase.create_content_type(RichTextContent)

        # test creating a cotent with arguments, but no initialize_type
        # classmethod
        ExampleCMSBase.create_content_type(VideoContent,
                                           arbitrary_arg='arbitrary_value')

        # content_type_for should return None if it does not have a subclass
        # registered
        self.assertEqual(ExampleCMSBase.content_type_for(Empty), None)

        self.assertTrue('filecontent' not in dict(
            ExampleCMSBase.template.regions[0].content_types).keys())
        self.assertTrue('filecontent' in dict(
            ExampleCMSBase.template.regions[1].content_types).keys())
Beispiel #18
0
    def test_01_simple_content_type_creation(self):
        self.assertEqual(ExampleCMSBase.content_type_for(FileContent), None)

        ExampleCMSBase.create_content_type(ContactFormContent)
        ExampleCMSBase.create_content_type(FileContent, regions=('region2',))

        ExampleCMSBase.create_content_type(RawContent)
        ExampleCMSBase.create_content_type(RichTextContent)

        # test creating a cotent with arguments, but no initialize_type
        # classmethod
        ExampleCMSBase.create_content_type(
            VideoContent,
            arbitrary_arg='arbitrary_value')

        # content_type_for should return None if it does not have a subclass
        # registered
        self.assertEqual(ExampleCMSBase.content_type_for(Empty), None)

        self.assertTrue(
            'filecontent' not in dict(
                ExampleCMSBase.template.regions[0].content_types).keys())
        self.assertTrue(
            'filecontent' in dict(
                ExampleCMSBase.template.regions[1].content_types).keys())