Example #1
0
	def setUp(self):
		# Note that in this test our index is not the default index
		# for the notebook. So any assumption from the notebook about
		# the index will be wrong.
		self.index = Index(dbfile=':memory:')
		self.notebook = tests.get_test_notebook()
		self.index.set_notebook(self.notebook)
Example #2
0
	def runTest(self):
		'''Test search API'''
		query = Query('foo bar')
		self.assertEqual(query.root,
			AndGroup([('content', 'foo'), ('content', 'bar')]) )

		notebook = get_test_notebook()
		searcher = Searcher(notebook)
		result = searcher.search(query)
		self.assertTrue(isinstance(result, ResultsSelection))
		self.assertTrue(len(result.pages) > 0)
		#~ print result.pages
		self.assertTrue(Path('Test:foo') in result.pages)
		self.assertTrue(Path('Test:foo:bar') in result.pages)
		scores = [result.scores[p] for p in result.pages]
		self.assertTrue(all(scores))

		#~ print result.pages

		notebook.index.update()
		query = Query('LinksTo: "Linking:Foo:Bar"')
		self.assertEqual(query.root,
			AndGroup([('linksto', 'Linking:Foo:Bar')]) )
		result = searcher.search(query)
		self.assertTrue(isinstance(result, ResultsSelection))
		self.assertTrue(Path('Linking:Dus:Ja') in result.pages)
		scores = [result.scores[p] for p in result.pages]
		self.assertTrue(all(scores))
Example #3
0
	def runTest(self):
		notebook = get_test_notebook()
		notebook.get_store(Path(':')).dir = Dir('/source/dir/') # fake source dir

		linker = StaticLinker('html', notebook)
		linker.set_usebase(True) # normally set by html format module
		linker.set_path(Path('foo:bar')) # normally set by exporter
		linker.set_base(Dir('/source/dir/foo')) # normally set by exporter

		self.assertEqual(linker.page('+dus'), './bar/dus.html')
		self.assertEqual(linker.page('dus'), './dus.html')
		self.assertEqual(linker.file('./dus.pdf'), './bar/dus.pdf')
		self.assertEqual(linker.file('../dus.pdf'), './dus.pdf')
		self.assertEqual(linker.file('../../dus.pdf'), '../dus.pdf')
Example #4
0
	def runTest(self):
		'Test WWW interface'
		notebook = get_test_notebook()
		notebook.index.update()
		interface = WWWInterface(notebook, template=self.template)
		validator = wsgiref.validate.validator(interface)

		def call(command, path):
			environ = {
				'REQUEST_METHOD': command,
				'SCRIPT_NAME': '',
				'PATH_INFO': path,
				'QUERY_STRING': '',
				'SERVER_NAME': 'localhost',
				'SERVER_PORT': '80',
				'SERVER_PROTOCOL': '1.0'
			}
			rfile = StringIO('')
			wfile = StringIO()
			handler = wsgiref.handlers.SimpleHandler(rfile, wfile, sys.stderr, environ)
			handler.run(validator)
			#~ print '>>>>\n', wfile.getvalue(), '<<<<'
			return wfile.getvalue()

		# index
		for path in ('/', '/Test/'):
			response = call('HEAD', path)
			self.assertResponseOK(response, expectbody=False)
			response = call('GET', path)
			#~ print '>'*80, '\n', response, '<'*80
			self.assertResponseOK(response)
			self.assertTrue('<li><a href="/Test/foo.html" title="foo">foo</a></li>' in response)

		# page
		response = call('GET', '/Test/foo.html')
		self.assertResponseOK(response)
		self.assertTrue('<h1>Foo</h1>' in response)

		# page not found

		with Filter404():
			for path in ('/Test', '/nonexistingpage.html', '/nonexisting/'):
				response = call('GET', path)
				header, body = self.assertResponseWellFormed(response)
				self.assertEqual(header[0], 'HTTP/1.0 404 Not Found')

		# favicon
		response = call('GET', '/favicon.ico')
		header, body = self.assertResponseWellFormed(response)
		self.assertEqual(header[0], 'HTTP/1.0 200 OK')
Example #5
0
	def __init__(self):
		self.notebook = tests.get_test_notebook()
		self.page = self.notebook.get_page(Path('Test:foo'))
		self.preferences = ConfigDict()
Example #6
0
	def export(self):
		notebook = get_test_notebook()
		notebook.get_store(Path(':')).dir = Dir('/foo/bar') # fake source dir
		notebook.index.update()
		exporter = Exporter(notebook, **self.options)
		exporter.export_all(self.dir)
Example #7
0
	def setUp(self):
		zim.history.MAX_HISTORY = 100
		self.notebook = get_test_notebook()
		self.pages = [self.notebook.get_page(Path(name))
			for name in self.notebook.testdata_manifest]
Example #8
0
	def setUp(self):
		self.notebook = tests.get_test_notebook()
Example #9
0
	def setUp(self):
		zim.errors.silence_signal_exception_context = True
		if not hasattr(self, 'notebook'):
			self.notebook = tests.get_test_notebook()
			self.notebook.index.update()
Example #10
0
	def setUp(self):
		self.index = Index(dbfile=':memory:')
		self.notebook = tests.get_test_notebook()
		self.index.set_notebook(self.notebook)