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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is govered by a BSD-style
3 # license that can be found in the LICENSE file or at
4 # https://developers.google.com/open-source/licenses/bsd
5
6 """Tests for the captcha module."""
7
8 import unittest
9
10 import mox
11
12 from google.appengine.ext import testbed
13
14 from framework import captcha
15
16
17 class CaptchaTest(unittest.TestCase):
18
19 def setUp(self):
20 self.mox = mox.Mox()
21 self.testbed = testbed.Testbed()
22 self.testbed.activate()
23 self.testbed.init_user_stub()
24 self.testbed.init_memcache_stub()
25 self.testbed.init_datastore_v3_stub()
26
27 def tearDown(self):
28 self.mox.UnsetStubs()
29 self.mox.ResetAll()
30
31 def testVerify_NoGuess(self):
32 self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
33 # We are verifying that _AskRecaptcha is not called.
34 self.mox.ReplayAll()
35 self.assertEqual(
36 (False, 'incorrect-captcha-sol'),
37 captcha.Verify('1.2.3.4', ''))
38 self.mox.VerifyAll()
39
40 def testVerify_NullGuess(self):
41 self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
42 # We are verifying that _AskRecaptcha is not called.
43 self.mox.ReplayAll()
44 self.assertEqual(
45 (False, 'incorrect-captcha-sol'),
46 captcha.Verify('1.2.3.4', None))
47 self.mox.VerifyAll()
48
49 def testVerify_WrongGuess(self):
50 self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
51 captcha._AskRecaptcha(
52 '1.2.3.4', 'matching').AndReturn(
53 {'success': False, 'error-codes': ['invalid-input-response']})
54 self.mox.ReplayAll()
55 self.assertEqual(
56 (False, ['invalid-input-response']),
57 captcha.Verify('1.2.3.4', 'some challenge'))
58 self.mox.VerifyAll()
59
60 def testVerify_CorrectGuess(self):
61 self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
62 captcha._AskRecaptcha(
63 '1.2.3.4', 'matching').AndReturn({'success':True})
64 self.mox.ReplayAll()
65
66 result = captcha.Verify('1.2.3.4', 'matching')
67
68 self.mox.VerifyAll()
69 self.assertEqual((True, ''), result)
70
71 def testVerify_WrongGuess(self):
72 self.mox.StubOutWithMock(captcha, '_AskRecaptcha')
73 captcha._AskRecaptcha(
74 '1.2.3.4', 'non-matching').AndReturn({'success': False})
75 self.mox.ReplayAll()
76
77 result = captcha.Verify('1.2.3.4', 'non-matching')
78
79 self.mox.VerifyAll()
80 self.assertEqual((False, 'incorrect-captcha-sol'), result)
81
82
83 if __name__ == '__main__':
84 unittest.main()
OLDNEW
« 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