Skip to content

Commit e8eab1f

Browse files
geppettodivacindjc
authored andcommitted
Fix logging response in query server (#321)
Documentation can be found at http://docs.couchdb.org/en/2.0.0/query-server/protocol.html * Fix logging tests to have correct format.
1 parent 438a392 commit e8eab1f

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

couchdb/tests/view.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def test_map_doc_with_logging(self):
5353
view.run(input=input, output=output)
5454
self.assertEqual(output.getvalue(),
5555
b'true\n'
56-
b'{"log": "running"}\n'
56+
b'["log", "running"]\n'
5757
b'[[[null, {"foo": "bar"}]]]\n')
5858

5959
def test_map_doc_with_logging_json(self):
@@ -64,7 +64,7 @@ def test_map_doc_with_logging_json(self):
6464
view.run(input=input, output=output)
6565
self.assertEqual(output.getvalue(),
6666
b'true\n'
67-
b'{"log": "[1, 2, 3]"}\n'
67+
b'["log", "[1, 2, 3]"]\n'
6868
b'[[[null, {"foo": "bar"}]]]\n')
6969

7070
def test_reduce(self):
@@ -82,7 +82,7 @@ def test_reduce_with_logging(self):
8282
output = StringIO()
8383
view.run(input=input, output=output)
8484
self.assertEqual(output.getvalue(),
85-
b'{"log": "Summing (1, 2, 3)"}\n'
85+
b'["log", "Summing (1, 2, 3)"]\n'
8686
b'[true, [6]]\n')
8787

8888
def test_rereduce(self):

couchdb/view.py

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def _writejson(obj):
4545
def _log(message):
4646
if not isinstance(message, util.strbase):
4747
message = json.encode(message)
48-
_writejson({'log': message})
48+
_writejson(['log', message])
4949

5050
def reset(config=None):
5151
del functions[:]
@@ -57,15 +57,15 @@ def add_fun(string):
5757
try:
5858
util.pyexec(string, {'log': _log}, globals_)
5959
except Exception as e:
60-
return {'error': {
61-
'id': 'map_compilation_error',
62-
'reason': e.args[0]
63-
}}
64-
err = {'error': {
65-
'id': 'map_compilation_error',
66-
'reason': 'string must eval to a function '
60+
return ['error',
61+
'map_compilation_error',
62+
e.args[0]
63+
]
64+
err = ['error',
65+
'map_compilation_error',
66+
'string must eval to a function '
6767
'(ex: "def(doc): return 1")'
68-
}}
68+
]
6969
if len(globals_) != 1:
7070
return err
7171
function = list(globals_.values())[0]
@@ -95,15 +95,15 @@ def reduce(*cmd, **kwargs):
9595
except Exception as e:
9696
log.error('runtime error in reduce function: %s', e,
9797
exc_info=True)
98-
return {'error': {
99-
'id': 'reduce_compilation_error',
100-
'reason': e.args[0]
101-
}}
102-
err = {'error': {
103-
'id': 'reduce_compilation_error',
104-
'reason': 'string must eval to a function '
98+
return ['error',
99+
'reduce_compilation_error',
100+
e.args[0]
101+
]
102+
err = ['error',
103+
'reduce_compilation_error',
104+
'string must eval to a function '
105105
'(ex: "def(keys, values): return 1")'
106-
}}
106+
]
107107
if len(globals_) != 1:
108108
return err
109109
function = list(globals_.values())[0]

0 commit comments

Comments
 (0)