Example #1
0
    def test_uri(self):
        self.assertEqual(URI('i18n://sv@page/title.txt'), 'i18n://sv@page/title.txt')

        uri = URI(scheme='i18n', namespace='sv-se', path='page/title', ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')

        uri = URI('page/title')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri.scheme, 'i18n')
        self.assertIsNone(uri.namespace)
        self.assertEqual(uri.path, 'page/title')
        self.assertIsNone(uri.ext)

        uri = uri.clone(namespace='sv-se')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri, 'i18n://sv-se@page/title')

        uri = uri.clone(ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')
        self.assertTrue(uri.is_absolute())

        uri = URI('page/title')
        uri = uri.clone(scheme=None)
        self.assertEqual(uri, 'page/title')

        uri = URI('i18n://sv@page/title.txt#draft')
        self.assertEqual(uri, 'i18n://sv@page/title.txt#draft')
        self.assertEqual(uri.version, 'draft')
Example #2
0
 def test_node_integrity(self):
     storage.backend._create(URI('i18n://[email protected]#draft'), u'first')
     with self.assertRaises(PersistenceError):
         storage.backend._create(URI('i18n://sv-se@a'), u'second')
     with self.assertRaises(PersistenceError):
         storage.backend._create(URI('i18n://[email protected]'), u'second')
     with self.assertRaises(PersistenceError):
         storage.backend._create(URI('i18n://sv-se@a#draft'), u'second')
Example #3
0
    def test_set(self):
        response = self.post('api', 'i18n://page/title', {'data': u'# Djedi'})
        self.assertEqual(response.status_code, 400)

        response = self.post('api', 'i18n://sv-se@page/title.txt', {'data': u'# Djedi', 'data[extra]': u'foobar'})
        self.assertEqual(response.status_code, 400)

        uri = 'i18n://sv-se@page/title.md'
        response = self.post('api', uri, {'data': u'# Djedi', 'meta[message]': u'lundberg'})
        self.assertEqual(response.status_code, 200)
        node = json_node(response, simple=False)
        meta = node.pop('meta')
        self.assertDictEqual(node, {'uri': 'i18n://sv-se@page/title.md#draft', 'content': u'<h1>Djedi</h1>'})
        self.assertEqual(meta['author'], u'master')
        self.assertEqual(meta['message'], u'lundberg')

        node = cio.get(uri, lazy=False)
        self.assertIsNone(node.content)
        cio.publish(uri)
        node = cio.get(uri, lazy=False)
        self.assertEqual(node.uri, 'i18n://sv-se@page/title.md#1')
        self.assertEqual(node.content, u'<h1>Djedi</h1>')

        response = self.post('api', node.uri, {'data': u'# Djedi', 'meta[message]': u'Lundberg'})
        node = json_node(response, simple=False)
        self.assertEqual(node['meta']['message'], u'Lundberg')

        with self.assertRaises(PersistenceError):
            storage.backend._create(URI(node['uri']), None)
Example #4
0
 def get(self, request, uri):
     try:
         uri = self.decode_uri(uri)
         uri = URI(uri)
         plugins.resolve(uri)
     except UnknownPlugin:
         raise Http404
     else:
         return self.render_plugin(request, self.get_context_data(uri=uri))
Example #5
0
    def get(self, request, uri):
        try:
            uri = self.decode_uri(uri)
            uri = URI(uri)
            plugin = plugins.resolve(uri)
            plugin_context = self.get_context_data(uri=uri)

            if isinstance(plugin, DjediPlugin):
                plugin_context = plugin.get_editor_context(**plugin_context)

        except UnknownPlugin:
            raise Http404
        else:
            return self.render_plugin(request, plugin_context)
Example #6
0
    def test_uri_query_params(self):
        # Verify query params are snatched up
        uri = URI('i18n://sv@page/title.txt?var=someval')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?var=someval')
        self.assertDictEqual(uri.query, {
            'var': ['someval']
        })

        # Verify query params work with version
        uri = URI('i18n://sv@page/title.txt?var=someval#2')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?var=someval#2')
        self.assertDictEqual(uri.query, {
            'var': ['someval']
        })

        # Verify multiple query parameters are handled
        uri = URI('i18n://sv@page/title.txt?var=someval&second=2')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?var=someval&second=2')
        self.assertDictEqual(uri.query, {
            'var': ['someval'],
            'second': ['2'],
        })

        # Verify query params can be replaced when cloned
        uri = uri.clone(query={
            'var': ['newval'],
            'second': ['1']
        })
        self.assertDictEqual(uri.query, {
            'var': ['newval'],
            'second': ['1']
        })
        exact_copy = uri.clone()
        self.assertEqual(exact_copy, uri)
        self.assertDictEqual(exact_copy.query, uri.query)
        self.assertEqual(exact_copy.query['second'], ['1'])
        self.assertNotEqual(id(exact_copy.query), id(uri.query))

        # Verify replacement works
        uri = URI('i18n://sv@page/title.txt?var=someval&second=2').clone(query=None)
        self.assertEqual(uri.query, None)

        # Verify unicode strings are handled correctly
        value = quote(u'räv')
        unicode_uri = u'i18n://sv@page/title.txt?fox=' + value
        uri = URI(unicode_uri.encode('utf-8'))
        self.assertEqual(uri, unicode_uri)
        self.assertDictEqual(uri.query, {
            u'fox': [u'räv']
        })

        # Verify query parameter order
        uri = URI(b'i18n://sv@page/title.txt?fox=1&variable=2&last=3')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?fox=1&variable=2&last=3')
        self.assertDictEqual(uri.query, {
            'fox': ['1'],
            'variable': ['2'],
            'last': ['3']
        })

        # Verify empty variables are handled correctly
        uri = URI(u'i18n://sv@page/title.txt?fox=&variable')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?fox=&variable=')
        self.assertDictEqual(uri.query, {
            'fox': [],
            'variable': []
        })

        # Verify delimiters as values and/or keys
        value = quote(u'i18n://sv@page/title.txt#1')
        unicode_uri = u'i18n://sv@page/title.txt?fox=' + value
        uri = URI(unicode_uri.encode('utf-8'))
        self.assertEqual(uri, unicode_uri)
        self.assertDictEqual(uri.query, {
            'fox': [u'i18n://sv@page/title.txt#1']
        })

        # Verify multiple query params with same key return last entry
        uri = URI('i18n://sv@page/title.txt?key=a&key=b&key=c')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?key=c')
        self.assertDictEqual(uri.query, {
            'key': ['c']
        })

        # Verify query string handles when no values are inputted
        uri = URI('i18n://sv@page/title.txt?')
        self.assertEqual(uri, 'i18n://sv@page/title.txt')
        self.assertEqual(uri.query, None)

        # Verify query string handles when keys without values are inputted
        uri = URI('i18n://sv@page/title.txt?key')
        self.assertEqual(uri, 'i18n://sv@page/title.txt?key=')
        self.assertEqual(uri.query, {
            'key': []
        })
Example #7
0
    def test_uri(self):
        self.assertEqual(URI('i18n://sv@page/title.txt'), 'i18n://sv@page/title.txt')

        uri = URI(scheme='i18n', namespace='sv-se', path='page/title', ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')

        uri = URI('page/title')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri.scheme, 'i18n')
        self.assertIsNone(uri.namespace)
        self.assertEqual(uri.path, 'page/title')
        self.assertIsNone(uri.ext)

        uri = uri.clone(namespace='sv-se')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri, 'i18n://sv-se@page/title')

        uri = uri.clone(ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')
        self.assertTrue(uri.is_absolute())

        uri = uri.clone(path='images/me.jpg/title', version='draft')
        self.assertEqual(uri, 'i18n://sv-se@images/me.jpg/title.txt#draft')
        self.assertEqual(uri.version, 'draft')
        self.assertEqual(uri.path, 'images/me.jpg/title')
        self.assertEqual(uri.ext, 'txt')

        uri = uri.clone(ext=None)
        self.assertEqual(uri, 'i18n://sv-se@images/me.jpg/title#draft')
        self.assertIsNone(uri.ext)

        with settings(URI_DEFAULT_SCHEME='l10n'):
            uri = URI('page/title')
            self.assertEqual(uri, 'l10n://page/title')
            self.assertEqual(uri.scheme, 'l10n')
        uri = uri.clone(scheme=None)
        self.assertEqual(uri, 'page/title')
        self.assertEqual(uri.scheme, None)

        uri = URI('i18n://sv@page/title.txt#draft')
        self.assertEqual(uri, 'i18n://sv@page/title.txt#draft')
        self.assertEqual(uri.version, 'draft')
Example #8
0
    def test_uri(self):
        self.assertEqual(URI('i18n://sv@page/title.txt'), 'i18n://sv@page/title.txt')

        uri = URI(scheme='i18n', namespace='sv-se', path='page/title', ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')

        uri = URI('page/title')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri.scheme, 'i18n')
        self.assertIsNone(uri.namespace)
        self.assertEqual(uri.path, 'page/title')
        self.assertIsNone(uri.ext)

        uri = uri.clone(namespace='sv-se')
        self.assertFalse(uri.is_absolute())
        self.assertEqual(uri, 'i18n://sv-se@page/title')

        uri = uri.clone(ext='txt')
        self.assertEqual(uri, 'i18n://sv-se@page/title.txt')
        self.assertTrue(uri.is_absolute())

        uri = uri.clone(path='images/me.jpg/title', version='draft')
        self.assertEqual(uri, 'i18n://sv-se@images/me.jpg/title.txt#draft')
        self.assertEqual(uri.version, 'draft')
        self.assertEqual(uri.path, 'images/me.jpg/title')
        self.assertEqual(uri.ext, 'txt')

        uri = uri.clone(ext=None)
        self.assertEqual(uri, 'i18n://sv-se@images/me.jpg/title#draft')
        self.assertIsNone(uri.ext)

        with settings(URI_DEFAULT_SCHEME='l10n'):
            uri = URI('page/title')
            self.assertEqual(uri, 'l10n://page/title')
            self.assertEqual(uri.scheme, 'l10n')
        uri = uri.clone(scheme=None)
        self.assertEqual(uri, 'page/title')
        self.assertEqual(uri.scheme, None)

        uri = URI('i18n://sv@page/title.txt#draft')
        self.assertEqual(uri, 'i18n://sv@page/title.txt#draft')
        self.assertEqual(uri.version, 'draft')