From 797fa62fded2377443bc06297ff02a1cb639330e Mon Sep 17 00:00:00 2001 From: Shubham Dhama Date: Fri, 12 Jan 2018 03:38:53 +0530 Subject: [PATCH] test auth.py: Add tests for json_fetch_api_key function. --- zerver/tests/test_auth_backends.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/zerver/tests/test_auth_backends.py b/zerver/tests/test_auth_backends.py index a4e57cded9..d277741870 100644 --- a/zerver/tests/test_auth_backends.py +++ b/zerver/tests/test_auth_backends.py @@ -1115,6 +1115,32 @@ class GoogleLoginTest(GoogleOAuthTest): self.assertEqual(m.call_args_list[0][0][0], 'Google oauth2 CSRF error') +class JSONFetchAPIKeyTest(ZulipTestCase): + def setUp(self) -> None: + self.user_profile = self.example_user('hamlet') + self.email = self.user_profile.email + + def test_success(self) -> None: + self.login(self.email) + result = self.client_post("/json/fetch_api_key", + dict(user_profile=self.user_profile, + password=initial_password(self.email))) + self.assert_json_success(result) + + def test_not_loggedin(self) -> None: + result = self.client_post("/json/fetch_api_key", + dict(user_profile=self.user_profile, + password=initial_password(self.email))) + self.assert_json_error(result, + "Not logged in: API authentication or user session required", 401) + + def test_wrong_password(self) -> None: + self.login(self.email) + result = self.client_post("/json/fetch_api_key", + dict(user_profile=self.user_profile, + password="wrong")) + self.assert_json_error(result, "Your username or password is incorrect.", 400) + class FetchAPIKeyTest(ZulipTestCase): def setUp(self) -> None: self.user_profile = self.example_user('hamlet')