Beispiel #1
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)
Beispiel #2
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)
Beispiel #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, {})
Beispiel #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, {})
Beispiel #5
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'
            }
        })
Beispiel #6
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'
                }
            })