Exemplo n.º 1
0
 def test_update_wrong_method(self):
     import json
     request = {
         'method': 'GET',
         'query': {},
         'body': '',
     }
     commands = [
         self.command_ddoc_add(),
         [
             'ddoc',
             '_design/test_update',
             ['updates', 'inc'],
             [None, request]
         ],
     ]
     input = StringIO(b'\n'.join(json.dumps(c).encode('utf-8')
                                 for c in commands))
     output = StringIO()
     view.run(input=input, output=output)
     results = [
         json.loads(l.decode('utf-8'))
         for l in output.getvalue().strip().split(b'\n')
     ]
     self.assertEqual(len(results), 2)
     self.assertEqual(results[1][2]['status'], 405)
Exemplo n.º 2
0
 def test_rereduce(self):
     input = StringIO(b'["rereduce", '
                       b'["def fun(keys, values, rereduce): return sum(values)"], '
                       b'[1, 2, 3]]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(), b'[true, [6]]\n')
Exemplo n.º 3
0
 def test_i18n(self):
     input = StringIO(b'["add_fun", "def fun(doc): yield doc[\\"test\\"], doc"]\n'
                      b'["map_doc", {"test": "b\xc3\xa5r"}]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(),
                      b'true\n'
                      b'[[["b\xc3\xa5r", {"test": "b\xc3\xa5r"}]]]\n')
Exemplo n.º 4
0
 def test_map_doc(self):
     input = StringIO(b'["add_fun", "def fun(doc): yield None, doc"]\n'
                      b'["map_doc", {"foo": "bar"}]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(),
                      b'true\n'
                      b'[[[null, {"foo": "bar"}]]]\n')
Exemplo n.º 5
0
 def test_reduce_with_logging(self):
     input = StringIO(b'["reduce", '
                       b'["def fun(keys, values): log(\'Summing %r\' % (values,)); return sum(values)"], '
                       b'[[null, 1], [null, 2], [null, 3]]]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(),
                      b'{"log": "Summing (1, 2, 3)"}\n'
                      b'[true, [6]]\n')
Exemplo n.º 6
0
 def test_map_doc_with_logging_json(self):
     fun = b'def fun(doc): log([1, 2, 3]); yield None, doc'
     input = StringIO(b'["add_fun", "' + fun + b'"]\n'
                      b'["map_doc", {"foo": "bar"}]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(),
                      b'true\n'
                      b'{"log": "[1, 2, 3]"}\n'
                      b'[[[null, {"foo": "bar"}]]]\n')
Exemplo n.º 7
0
    def test_unicode_content(self):
        buf = StringIO()
        envelope = multipart.write_multipart(buf, boundary='==123456789==')
        envelope.add('text/plain', u'Iñtërnâtiônàlizætiøn')
        envelope.close()
        self.assertEqual(u'''Content-Type: multipart/mixed; boundary="==123456789=="

--==123456789==
Content-Length: 27
Content-MD5: 5eYoIG5zsa5ps3/Gl2Kh4Q==
Content-Type: text/plain;charset=utf-8

Iñtërnâtiônàlizætiøn
--==123456789==--
'''.encode('utf-8'), buf.getvalue().replace(b'\r\n', b'\n'))
Exemplo n.º 8
0
    def test_unicode_content(self):
        buf = StringIO()
        envelope = multipart.write_multipart(buf, boundary='==123456789==')
        envelope.add('text/plain', u'Iñtërnâtiônàlizætiøn')
        envelope.close()
        self.assertEqual(
            u'''Content-Type: multipart/mixed; boundary="==123456789=="

--==123456789==
Content-Length: 27
Content-MD5: 5eYoIG5zsa5ps3/Gl2Kh4Q==
Content-Type: text/plain;charset=utf-8

Iñtërnâtiônàlizætiøn
--==123456789==--
'''.encode('utf-8'),
            buf.getvalue().replace(b'\r\n', b'\n'))
Exemplo n.º 9
0
    def test_unicode_headers_charset(self):
        # http://code.google.com/p/couchdb-python/issues/detail?id=179
        buf = StringIO()
        envelope = multipart.write_multipart(buf, boundary='==123456789==')
        envelope.add('application/json;charset=utf-8',
                     '{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09",'
                     ' "_id": "文档"}',
                     headers={'Content-ID': u"文档"})
        self.assertEqual(u'''Content-Type: multipart/mixed; boundary="==123456789=="

--==123456789==
Content-ID: =?utf-8?b?5paH5qGj?=
Content-Length: 63
Content-MD5: Cpw3iC3xPua8YzKeWLzwvw==
Content-Type: application/json;charset=utf-8

{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
'''.encode('utf-8'), buf.getvalue().replace(b'\r\n', b'\n'))
Exemplo n.º 10
0
    def test_unicode_content(self):
        buf = StringIO()
        envelope = multipart.write_multipart(buf, boundary="==123456789==")
        envelope.add("text/plain", u"Iñtërnâtiônàlizætiøn")
        envelope.close()
        self.assertEqual(
            u"""Content-Type: multipart/mixed; boundary="==123456789=="

--==123456789==
Content-Length: 27
Content-MD5: 5eYoIG5zsa5ps3/Gl2Kh4Q==
Content-Type: text/plain;charset=utf-8

Iñtërnâtiônàlizætiøn
--==123456789==--
""".encode(
                "utf-8"
            ),
            buf.getvalue().replace(b"\r\n", b"\n"),
        )
Exemplo n.º 11
0
    def test_unicode_headers(self):
        # http://code.google.com/p/couchdb-python/issues/detail?id=179
        buf = StringIO()
        envelope = multipart.write_multipart(buf, boundary='==123456789==')
        envelope.add('application/json',
                     '{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09",'
                     ' "_id": "文档"}',
                     headers={'Content-ID': u"文档"})
        self.assertEqual(
            u'''Content-Type: multipart/mixed; boundary="==123456789=="

--==123456789==
Content-ID: =?utf-8?b?5paH5qGj?=
Content-Length: 63
Content-MD5: Cpw3iC3xPua8YzKeWLzwvw==
Content-Type: application/json;charset=utf-8

{"_rev": "3-bc27b6930ca514527d8954c7c43e6a09", "_id": "文档"}
'''.encode('utf-8'),
            buf.getvalue().replace(b'\r\n', b'\n'))
Exemplo n.º 12
0
 def test_update(self):
     import json
     request = {
         'method': 'POST',
         'query': {},
         'body': '',
     }
     commands = [
         self.command_ddoc_add(),
         [
             'ddoc',
             '_design/test_update',
             ['updates', 'inc'],
             [None, request]
         ],
         [
             'ddoc',
             '_design/test_update',
             ['updates', 'inc'],
             [{'field': 41, 'other_field': 'x'}, request]
         ],
     ]
     input = StringIO(b'\n'.join(json.dumps(c).encode('utf-8')
                                 for c in commands))
     output = StringIO()
     view.run(input=input, output=output)
     results = [
         json.loads(l.decode('utf-8'))
         for l in output.getvalue().strip().split(b'\n')
     ]
     self.assertEqual(len(results), 3)
     self.assertEqual(results[0], True)
     self.assertEqual(results[1], ['up', None, {'body': '.'}])
     self.assertEqual(
         results[2],
         ['up', {'field': 42, 'other_field': 'x'}, {'body': '.'}])
Exemplo n.º 13
0
 def test_add_fun(self):
     input = StringIO(b'["add_fun", "def fun(doc): yield None, doc"]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(), b'true\n')
Exemplo n.º 14
0
 def test_reset(self):
     input = StringIO(b'["reset"]\n')
     output = StringIO()
     view.run(input=input, output=output)
     self.assertEqual(output.getvalue(), b'true\n')