Mercurial > wikked
annotate tests/mock.py @ 439:debeff30d9bd
update: Do a reset if the DB requires an upgrade.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Mon, 17 Apr 2017 21:36:49 -0700 |
parents | 64acfb58e023 |
children | c78eaebced8b |
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) |
49 | 94 if not structure: |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
95 self.structure = {} |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
96 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
97 self.structure = MockFileSystem.flat_to_nested(structure) |
49 | 98 |
99 def getPageInfos(self, subdir=None): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
100 def tmp_walk(path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
101 node = self._getNode(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
102 return mock_os_walk(path, node) |
49 | 103 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
104 orig_walk = os.walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
105 os.walk = tmp_walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
106 try: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
107 gen = super(MockFileSystem, self).getPageInfos(subdir) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
108 return list(gen) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
109 finally: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
110 os.walk = orig_walk |
49 | 111 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
112 def setPage(self, url, content): |
51 | 113 raise NotImplementedError() |
49 | 114 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
115 def _getPageInfo(self, path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
116 pi = super(MockFileSystem, self)._getPageInfo(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
117 node = self._getNode(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
118 if node is not None: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
119 pi._content = node |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
120 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
121 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
|
122 return pi |
49 | 123 |
124 def _getNode(self, path): | |
125 node = self.structure | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
126 path = path.lstrip('/') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
127 if path != '': |
49 | 128 for n in path.split('/'): |
51 | 129 if n not in node: |
130 return None | |
49 | 131 node = node[n] |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
132 return node |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
133 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
134 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
|
135 def tmp_walk(path): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
136 node = self._getNode(path) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
137 return mock_os_walk(path, node) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
138 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
139 orig_walk = os.walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
140 os.walk = tmp_walk |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
141 try: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
142 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
|
143 make_new) |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
144 finally: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
145 os.walk = orig_walk |
49 | 146 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
147 @staticmethod |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
148 def flat_to_nested(flat): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
149 nested = {} |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
150 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
|
151 bits = k.lstrip('/').split('/') |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
152 cur = nested |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
153 for i, b in enumerate(bits): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
154 if i < len(bits) - 1: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
155 if b not in cur: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
156 cur[b] = {} |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
157 cur = cur[b] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
158 else: |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
159 cur[b] = v |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
160 return nested |
49 | 161 |
162 @staticmethod | |
163 def save_structure(path, structure): | |
164 if not os.path.isdir(path): | |
165 os.makedirs(path) | |
166 for node in structure: | |
167 node_path = os.path.join(path, node) | |
336
03e3e793fa22
Convert project to Python 3.4.
Ludovic Chabant <ludovic@chabant.com>
parents:
225
diff
changeset
|
168 if isinstance(structure[node], str): |
49 | 169 with codecs.open(node_path, 'w', encoding='utf-8') as f: |
170 f.write(structure[node]) | |
171 else: | |
172 MockFileSystem.save_structure(node_path, structure[node]) | |
173 | |
174 | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
175 class MockDatabase(Database): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
176 def __init__(self, content=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
177 super(MockDatabase, self).__init__() |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
178 self.content = content |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
179 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
180 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
|
181 return [] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
182 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
183 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
|
184 fields=None): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
185 return [] |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
186 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
187 def isCacheValid(self, page): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
188 return False |
49 | 189 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
190 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
|
191 return False |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
192 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
193 def getLinksTo(self, url): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
194 return [] |
49 | 195 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
196 def _getPageByUrl(self, url, fields): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
197 return None |
49 | 198 |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
199 def _getPageByPath(self, path, fields): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
200 return None |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
201 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
202 |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
203 class MockWikiIndex(WikiIndex): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
204 def __init__(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
205 super(MockWikiIndex, self).__init__() |
49 | 206 |
207 def search(self, query): | |
208 # url, title, content_highlights | |
209 return None | |
210 | |
211 | |
212 class MockSourceControl(SourceControl): | |
225
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
213 def __init__(self): |
ebb12ff21cb2
Updated unit tests to be able to run.
Ludovic Chabant <ludovic@chabant.com>
parents:
100
diff
changeset
|
214 super(MockSourceControl, self).__init__() |
49 | 215 |
216 def getSpecialFilenames(self): | |
217 return [] | |
218 | |
219 def getHistory(self, path=None): | |
220 return [] | |
221 | |
222 def getState(self, path): | |
223 raise NotImplementedError() | |
224 | |
225 def getRevision(self, path, rev): | |
226 raise NotImplementedError() | |
227 | |
228 def diff(self, path, rev1, rev2): | |
229 raise NotImplementedError() |