Example #1
0
 def test_create_update(self):
     storage.set('i18n://[email protected]#draft', u'first')
     node = storage.get('i18n://sv-se@a#draft')
     self.assertEqual(node['content'], u'first')
     self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
     storage.set('i18n://[email protected]#draft', u'second')
     node = storage.get('i18n://sv-se@a#draft')
     self.assertEqual(node['content'], u'second')
     self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
Example #2
0
 def test_create_update(self):
     storage.set('i18n://[email protected]#draft', u'first')
     node = storage.get('i18n://sv-se@a#draft')
     self.assertEqual(node['content'], u'first')
     self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
     storage.set('i18n://[email protected]#draft', u'second')
     node = storage.get('i18n://sv-se@a#draft')
     self.assertEqual(node['content'], u'second')
     self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
Example #3
0
    def test_plugin_mismatch(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.publish('i18n://[email protected]#draft')

        with self.assertRaises(NodeDoesNotExist):
            storage.get('i18n://[email protected]')

        nodes = storage.get_many(('i18n://[email protected]',))
        self.assertDictEqual(nodes, {})
Example #4
0
    def test_plugin_mismatch(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.publish('i18n://[email protected]#draft')

        with self.assertRaises(NodeDoesNotExist):
            storage.get('i18n://[email protected]')

        nodes = storage.get_many(('i18n://[email protected]', ))
        self.assertDictEqual(nodes, {})
Example #5
0
    def test_cached_node(self):
        with self.assertRaises(NodeDoesNotExist):
            storage.get(self.uri)

        content = cache.get(self.uri)
        self.assertIsNone(content)

        node, _ = storage.set(self.uri + '#draft', u'e-post')
        storage.publish(node['uri'])

        with self.assertCache(calls=2, misses=1, sets=1):
            node = cio.get('i18n://label/email', lazy=False)

        cached_node = cache.get('i18n://sv-se@label/email')
        self.assertIsInstance(cached_node, dict)
        self.assertKeys(cached_node, 'uri', 'content')
        _uri, content = cached_node['uri'], cached_node['content']
        self.assertEqual(_uri, 'i18n://sv-se@label/email.txt#1')
        self.assertTrue(content == node.content == u'e-post')

        with self.assertCache(calls=1, misses=0, hits=1):
            node = cio.get('i18n://label/email', lazy=False)
            self.assertEqual(node.uri, 'i18n://sv-se@label/email.txt#1')

        cio.delete(self.uri)
        content = cache.get(self.uri)
        self.assertIsNone(content)
Example #6
0
    def test_cached_node(self):
        with self.assertRaises(NodeDoesNotExist):
            storage.get(self.uri)

        content = cache.get(self.uri)
        self.assertIsNone(content)

        node, _ = storage.set(self.uri + '#draft', u'e-post')
        storage.publish(node['uri'])

        with self.assertCache(calls=2, misses=1, sets=1):
            node = cio.get('i18n://label/email', lazy=False)

        cached_node = cache.get('i18n://sv-se@label/email')
        self.assertIsInstance(cached_node, dict)
        self.assertKeys(cached_node, 'uri', 'content')
        _uri, content = cached_node['uri'], cached_node['content']
        self.assertEqual(_uri, 'i18n://sv-se@label/email.txt#1')
        self.assertTrue(content == node.content == u'e-post')

        with self.assertCache(calls=1, misses=0, hits=1):
            node = cio.get('i18n://label/email', lazy=False)
            self.assertEqual(node.uri, 'i18n://sv-se@label/email.txt#1')

        cio.delete(self.uri)
        content = cache.get(self.uri)
        self.assertIsNone(content)
Example #7
0
    def test_delete(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.set('i18n://[email protected]#draft', u'B')

        node = storage.get('i18n://sv-se@a#draft')
        self.assertEqual(node['content'], u'A')

        deleted_node = storage.delete('sv-se@a#draft')
        deleted_node.pop('meta')
        self.assertDictEqual(deleted_node, {'uri': 'i18n://[email protected]#draft', 'content': u'A'})

        deleted_nodes = storage.delete_many(('sv-se@a#draft', 'sv-se@b#draft'))
        for node in deleted_nodes.values():
            node.pop('meta')
        self.assertDictEqual(deleted_nodes, {
            'i18n://sv-se@b#draft': {'uri': 'i18n://[email protected]#draft', 'content': u'B'}
        })
Example #8
0
    def test_get(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.set('i18n://[email protected]#draft', u'B')
        node = storage.get('i18n://sv-se@a#draft')
        self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
        self.assertEqual(node['content'], u'A')

        storage.publish('i18n://sv-se@a#draft')
        storage.publish('i18n://sv-se@b#draft')

        nodes = storage.get_many(('i18n://sv-se@a', 'i18n://sv-se@b'))
        for node in nodes.values():
            node.pop('meta')
        self.assertDictEqual(nodes, {
            'i18n://sv-se@a': {
                'uri': 'i18n://[email protected]#1',
                'content': u'A'
            },
            'i18n://sv-se@b': {
                'uri': 'i18n://[email protected]#1',
                'content': u'B'
            }
        })
Example #9
0
    def test_delete(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.set('i18n://[email protected]#draft', u'B')

        node = storage.get('i18n://sv-se@a#draft')
        self.assertEqual(node['content'], u'A')

        deleted_node = storage.delete('sv-se@a#draft')
        deleted_node.pop('meta')
        self.assertDictEqual(deleted_node, {
            'uri': 'i18n://[email protected]#draft',
            'content': u'A'
        })

        deleted_nodes = storage.delete_many(('sv-se@a#draft', 'sv-se@b#draft'))
        for node in deleted_nodes.values():
            node.pop('meta')
        self.assertDictEqual(
            deleted_nodes, {
                'i18n://sv-se@b#draft': {
                    'uri': 'i18n://[email protected]#draft',
                    'content': u'B'
                }
            })
Example #10
0
    def test_get(self):
        storage.set('i18n://[email protected]#draft', u'A')
        storage.set('i18n://[email protected]#draft', u'B')
        node = storage.get('i18n://sv-se@a#draft')
        self.assertEqual(node['uri'], 'i18n://[email protected]#draft')
        self.assertEqual(node['content'], u'A')

        storage.publish('i18n://sv-se@a#draft')
        storage.publish('i18n://sv-se@b#draft')

        nodes = storage.get_many(('i18n://sv-se@a', 'i18n://sv-se@b'))
        for node in nodes.values():
            node.pop('meta')
        self.assertDictEqual(
            nodes, {
                'i18n://sv-se@a': {
                    'uri': 'i18n://[email protected]#1',
                    'content': u'A'
                },
                'i18n://sv-se@b': {
                    'uri': 'i18n://[email protected]#1',
                    'content': u'B'
                }
            })
Example #11
0
    def test_search(self):
        storage.set('i18n://sv-se@foo/bar.txt#draft', u'')
        storage.set('i18n://sv-se@foo/bar/baz.md#draft', u'')
        storage.set('i18n://en@foo/bar/baz.md#draft', u'')
        storage.set('i18n://en@foo/bar/baz.md#1', u'')
        storage.set('i18n://en@ham/spam.txt#draft', u'')
        storage.set('l10n://a@foo/bar.md#draft', u'')
        storage.set('l10n://b@foo/bar/baz.txt#draft', u'')

        uris = storage.search()
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
            'l10n://a@foo/bar.md',
            'l10n://b@foo/bar/baz.txt',
        ])

        uris = storage.search('i18n://')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('en@')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
        ])

        uris = storage.search('foo/')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
            'l10n://a@foo/bar.md',
            'l10n://b@foo/bar/baz.txt',
        ])

        uris = storage.search('sv-se@foo/')
        self.assertListEqual(uris, [
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('i18n://foo/')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('i18n://en@')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
        ])
