示例#1
0
 def test_embed(self):
     url = reverse('index')
     response = self.client.get(url)
     self.assertIn(u'Djedi Test', smart_unicode(response.content))
     self.assertIn(u'window.DJEDI_NODES', smart_unicode(response.content))
     self.assertIn(u'i18n://sv-se@foo/bar.txt', smart_unicode(response.content))
     self.assertIn(u'</body>', smart_unicode(response.content).lower())
示例#2
0
 def test_embed(self):
     url = reverse('index')
     response = self.client.get(url)
     self.assertIn(u'Djedi Test', smart_unicode(response.content))
     self.assertIn(u'window.DJEDI_NODES', smart_unicode(response.content))
     self.assertIn(u'i18n://sv-se@foo/bar.txt', smart_unicode(response.content))
     self.assertIn(u'</body>', smart_unicode(response.content).lower())
示例#3
0
    def test_cms(self):
        url = reverse('admin:djedi:cms')
        response = self.client.get(url)
        self.assertIn(u'<title>djedi cms</title>', smart_unicode(response.content))
        self.assertNotIn(u'document.domain', smart_unicode(response.content))
        self.assertNotIn(u'None', smart_unicode(response.content))

        with cio.conf.settings(XSS_DOMAIN='foobar.se'):
            response = self.client.get(url)
            self.assertIn(b'document.domain = "foobar.se"', response.content)
示例#4
0
    def test_render(self):
        response = self.post('api.render', 'foo', {'data': u'# Djedi'})
        assert response.status_code == 404

        response = self.post('api.render', 'md', {'data': u'# Djedi'})
        assert response.status_code == 200
        self.assertRenderedMarkdown(smart_unicode(response.content), u'# Djedi')

        response = self.post('api.render', 'img', {'data': json.dumps({
            'url': '/foo/bar.png',
            'width': '64',
            'height': '64'
        })})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(smart_unicode(response.content), u'<img height="64" src="/foo/bar.png" width="64" />')
示例#5
0
    def test_render(self):
        response = self.post('api.render', 'foo', {'data': u'# Djedi'})
        assert response.status_code == 404

        response = self.post('api.render', 'md', {'data': u'# Djedi'})
        assert response.status_code == 200
        self.assertRenderedMarkdown(smart_unicode(response.content), u'# Djedi')

        response = self.post('api.render', 'img', {'data': json.dumps({
            'url': '/foo/bar.png',
            'width': '64',
            'height': '64'
        })})
        self.assertEqual(response.status_code, 200)
        self.assertEqual(smart_unicode(response.content), u'<img height="64" src="/foo/bar.png" width="64" />')
示例#6
0
 def _decode_content(self, content):
     """
     Split node string to uri and content and convert back to unicode.
     """
     content = smart_unicode(content)
     uri, _, content = content.partition(u'|')
     if content == self.NONE:
         content = None
     return uri or None, content
示例#7
0
 def _decode_content(self, content):
     """
     Split node string to uri and content and convert back to unicode.
     """
     content = smart_unicode(content)
     uri, _, content = content.partition(u'|')
     if content == self.NONE:
         content = None
     return uri or None, content
示例#8
0
 def test_middleware(self):
     with self.settings(MIDDLEWARE_CLASSES=[
         'djedi.middleware.translation.DjediTranslationMiddleware',
     ], MIDDLEWARE=[
         'djedi.middleware.translation.DjediTranslationMiddleware',
     ]):
         url = reverse('index')
         response = self.client.get(url)
         self.assertNotIn(u'window.DJEDI_NODES',
                          smart_unicode(response.content))
示例#9
0
 def test_middleware(self):
     with self.settings(MIDDLEWARE_CLASSES=[
         'djedi.middleware.translation.DjediTranslationMiddleware',
     ], MIDDLEWARE=[
         'djedi.middleware.translation.DjediTranslationMiddleware',
     ]):
         url = reverse('index')
         response = self.client.get(url)
         self.assertNotIn(u'window.DJEDI_NODES',
                          smart_unicode(response.content))
示例#10
0
    def test_django_admin(self):
        # Patch django admin index
        from django.contrib.admin.templatetags.log import AdminLogNode
        _render = AdminLogNode.render
        AdminLogNode.render = lambda x, y: None

        url = reverse('admin:index')
        response = self.client.get(url)
        cms_url = reverse('admin:djedi:cms')
        self.assertIn(u'<a href="%s">CMS</a>' % cms_url, smart_unicode(response.content))

        # Rollback patch
        AdminLogNode.render = _render
示例#11
0
    def test_django_admin(self):
        # Patch django admin index
        from django.contrib.admin.templatetags.log import AdminLogNode
        _render = AdminLogNode.render
        AdminLogNode.render = lambda x, y: None

        url = reverse('admin:index')
        response = self.client.get(url)
        cms_url = reverse('admin:djedi:cms')
        self.assertIn(u'<a href="%s">CMS</a>' % cms_url, smart_unicode(response.content))

        # Rollback patch
        AdminLogNode.render = _render
示例#12
0
    def test_delete(self):
        response = self.delete('api', 'i18n://sv-se@page/title')
        self.assertEqual(response.status_code, 404)

        node = cio.set('i18n://sv-se@page/title.md', u'# Djedi')

        response = self.delete('api', node.uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(smart_unicode(response.content), u'')

        with self.assertRaises(NodeDoesNotExist):
            storage.get('i18n://sv-se@page/title')

        node = cio.get('i18n://page/title', lazy=False)
        self.assertIsNone(node.content)
示例#13
0
    def test_delete(self):
        response = self.delete('api', 'i18n://sv-se@page/title')
        self.assertEqual(response.status_code, 404)

        node = cio.set('i18n://sv-se@page/title.md', u'# Djedi')

        response = self.delete('api', node.uri)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(smart_unicode(response.content), u'')

        with self.assertRaises(NodeDoesNotExist):
            storage.get('i18n://sv-se@page/title')

        node = cio.get('i18n://page/title', lazy=False)
        self.assertIsNone(node.content)
示例#14
0
    def test_embed(self):
        url = reverse('admin:djedi:rest:embed')
        response = self.client.get(url)
        html = smart_unicode(response.content)

        self.assertIn(u'iframe id="djedi-cms"', html)
        cms_url = u'http://testserver' + reverse('admin:djedi:cms')
        self.assertIn(cms_url, html)
        self.assertNotIn(u'window.DJEDI_NODES', html)
        self.assertNotIn(u'document.domain', html)

        with cio.conf.settings(XSS_DOMAIN='foobar.se'):
            response = self.client.get(url)
            self.assertIn(b'document.domain = "foobar.se"', response.content)

        self.client.logout()
        response = self.client.get(url)
        self.assertEqual(response.status_code, 204)
示例#15
0
 def test_embed(self):
     url = reverse("index")
     response = self.client.get(url)
     self.assertIn(u"Djedi Test", smart_unicode(response.content))
     self.assertIn(u"window.DJEDI_NODES", smart_unicode(response.content))
     self.assertIn(u"</body>", smart_unicode(response.content).lower())
示例#16
0
 def test_cms(self):
     url = reverse('admin:djedi:cms')
     response = self.client.get(url)
     self.assertIn(u'<title>djedi cms</title>', smart_unicode(response.content))
示例#17
0
 def test_cms(self):
     url = reverse('admin:djedi:cms')
     response = self.client.get(url)
     self.assertIn(u'<title>djedi cms</title>',
                   smart_unicode(response.content))