예제 #1
0
    def test_retrieve_io_exc_handling(self, mock_path_exists, mock_open):
        mock_path_exists.return_value = True
        mock_open.side_effect = IOError()

        store = FileSystemBackingStore(60)
        store.retrieve("get_templates")

        mock_path_exists.assert_called_once_with(self.cache_file_path)
예제 #2
0
    def test_cache_for_existing_root(self, mock_path_exists, mock_makedirs, mock_open):
        mock_path_exists.return_value = True
        mock_file_handle = mock_open.return_value.__enter__.return_value

        store = FileSystemBackingStore(60)
        store.cache("get_templates", {"foo": "bar"})

        self.assertFalse(mock_makedirs.called)
        mock_file_handle.write.assert_called_once_with("\x80\x02}q\x01U\x03fooq\x02U\x03barq\x03s.")
예제 #3
0
    def test_retrieve_for_existing_key(self, mock_path_exists, mock_open):
        mock_path_exists.return_value = True
        mock_file_handle = mock_open.return_value.__enter__.return_value
        mock_file_handle.read.return_value = "\x80\x02}q\x01U\x03fooq\x02U\x03barq\x03s."

        store = FileSystemBackingStore(60)
        result = store.retrieve("get_templates")
        self.assertDictEqual(result, {"foo": "bar"})

        mock_path_exists.assert_called_once_with(self.cache_file_path)
        self.assertTrue(mock_file_handle.read.called)
        mock_open.assert_called_once_with("/cache/.get_templates_cache", "r")
예제 #4
0
    def test_exists(self, mock_path_exists):
        mock_path_exists.return_value = True
        store = FileSystemBackingStore(60)

        self.assertTrue(store.exists("get_templates"))
        self.assertTrue(mock_path_exists.called)
예제 #5
0
    def test_cache_file_open_exc_handling(self, mock_path_exists, mock_open):
        mock_path_exists.return_value = True
        mock_open.side_effect = IOError()

        store = FileSystemBackingStore(60)
        store.cache("get_templates", {"foo": "bar"})
예제 #6
0
    def test_cache_create_root_exc_handling(self, mock_path_exists, mock_makedirs):
        mock_path_exists.return_value = False
        mock_makedirs.side_effect = IOError()

        store = FileSystemBackingStore(60)
        store.cache("get_templates", {"foo": "bar"})