Files
mayan-edms/mayan/apps/mirroring/tests/test_caches.py
Roberto Rosario 8e69178e07 Project: Switch to full app paths
Instead of inserting the path of the apps into the Python app,
the apps are now referenced by their full import path.

This app name claves with external or native Python libraries.
Example: Mayan statistics app vs. Python new statistics library.

Every app reference is now prepended with 'mayan.apps'.

Existing config.yml files need to be updated manually.

Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
2018-12-05 02:04:20 -04:00

72 lines
2.2 KiB
Python

from __future__ import absolute_import, unicode_literals
import warnings
from mayan.apps.common.tests import BaseTestCase
from ..caches import IndexFilesystemCache
from .literals import (
TEST_CACHE_KEY_BAD_CHARACTERS, TEST_DOCUMENT_PK, TEST_KEY_UNICODE,
TEST_KEY_UNICODE_HASH, TEST_NODE_PK, TEST_PATH,
)
class MockDocument(object):
pk = TEST_DOCUMENT_PK
class MockNode(object):
pk = TEST_NODE_PK
class IndexFilesystemCacheTestCase(BaseTestCase):
def setUp(self):
super(IndexFilesystemCacheTestCase, self).setUp()
self.cache = IndexFilesystemCache()
self.document = MockDocument()
self.node = MockNode()
def test_set_path_document(self):
self.cache.set_path(path=TEST_PATH, document=self.document)
self.assertEquals(
{'document_pk': TEST_DOCUMENT_PK},
self.cache.get_path(path=TEST_PATH)
)
def test_set_path_document_clear_document(self):
self.cache.set_path(path=TEST_PATH, document=self.document)
self.cache.clear_document(document=self.document)
self.assertEquals(None, self.cache.get_path(path=TEST_PATH))
def test_set_path_node(self):
self.cache.set_path(path=TEST_PATH, node=self.node)
self.assertEquals(
{'node_pk': TEST_NODE_PK},
self.cache.get_path(path=TEST_PATH)
)
def test_set_path_node_clear_node(self):
self.cache.set_path(path=TEST_PATH, node=self.node)
self.cache.clear_node(node=self.node)
self.assertEquals(None, self.cache.get_path(path=TEST_PATH))
def test_valid_cache_key_characters(self):
with warnings.catch_warnings(record=True) as warning_list:
self.cache.cache.validate_key(TEST_CACHE_KEY_BAD_CHARACTERS)
self.assertTrue(len(warning_list) == 1)
with warnings.catch_warnings(record=True) as warning_list:
self.cache.cache.validate_key(
self.cache.get_key_hash(key=TEST_CACHE_KEY_BAD_CHARACTERS)
)
self.assertTrue(len(warning_list) == 0)
def test_hash_non_ascii_key(self):
self.assertEqual(
self.cache.get_key_hash(key=TEST_KEY_UNICODE),
TEST_KEY_UNICODE_HASH
)