Mercurial > wikked
annotate tests/mock.py @ 457:038b22935250
web: Fix the special pages (based on lists).
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Wed, 10 Jan 2018 22:51:39 -0800 |
parents | c78eaebced8b |
children | 2027ab79f006 |
rev | line source |
---|---|
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
1 import os |
49 | 2 import os.path |
3 import codecs | |
4 import logging | |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
5 import io |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
6 from collections import deque |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
7 from contextlib import closing |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
8 from configparser import SafeConfigParser |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
9 from wikked.fs import FileSystem |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
10 from wikked.db.base import Database |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
11 from wikked.indexer.base import WikiIndex |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
12 from wikked.scm.base import SourceControl |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
13 from wikked.wiki import WikiParameters, passthrough_formatter |
49 | 14 |
15 | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
16 logger = logging.getLogger(__name__) |
49 | 17 |
18 | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
19 class MockWikiParameters(WikiParameters): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
20 def __init__(self, root=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
21 super(MockWikiParameters, self).__init__(root) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
22 self.config_text = "" |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
23 self.mock_fs = None |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
24 self.mock_index = None |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
25 self.mock_db = None |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
26 self.mock_scm = None |
49 | 27 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
28 def fs_factory(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
29 if self.mock_fs is False: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
30 return super(MockWikiParameters, self).fs_factory() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
31 return self.mock_fs or MockFileSystem(self.root, self.config) |
49 | 32 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
33 def index_factory(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
34 if self.mock_index is False: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
35 return super(MockWikiParameters, self).index_factory() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
36 return self.mock_index or MockWikiIndex() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
37 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
38 def db_factory(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
39 if self.mock_db is False: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
40 return super(MockWikiParameters, self).db_factory() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
41 return self.mock_db or MockDatabase() |
49 | 42 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
43 def scm_factory(self, for_init=False): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
44 if self.mock_scm is False: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
45 return super(MockWikiParameters, self).scm_factory(for_init) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
46 return self.mock_scm or MockSourceControl() |
49 | 47 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
48 def getFormatters(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
49 formatters = { |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
50 passthrough_formatter: ['txt', 'html'] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
51 } |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
52 return formatters |
49 | 53 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
54 def getPageUpdater(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
55 return lambda wiki, url: wiki.update(url, cache_ext_data=True) |
49 | 56 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
57 def _loadConfig(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
58 default_config_path = os.path.join( |
339
64acfb58e023
Cleanup import and code.
Ludovic Chabant <ludovic@chabant.com>
parents:
336
diff
changeset
|
59 os.path.dirname(__file__), '..', |
64acfb58e023
Cleanup import and code.
Ludovic Chabant <ludovic@chabant.com>
parents:
336
diff
changeset
|
60 'wikked', 'resources', 'defaults.cfg') |
49 | 61 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
62 config = SafeConfigParser() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
63 config.readfp(open(default_config_path)) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
64 config.set('wiki', 'root', '/fake/root') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
65 if self.config_text: |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
66 with closing(io.StringIO(self.config_text)) as conf: |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
67 config.readfp(conf) |
49 | 68 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
69 return config |
49 | 70 |
71 | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
72 def mock_os_walk(root_dir, root_node): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
73 queue = deque() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
74 queue.appendleft((root_dir, root_node)) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
75 while len(queue) > 0: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
76 cur_dir, cur_node = queue.pop() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
77 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
78 dirnames = [] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
79 filenames = [] |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
80 for name, child in cur_node.items(): |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
81 if isinstance(child, dict): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
82 dirnames.append(name) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
83 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
84 filenames.append(name) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
85 yield cur_dir, dirnames, filenames |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
86 for name in dirnames: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
87 fullname = os.path.join(cur_dir, name) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
88 queue.appendleft((fullname, cur_node[name])) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
89 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
90 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
91 class MockFileSystem(FileSystem): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
92 def __init__(self, root, config, structure=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
93 super(MockFileSystem, self).__init__(root, config) |
448
c78eaebced8b
fs: Add support for builtin namespaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
339
diff
changeset
|
94 self.include_builtin_namespaces = False |
49 | 95 if not structure: |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
96 self.structure = {} |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
97 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
98 self.structure = MockFileSystem.flat_to_nested(structure) |
49 | 99 |
100 def getPageInfos(self, subdir=None): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
101 def tmp_walk(path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
102 node = self._getNode(path) |
448
c78eaebced8b
fs: Add support for builtin namespaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
339
diff
changeset
|
103 if node is None: |
c78eaebced8b
fs: Add support for builtin namespaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
339
diff
changeset
|
104 raise Exception("No node at %s" % path) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
105 return mock_os_walk(path, node) |
49 | 106 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
107 orig_walk = os.walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
108 os.walk = tmp_walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
109 try: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
110 gen = super(MockFileSystem, self).getPageInfos(subdir) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
111 return list(gen) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
112 finally: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
113 os.walk = orig_walk |
49 | 114 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
115 def setPage(self, url, content): |
51 | 116 raise NotImplementedError() |
49 | 117 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
118 def _getPageInfo(self, path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
119 pi = super(MockFileSystem, self)._getPageInfo(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
120 node = self._getNode(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
121 if node is not None: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
122 pi._content = node |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
123 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
124 raise Exception("Can't find node: %s" % path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
125 return pi |
49 | 126 |
127 def _getNode(self, path): | |
128 node = self.structure | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
129 path = path.lstrip('/') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
130 if path != '': |
49 | 131 for n in path.split('/'): |
51 | 132 if n not in node: |
133 return None | |
49 | 134 node = node[n] |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
135 return node |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
136 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
137 def _getPhysicalPath(self, url, is_file=True, make_new=False): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
138 def tmp_walk(path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
139 node = self._getNode(path) |
448
c78eaebced8b
fs: Add support for builtin namespaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
339
diff
changeset
|
140 if node is None: |
c78eaebced8b
fs: Add support for builtin namespaces.
Ludovic Chabant <ludovic@chabant.com>
parents:
339
diff
changeset
|
141 raise Exception("No node at %s" % path) |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
142 return mock_os_walk(path, node) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
143 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
144 orig_walk = os.walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
145 os.walk = tmp_walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
146 try: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
147 return super(MockFileSystem, self)._getPhysicalPath(url, is_file, |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
148 make_new) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
149 finally: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
150 os.walk = orig_walk |
49 | 151 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
152 @staticmethod |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
153 def flat_to_nested(flat): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
154 nested = {} |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
155 for k, v in flat.items(): |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
156 bits = k.lstrip('/').split('/') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
157 cur = nested |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
158 for i, b in enumerate(bits): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
159 if i < len(bits) - 1: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
160 if b not in cur: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
161 cur[b] = {} |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
162 cur = cur[b] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
163 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
164 cur[b] = v |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
165 return nested |
49 | 166 |
167 @staticmethod | |
168 def save_structure(path, structure): | |
169 if not os.path.isdir(path): | |
170 os.makedirs(path) | |
171 for node in structure: | |
172 node_path = os.path.join(path, node) | |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
173 if isinstance(structure[node], str): |
49 | 174 with codecs.open(node_path, 'w', encoding='utf-8') as f: |
175 f.write(structure[node]) | |
176 else: | |
177 MockFileSystem.save_structure(node_path, structure[node]) | |
178 | |
179 | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
180 class MockDatabase(Database): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
181 def __init__(self, content=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
182 super(MockDatabase, self).__init__() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
183 self.content = content |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
184 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
185 def getPageUrls(self, subdir=None, uncached_only=False): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
186 return [] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
187 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
188 def getPages(self, subdir=None, meta_query=None, uncached_only=False, |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
189 fields=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
190 return [] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
191 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
192 def isCacheValid(self, page): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
193 return False |
49 | 194 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
195 def pageExists(self, url=None, path=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
196 return False |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
197 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
198 def getLinksTo(self, url): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
199 return [] |
49 | 200 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
201 def _getPageByUrl(self, url, fields): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
202 return None |
49 | 203 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
204 def _getPageByPath(self, path, fields): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
205 return None |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
206 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
207 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
208 class MockWikiIndex(WikiIndex): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
209 def __init__(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
210 super(MockWikiIndex, self).__init__() |
49 | 211 |
212 def search(self, query): | |
213 # url, title, content_highlights | |
214 return None | |
215 | |
216 | |
217 class MockSourceControl(SourceControl): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
218 def __init__(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
219 super(MockSourceControl, self).__init__() |
49 | 220 |
221 def getSpecialFilenames(self): | |
222 return [] | |
223 | |
224 def getHistory(self, path=None): | |
225 return [] | |
226 | |
227 def getState(self, path): | |
228 raise NotImplementedError() | |
229 | |
230 def getRevision(self, path, rev): | |
231 raise NotImplementedError() | |
232 | |
233 def diff(self, path, rev1, rev2): | |
234 raise NotImplementedError() |