From 67c2e3ce3c66b6b3e828e4630f6148b5e280b2aa Mon Sep 17 00:00:00 2001 From: Strahinja Val Markovic Date: Tue, 18 Nov 2014 13:41:42 -0800 Subject: [PATCH] Ensuring /event_notification always returns JSON Empty string is not valid JSON. Fixes #51. --- ycmd/handlers.py | 1 + ycmd/tests/diagnostics_test.py | 4 ++-- ycmd/tests/misc_handlers_test.py | 9 +++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/ycmd/handlers.py b/ycmd/handlers.py index ea71ee8989..a8cbd2ec82 100644 --- a/ycmd/handlers.py +++ b/ycmd/handlers.py @@ -71,6 +71,7 @@ def EventNotification(): if response_data: return _JsonResponse( response_data ) + return _JsonResponse( {} ) @app.post( '/run_completer_command' ) diff --git a/ycmd/tests/diagnostics_test.py b/ycmd/tests/diagnostics_test.py index 433344e1b3..cfc951df25 100644 --- a/ycmd/tests/diagnostics_test.py +++ b/ycmd/tests/diagnostics_test.py @@ -134,8 +134,8 @@ def Diagnostics_ClangCompleter_PragmaOnceWarningIgnored_test(): filepath = '/foo.h', filetype = 'cpp' ) - response = app.post_json( '/event_notification', event_data ) - assert_that( response.body, empty() ) + response = app.post_json( '/event_notification', event_data ).json + assert_that( response, empty() ) @with_setup( Setup ) diff --git a/ycmd/tests/misc_handlers_test.py b/ycmd/tests/misc_handlers_test.py index 8b50531232..208201bc9f 100644 --- a/ycmd/tests/misc_handlers_test.py +++ b/ycmd/tests/misc_handlers_test.py @@ -47,3 +47,12 @@ def UserOptions_Works_test(): app.post_json( '/user_options', options ) eq_( options, app.get( '/user_options' ).json ) + + +@with_setup( Setup ) +def EventNotification_AlwaysJsonResponse_test(): + app = TestApp( handlers.app ) + event_data = BuildRequest( contents = 'foo foogoo ba', + event_name = 'FileReadyToParse' ) + + app.post_json( '/event_notification', event_data ).json