OLD | NEW |
(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() |
OLD | NEW |