coverage: bring zerver/lib/response.py to 100% coverage.

This commit is contained in:
Tim Abbott 2017-03-05 00:26:07 -08:00
parent 89decf6ded
commit e95f139308
3 changed files with 10 additions and 5 deletions

View File

@ -54,6 +54,7 @@ target_fully_covered = {path for target in [
'zerver/lib/notifications.py', 'zerver/lib/notifications.py',
'zerver/lib/push_notifications.py', 'zerver/lib/push_notifications.py',
'zerver/lib/request.py', 'zerver/lib/request.py',
'zerver/lib/response.py',
'zerver/lib/test_helpers.py', 'zerver/lib/test_helpers.py',
'zerver/lib/test_classes.py', 'zerver/lib/test_classes.py',
'zerver/lib/upload.py', 'zerver/lib/upload.py',

View File

@ -18,7 +18,7 @@ class HttpResponseUnauthorized(HttpResponse):
elif www_authenticate == "session": elif www_authenticate == "session":
self["WWW-Authenticate"] = 'Session realm="%s"' % (realm,) self["WWW-Authenticate"] = 'Session realm="%s"' % (realm,)
else: else:
raise Exception("Invalid www_authenticate value!") raise AssertionError("Invalid www_authenticate value!")
def json_unauthorized(message, www_authenticate=None): def json_unauthorized(message, www_authenticate=None):
# type: (Text, Optional[Text]) -> HttpResponse # type: (Text, Optional[Text]) -> HttpResponse
@ -50,7 +50,3 @@ def json_success(data=None):
def json_error(msg, data=None, status=400): def json_error(msg, data=None, status=400):
# type: (str, Optional[Dict[str, Any]], int) -> HttpResponse # type: (str, Optional[Dict[str, Any]], int) -> HttpResponse
return json_response(res_type="error", msg=msg, data=data, status=status) return json_response(res_type="error", msg=msg, data=data, status=status)
def json_unhandled_exception():
# type: () -> HttpResponse
return json_response(res_type="error", msg="Internal server error", status=500)

View File

@ -1004,3 +1004,11 @@ class ReturnSuccessOnHeadRequestDecorator(ZulipTestCase):
response = test_function(request) response = test_function(request)
self.assertEqual(ujson.loads(response.content).get('msg'), u'from_test_function') self.assertEqual(ujson.loads(response.content).get('msg'), u'from_test_function')
class RestAPITest(ZulipTestCase):
def test_method_not_allowed(self):
# type: () -> None
self.login("hamlet@zulip.com")
result = self.client_patch('/json/users')
self.assertEqual(result.status_code, 405)
self.assert_in_response('Method Not Allowed', result)