Example #12
0
    def test_search(self):
        storage.set('i18n://sv-se@foo/bar.txt#draft', u'')
        storage.set('i18n://sv-se@foo/bar/baz.md#draft', u'')
        storage.set('i18n://en@foo/bar/baz.md#draft', u'')
        storage.set('i18n://en@foo/bar/baz.md#1', u'')
        storage.set('i18n://en@ham/spam.txt#draft', u'')
        storage.set('l10n://a@foo/bar.md#draft', u'')
        storage.set('l10n://b@foo/bar/baz.txt#draft', u'')

        uris = storage.search()
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
            'l10n://a@foo/bar.md',
            'l10n://b@foo/bar/baz.txt',
        ])

        uris = storage.search('i18n://')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('en@')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
        ])

        uris = storage.search('foo/')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
            'l10n://a@foo/bar.md',
            'l10n://b@foo/bar/baz.txt',
        ])

        uris = storage.search('sv-se@foo/')
        self.assertListEqual(uris, [
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('i18n://foo/')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://sv-se@foo/bar.txt',
            'i18n://sv-se@foo/bar/baz.md',
        ])

        uris = storage.search('i18n://en@')
        self.assertListEqual(uris, [
            'i18n://en@foo/bar/baz.md',
            'i18n://en@ham/spam.txt',
        ])