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

Side by Side Diff: appengine/monorail/testing/test/testing_helpers_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 testing_helpers module."""
7
8 import unittest
9
10 from testing import testing_helpers
11
12
13 class TestingHelpersTest(unittest.TestCase):
14
15 def testMakeMonorailRequest(self):
16 mr = testing_helpers.MakeMonorailRequest(
17 path='/foo?key1=2&key2=a%20string&key3')
18
19 self.assertEqual(None, mr.GetIntParam('foo'))
20 self.assertEqual(2, mr.GetIntParam('key1'))
21 self.assertEqual(None, mr.GetIntParam('key2'))
22 self.assertEqual(None, mr.GetIntParam('key3'))
23 self.assertEqual(3, mr.GetIntParam('key2', default_value=3))
24 self.assertEqual(3, mr.GetIntParam('foo', default_value=3))
25
26 def testGetRequestObjectsBasics(self):
27 request, mr = testing_helpers.GetRequestObjects(
28 path='/foo/bar/wee?sna=foo',
29 params={'ya': 'hoo'}, method='POST')
30
31 # supplied as part of the url
32 self.assertEqual('foo', mr.GetParam('sna'))
33
34 # supplied as a param
35 self.assertEqual('hoo', mr.GetParam('ya'))
36
37 # default Host header
38 self.assertEqual('127.0.0.1', request.host)
39
40 def testGetRequestObjectsHeaders(self):
41 # with some headers
42 request, _mr = testing_helpers.GetRequestObjects(
43 headers={'Accept-Language': 'en', 'Host': 'pickledsheep.com'},
44 path='/foo/bar/wee?sna=foo')
45
46 # default Host header
47 self.assertEqual('pickledsheep.com', request.host)
48
49 # user specified headers
50 self.assertEqual('en', request.headers['Accept-Language'])
51
52 def testGetRequestObjectsUserInfo(self):
53 user_id = '123'
54
55 _request, mr = testing_helpers.GetRequestObjects(
56 user_info={'user_id': user_id})
57
58 self.assertEqual(user_id, mr.auth.user_id)
59
60
61 class BlankTest(unittest.TestCase):
62
63 def testBlank(self):
64 blank = testing_helpers.Blank(
65 foo='foo',
66 bar=123,
67 inc=lambda x: x + 1)
68
69 self.assertEqual('foo', blank.foo)
70 self.assertEqual(123, blank.bar)
71 self.assertEqual(5, blank.inc(4))
72
73
74 if __name__ == '__main__':
75 unittest.main()
OLDNEW
« no previous file with comments | « appengine/monorail/testing/test/fake_test.py ('k') | appengine/monorail/testing/testing_helpers.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698