def testResolveUserInput(self): db = new_test_database() pages = PagesView(db) # cleaning absolute paths for name, wanted in ( ('foo:::bar', 'Foo:bar'), # "Foo" exists, so "foo" gets capital ('::foo:bar:', 'Foo:bar'), (':foo', 'Foo'), ('/foo', 'Foo'), (':Bar', 'Bar'), (':Foo (Bar)', 'Foo (Bar)'), ('non-existing-page', 'non-existing-page'), # TODO more ambigous test cases ): self.assertEqual(pages.lookup_from_user_input(name), Path(wanted)) # resolving relative paths for name, ns, wanted in ( ('foo:test', 'Foo:Child1', 'Foo:test'), ('foo:test', 'Bar', 'Foo:test'), ('test', 'Foo:Child1', 'Foo:test'), ('+test', 'Foo:Child1', 'Foo:Child1:test'), ): self.assertEqual(pages.lookup_from_user_input(name, Path(ns)), Path(wanted)) self.assertRaises(ValueError, pages.lookup_from_user_input, ':::')
def testResolveLink(self): db = new_test_database() pages = PagesView(db) for sourcename, link, target in ( ('Foo:Child1:GrandChild1', 'Child1', 'Foo:Child1'), ('Foo:Child1:GrandChild1', 'Child2:AAA', 'Foo:Child2:AAA'), ('Foo:Child1:GrandChild1', 'AAA', 'Foo:Child1:AAA'), ('Foo:Child1:GrandChild1', '+AAA', 'Foo:Child1:GrandChild1:AAA'), ('Foo:Child1:GrandChild1', ':AAA', 'AAA'), # TODO more examples #~ ('Foo:Bar', 'Bar', 'Foo:Bar'), #~ ('Foo:Bar', '+Baz', 'Foo:Bar:Baz'), #~ ('Foo:Bar:Baz', 'Foo:Dus', 'Foo:Dus'), #~ ('Foo:Bar:Baz', 'Dus', 'Foo:Bar:Dus'), #~ ('Foo:Bar', 'Dus:Ja', 'Dus:Ja'), #~ ('Foo:Bar', 'Ja', 'Foo:Ja'), #~ ('Foo:Bar:Baz', 'Bar', 'Foo:Bar'), #~ ('Foo:Bar:Baz', 'Foo', 'Foo'), #~ ('Foo:Bar:Baz', ':Bar', 'Bar'), # conflict with anchor ): source = Path(sourcename) href = HRef.new_from_wiki_link(link) path = pages.resolve_link(source, href) self.assertEqual(path.name, target) newhref = pages.create_link(source, path) self.assertEqual(newhref.rel, href.rel) self.assertEqual(newhref.names, href.names)
def testRecentChanges(self): db = new_test_database() pages = PagesView(db) pageset = set(pages.walk()) recent = set(pages.list_recent_changes()) self.assertEqual(recent, pageset) recent = set(pages.list_recent_changes(limit=3, offset=0)) self.assertEqual(len(recent), 3)
def testBasics(self): db = new_test_database() pages = PagesView(db) toplevel = [p.name for p in pages.list_pages(Path(':'))] self.assertIn('Bar', toplevel) self.assertIn('Foo', toplevel) for name in toplevel: path = Path(name) userpath = pages.lookup_from_user_input(name) self.assertEqual(path, userpath)
def testWalk(self): db = new_test_database() pages = PagesView(db) names = [p.name for p in pages.walk()] self.assertIn('Bar', names) self.assertIn('Foo', names) self.assertIn('Foo:Child1:GrandChild1', names) self.assertNotIn('', names) self.assertEqual(len(names), pages.n_all_pages()) last = len(names) - 1 for i, name in enumerate(names): p = pages.get_previous(Path(name)) if i > 0: self.assertIsNotNone(p, 'Missing prev for %s' % name) self.assertEqual(p.name, names[i - 1]) else: self.assertIsNone(p) n = pages.get_next(Path(name)) if i < last: self.assertIsNotNone(n, 'Missing next for %s' % name) self.assertEqual(n.name, names[i + 1]) else: self.assertIsNone(n) section = Path('Foo') for page in pages.walk(section): self.assertTrue(page.ischild(section))
def testPreviousAndNext(self): # Mix of caps and small letters to trigger issues with sorting names = ('AAA', 'BBB', 'ccc', 'ddd', 'EEE', 'FFF', 'ggg', 'hhh') db = new_test_database((name + '.txt', 'Test 123\n') for name in names) pages = PagesView(db) last = len(names) - 1 for i, name in enumerate(names): p = pages.get_previous(Path(name)) if i > 0: self.assertIsNotNone(p, 'Missing prev for %s' % name) self.assertEqual(p.name, names[i - 1]) else: self.assertIsNone(p) n = pages.get_next(Path(name)) if i < last: self.assertIsNotNone(n, 'Missing next for %s' % name) self.assertEqual(n.name, names[i + 1]) else: self.assertIsNone(n)