Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1598)

Unified Diff: appengine/monorail/framework/test/captcha_test.py

Issue 1868553004: Open Source Monorail (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: appengine/monorail/framework/test/captcha_test.py
diff --git a/appengine/monorail/framework/test/captcha_test.py b/appengine/monorail/framework/test/captcha_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..19996e59a548100b3e45f5f99e12ba9f6ed80e53
--- /dev/null
+++ b/appengine/monorail/framework/test/captcha_test.py
@@ -0,0 +1,84 @@
+# Copyright 2016 The Chromium Authors. All rights reserved.
+# Use of this source code is govered by a BSD-style
+# license that can be found in the LICENSE file or at
+# https://developers.google.com/open-source/licenses/bsd
+
+"""Tests for the captcha module."""
+
+import unittest
+
+import mox
+
+from google.appengine.ext import testbed
+
+from framework import captcha
+
+
+class CaptchaTest(unittest.TestCase):
+
+ def setUp(self):
+ self.mox = mox.Mox()
+ self.testbed = testbed.Testbed()
+ self.testbed.activate()
+ self.testbed.init_user_stub()
+ self.testbed.init_memcache_stub()
+ self.testbed.init_datastore_v3_stub()
+
+ def tearDown(self):
+ self.mox.UnsetStubs()
+ self.mox.ResetAll()
+
+ def testVerify_NoGuess(self):
+ self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
+ # We are verifying that _AskRecaptcha is not called.
+ self.mox.ReplayAll()
+ self.assertEqual(
+ (False, 'incorrect-captcha-sol'),
+ captcha.Verify('1.2.3.4', ''))
+ self.mox.VerifyAll()
+
+ def testVerify_NullGuess(self):
+ self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
+ # We are verifying that _AskRecaptcha is not called.
+ self.mox.ReplayAll()
+ self.assertEqual(
+ (False, 'incorrect-captcha-sol'),
+ captcha.Verify('1.2.3.4', None))
+ self.mox.VerifyAll()
+
+ def testVerify_WrongGuess(self):
+ self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
+ captcha._AskRecaptcha(
+ '1.2.3.4', 'matching').AndReturn(
+ {'success': False, 'error-codes': ['invalid-input-response']})
+ self.mox.ReplayAll()
+ self.assertEqual(
+ (False, ['invalid-input-response']),
+ captcha.Verify('1.2.3.4', 'some challenge'))
+ self.mox.VerifyAll()
+
+ def testVerify_CorrectGuess(self):
+ self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
+ captcha._AskRecaptcha(
+ '1.2.3.4', 'matching').AndReturn({'success':True})
+ self.mox.ReplayAll()
+
+ result = captcha.Verify('1.2.3.4', 'matching')
+
+ self.mox.VerifyAll()
+ self.assertEqual((True, ''), result)
+
+ def testVerify_WrongGuess(self):
+ self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
+ captcha._AskRecaptcha(
+ '1.2.3.4', 'non-matching').AndReturn({'success': False})
+ self.mox.ReplayAll()
+
+ result = captcha.Verify('1.2.3.4', 'non-matching')
+
+ self.mox.VerifyAll()
+ self.assertEqual((False, 'incorrect-captcha-sol'), result)
+
+
+if __name__ == '__main__':
+ unittest.main()
« no previous file with comments | « appengine/monorail/framework/test/banned_test.py ('k') | appengine/monorail/framework/test/emailfmt_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698