/usr/share/pyshared/couchdb/tests/view.py is in python-couchdb 0.8-0ubuntu2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 | # -*- coding: utf-8 -*-
#
# Copyright (C) 2007-2008 Christopher Lenz
# All rights reserved.
#
# This software is licensed as described in the file COPYING, which
# you should have received as part of this distribution.
import doctest
from StringIO import StringIO
import unittest
from couchdb import view
class ViewServerTestCase(unittest.TestCase):
def test_reset(self):
input = StringIO('["reset"]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEquals(output.getvalue(), 'true\n')
def test_add_fun(self):
input = StringIO('["add_fun", "def fun(doc): yield None, doc"]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEquals(output.getvalue(), 'true\n')
def test_map_doc(self):
input = StringIO('["add_fun", "def fun(doc): yield None, doc"]\n'
'["map_doc", {"foo": "bar"}]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(),
'true\n'
'[[[null, {"foo": "bar"}]]]\n')
def test_i18n(self):
input = StringIO('["add_fun", "def fun(doc): yield doc[\\"test\\"], doc"]\n'
'["map_doc", {"test": "b\xc3\xa5r"}]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(),
'true\n'
'[[["b\xc3\xa5r", {"test": "b\xc3\xa5r"}]]]\n')
def test_map_doc_with_logging(self):
fun = 'def fun(doc): log(\'running\'); yield None, doc'
input = StringIO('["add_fun", "%s"]\n'
'["map_doc", {"foo": "bar"}]\n' % fun)
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(),
'true\n'
'{"log": "running"}\n'
'[[[null, {"foo": "bar"}]]]\n')
def test_map_doc_with_logging_json(self):
fun = 'def fun(doc): log([1, 2, 3]); yield None, doc'
input = StringIO('["add_fun", "%s"]\n'
'["map_doc", {"foo": "bar"}]\n' % fun)
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(),
'true\n'
'{"log": "[1, 2, 3]"}\n'
'[[[null, {"foo": "bar"}]]]\n')
def test_reduce(self):
input = StringIO('["reduce", '
'["def fun(keys, values): return sum(values)"], '
'[[null, 1], [null, 2], [null, 3]]]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(), '[true, [6]]\n')
def test_reduce_with_logging(self):
input = StringIO('["reduce", '
'["def fun(keys, values): log(\'Summing %r\' % (values,)); return sum(values)"], '
'[[null, 1], [null, 2], [null, 3]]]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(),
'{"log": "Summing (1, 2, 3)"}\n'
'[true, [6]]\n')
def test_rereduce(self):
input = StringIO('["rereduce", '
'["def fun(keys, values, rereduce): return sum(values)"], '
'[1, 2, 3]]\n')
output = StringIO()
view.run(input=input, output=output)
self.assertEqual(output.getvalue(), '[true, [6]]\n')
def suite():
suite = unittest.TestSuite()
suite.addTest(doctest.DocTestSuite(view))
suite.addTest(unittest.makeSuite(ViewServerTestCase, 'test'))
return suite
if __name__ == '__main__':
unittest.main(defaultTest='suite')
|