コード例 #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_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")