0001-utils-capture-and-log-phantomjs-stderr-32773.patch
mandayejs/mandaye/utils.py | ||
---|---|---|
37 | 37 |
os.path.join(settings.BASE_DIR, 'mandayejs', script)], |
38 | 38 |
close_fds=True, |
39 | 39 |
stdin=subprocess.PIPE, |
40 |
stdout=subprocess.PIPE |
|
40 |
stdout=subprocess.PIPE, |
|
41 |
stderr=subprocess.PIPE |
|
41 | 42 |
) |
42 | 43 |
stdout, stderr = phantom.communicate(json.dumps(data)) |
43 | 44 | |
... | ... | |
49 | 50 |
result = json.loads(stdout) |
50 | 51 |
except (ValueError,): |
51 | 52 |
result = {"result": "json_error"} |
52 |
logger.error("invalid json: %s" % stdout)
|
|
53 |
logger.error("invalid json: %s (stderr: %s)", stdout, stderr)
|
|
53 | 54 | |
54 | 55 |
if result.get('stderr'): |
55 | 56 |
logger.warning(result['stderr']) |
tests/test_mandayejs.py | ||
---|---|---|
100 | 100 |
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen') |
101 | 101 |
@mock.patch('mandayejs.applications.Test.SITE_LOCATORS', MOCKED_SITE_LOCATORS) |
102 | 102 |
def test_phantom_invalid_json(mocked_popen, caplog, user_john): |
103 |
expected_output = ('This is not a valid JSON', None)
|
|
103 |
expected_output = ('This is not a valid JSON', 'msg on stderr')
|
|
104 | 104 |
mocked_popen.return_value = MockedPopen(expected_output=expected_output) |
105 | 105 | |
106 | 106 |
UserCredentials.objects.create(user=user_john, |
... | ... | |
119 | 119 | |
120 | 120 |
for record in caplog.records: |
121 | 121 |
if record.levelname == 'ERROR': |
122 |
assert record.message == 'invalid json: This is not a valid JSON' |
|
122 |
assert record.message == 'invalid json: This is not a valid JSON (stderr: msg on stderr)'
|
|
123 | 123 | |
124 | 124 | |
125 | 125 |
@mock.patch('mandayejs.mandaye.utils.subprocess.Popen') |
126 |
- |