From 1a8bc5f3830161fb35ec9608108e3ac965734f4c Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Sat, 4 Mar 2017 23:34:28 -0800 Subject: [PATCH] coverage: Bring test_decorators to 100% coverage. --- tools/test-backend | 1 - zerver/tests/test_decorators.py | 19 ++++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/tools/test-backend b/tools/test-backend index 7281a830bd..4aa5436888 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -84,7 +84,6 @@ not_yet_fully_covered = { # they don't! 'zerver/tests/test_auth_backends.py', 'zerver/tests/test_bugdown.py', - 'zerver/tests/test_decorators.py', 'zerver/tests/test_narrow.py', 'zerver/tests/test_tornado.py', 'zerver/tests/test_urls.py', diff --git a/zerver/tests/test_decorators.py b/zerver/tests/test_decorators.py index 1cfc39298d..83ac175024 100644 --- a/zerver/tests/test_decorators.py +++ b/zerver/tests/test_decorators.py @@ -123,6 +123,11 @@ class DecoratorTestCase(TestCase): get_total(request) self.assertEqual(str(cm.exception), "Bad value for 'numbers': bad_value") + request.POST['numbers'] = ujson.dumps('{fun: unfun}') + with self.assertRaises(JsonableError) as cm: + get_total(request) + self.assertEqual(str(cm.exception), 'Bad value for \'numbers\': "{fun: unfun}"') + request.POST['numbers'] = ujson.dumps([2, 3, 5, 8, 13, 21]) with self.assertRaises(JsonableError) as cm: get_total(request) @@ -188,7 +193,7 @@ class DecoratorTestCase(TestCase): @has_request_variables def test(request, payload=REQ(argument_type="invalid")): # type: (HttpRequest, Dict[str, Dict]) -> None - pass + pass # nocoverage # this function isn't meant to be called test(request) def test_api_key_only_webhook_view(self): @@ -899,7 +904,7 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase): def test_authenticated_json_view_if_subdomain_is_invalid(self): # type: () -> None user_email = 'hamlet@zulip.com' - self._login(user_email) + self.login(user_email) with self.settings(REALMS_HAVE_SUBDOMAINS=True): with mock.patch('logging.warning') as mock_warning, \ mock.patch('zerver.decorator.get_subdomain', return_value=''): @@ -924,14 +929,6 @@ class TestAuthenticatedJsonViewDecorator(ZulipTestCase): data = {"status": '"started"'} return self.client_post(r'/json/tutorial_status', data) - def _login(self, user_email, password=None): - # type: (str, str) -> None - if password: - user_profile = get_user_profile_by_email(user_email) - user_profile.set_password(password) - user_profile.save() - self.login(user_email, password) - class TestZulipLoginRequiredDecorator(ZulipTestCase): def test_zulip_login_required_if_subdomain_is_invalid(self): # type: () -> None @@ -978,7 +975,7 @@ class ReturnSuccessOnHeadRequestDecorator(ZulipTestCase): @return_success_on_head_request def test_function(request): # type: (HttpRequest) -> HttpResponse - return json_response(msg=u'from_test_function') + return json_response(msg=u'from_test_function') # nocoverage. isn't meant to be called response = test_function(request) self.assert_json_success(response)