Mercurial > wikked
comparison tests/mock.py @ 100:fd6eccb24882
Refactoring to get rid of `slugify` callbacks.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sat, 25 May 2013 22:35:23 -0700 |
parents | 9afe4a1dbd1e |
children | ebb12ff21cb2 |
comparison
equal
deleted
inserted
replaced
99:58a1a7baca25 | 100:fd6eccb24882 |
---|---|
7 from wikked.page import Page | 7 from wikked.page import Page |
8 from wikked.fs import PageInfo, PageNotFoundError | 8 from wikked.fs import PageInfo, PageNotFoundError |
9 from wikked.db import Database | 9 from wikked.db import Database |
10 from wikked.indexer import WikiIndex | 10 from wikked.indexer import WikiIndex |
11 from wikked.scm import SourceControl | 11 from wikked.scm import SourceControl |
12 from wikked.utils import title_to_url | |
12 | 13 |
13 | 14 |
14 class MockWikiParameters(object): | 15 class MockWikiParameters(object): |
15 def __init__(self): | 16 def __init__(self): |
16 self.formatters = { | 17 self.formatters = { |
84 def getLinksTo(self, url): | 85 def getLinksTo(self, url): |
85 return [] | 86 return [] |
86 | 87 |
87 | 88 |
88 class MockFileSystem(): | 89 class MockFileSystem(): |
89 def __init__(self, structure=None, slugify=Page.title_to_url, logger=None): | 90 def __init__(self, structure=None, logger=None): |
90 if not structure: | 91 if not structure: |
91 structure = [] | 92 structure = [] |
92 if not slugify: | |
93 slugify = lambda x: x | |
94 self.structure = structure | 93 self.structure = structure |
95 self.slugify = slugify | |
96 self.logger = logger | 94 self.logger = logger |
97 self.excluded = [] | 95 self.excluded = [] |
98 | 96 |
99 def getPageInfos(self, subdir=None): | 97 def getPageInfos(self, subdir=None): |
100 node = self._getNode(subdir) | 98 node = self._getNode(subdir) |
129 def getPhysicalNamespacePath(self, url): | 127 def getPhysicalNamespacePath(self, url): |
130 raise NotImplementedError() | 128 raise NotImplementedError() |
131 | 129 |
132 def _getPageInfo(self, node, with_content=False): | 130 def _getPageInfo(self, node, with_content=False): |
133 path_split = os.path.splitext(node['path']) | 131 path_split = os.path.splitext(node['path']) |
134 url = self.slugify(path_split[0]) | 132 url = title_to_url(path_split[0]) |
135 info = PageInfo(url, node['path']) | 133 info = PageInfo(url, node['path']) |
136 if with_content: | 134 if with_content: |
137 info.content = node['content'] | 135 info.content = node['content'] |
138 return info | 136 return info |
139 | 137 |
174 path = '' | 172 path = '' |
175 current = self.structure | 173 current = self.structure |
176 parts = unicode(url).lower().split('/') | 174 parts = unicode(url).lower().split('/') |
177 for i, part in enumerate(parts): | 175 for i, part in enumerate(parts): |
178 for name in current: | 176 for name in current: |
179 name_slug = self.slugify(name) | 177 name_slug = title_to_url(name) |
180 if is_file and i == len(parts) - 1: | 178 if is_file and i == len(parts) - 1: |
181 if re.match(r"%s\.[a-z]+" % re.escape(part), name_slug): | 179 if re.match(r"%s\.[a-z]+" % re.escape(part), name_slug): |
182 current = current[name] | 180 current = current[name] |
183 path = os.path.join(path, name) | 181 path = os.path.join(path, name) |
184 break | 182 break |