Example #1
0
    def test_cache_encoding(self):
        cio.set(self.uri, u'epost')

        cached_node = cache.get(self.uri)
        content = cached_node['content']
        self.assertIsInstance(content, six.text_type)
        self.assertEqual(content, u'epost')

        cache.set('i18n://sv-se@label/email.txt#1', u'epost')
        nodes = cache.get_many((self.uri, self.uri))
        self.assertDictEqual(nodes, {self.uri: {'uri': 'i18n://sv-se@label/email.txt#1', 'content': u'epost'}})
Example #2
0
    def test_cache_delete(self):
        uris = ['i18n://[email protected]', 'i18n://[email protected]']

        cache.set(uris[0], u'Foo')
        cache.set(uris[1], u'Bar')

        with self.assertCache(hits=2):
            cache.get_many(uris)

        cache.delete_many(uris)

        with self.assertCache(misses=2):
            cache.get_many(uris)
Example #3
0
    def test_cache_delete(self):
        uris = ['i18n://[email protected]', 'i18n://[email protected]']

        cache.set(uris[0], u'Foo')
        cache.set(uris[1], u'Bar')

        with self.assertCache(hits=2):
            cache.get_many(uris)

        cache.delete_many(uris)

        with self.assertCache(misses=2):
            cache.get_many(uris)
Example #4
0
    def test_set(self):
        uri = 'i18n://sv-se@page/title.txt#1'
        content = u'Title'

        self.assertIsNone(cache.get(uri))
        cache.set(uri, content)

        node = cache.get(uri)
        self.assertEqual(node['uri'], uri)
        self.assertEqual(node['content'], content)

        cache.delete(uri)
        self.assertIsNone(cache.get(uri))
Example #5
0
    def test_set(self):
        uri = 'i18n://sv-se@page/title.txt#1'
        content = u'Title'

        self.assertIsNone(cache.get(uri))
        cache.set(uri, content)

        node = cache.get(uri)
        self.assertEqual(node['uri'], uri)
        self.assertEqual(node['content'], content)

        cache.delete(uri)
        self.assertIsNone(cache.get(uri))
Example #6
0
    def test_cache_set(self):
        with self.assertRaises(URI.Invalid):
            cache.set('i18n://sv-se@foo', u'Bar')

        nodes = {
            'i18n://[email protected]#1': u'Foo',
            'i18n://[email protected]#2': u'Bar'
        }
        cache.set_many(nodes)

        with self.assertCache(calls=1, hits=2):
            result = cache.get_many(['i18n://sv-se@foo', 'i18n://sv-se@bar'])
            self.assertDictEqual(result, {
                'i18n://sv-se@foo': {'uri': 'i18n://[email protected]#1', 'content': u'Foo'},
                'i18n://sv-se@bar': {'uri': 'i18n://[email protected]#2', 'content': u'Bar'}
            })
Example #7
0
    def test_cache_encoding(self):
        cio.set(self.uri, u'epost')

        cached_node = cache.get(self.uri)
        content = cached_node['content']
        self.assertIsInstance(content, six.text_type)
        self.assertEqual(content, u'epost')

        cache.set('i18n://sv-se@label/email.txt#1', u'epost')
        nodes = cache.get_many((self.uri, self.uri))
        self.assertDictEqual(
            nodes, {
                self.uri: {
                    'uri': 'i18n://sv-se@label/email.txt#1',
                    'content': u'epost'
                }
            })
Example #8
0
    def test_cache_set(self):
        with self.assertRaises(URI.Invalid):
            cache.set('i18n://sv-se@foo', u'Bar')

        nodes = {
            'i18n://[email protected]#1': u'Foo',
            'i18n://[email protected]#2': u'Bar'
        }
        cache.set_many(nodes)

        with self.assertCache(calls=1, hits=2):
            result = cache.get_many(['i18n://sv-se@foo', 'i18n://sv-se@bar'])
            self.assertDictEqual(
                result, {
                    'i18n://sv-se@foo': {
                        'uri': 'i18n://[email protected]#1',
                        'content': u'Foo'
                    },
                    'i18n://sv-se@bar': {
                        'uri': 'i18n://[email protected]#2',
                        'content': u'Bar'
                    }
                })