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

Unified 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 side-by-side diff with in-line comments
Download patch
« 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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: appengine/monorail/testing/test/testing_helpers_test.py
diff --git a/appengine/monorail/testing/test/testing_helpers_test.py b/appengine/monorail/testing/test/testing_helpers_test.py
new file mode 100644
index 0000000000000000000000000000000000000000..f36595c3962ca397567f683a57bd48d39da8d5d9
--- /dev/null
+++ b/appengine/monorail/testing/test/testing_helpers_test.py
@@ -0,0 +1,75 @@
+# 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 testing_helpers module."""
+
+import unittest
+
+from testing import testing_helpers
+
+
+class TestingHelpersTest(unittest.TestCase):
+
+ def testMakeMonorailRequest(self):
+ mr = testing_helpers.MakeMonorailRequest(
+ path='/foo?key1=2&key2=a%20string&key3')
+
+ self.assertEqual(None, mr.GetIntParam('foo'))
+ self.assertEqual(2, mr.GetIntParam('key1'))
+ self.assertEqual(None, mr.GetIntParam('key2'))
+ self.assertEqual(None, mr.GetIntParam('key3'))
+ self.assertEqual(3, mr.GetIntParam('key2', default_value=3))
+ self.assertEqual(3, mr.GetIntParam('foo', default_value=3))
+
+ def testGetRequestObjectsBasics(self):
+ request, mr = testing_helpers.GetRequestObjects(
+ path='/foo/bar/wee?sna=foo',
+ params={'ya': 'hoo'}, method='POST')
+
+ # supplied as part of the url
+ self.assertEqual('foo', mr.GetParam('sna'))
+
+ # supplied as a param
+ self.assertEqual('hoo', mr.GetParam('ya'))
+
+ # default Host header
+ self.assertEqual('127.0.0.1', request.host)
+
+ def testGetRequestObjectsHeaders(self):
+ # with some headers
+ request, _mr = testing_helpers.GetRequestObjects(
+ headers={'Accept-Language': 'en', 'Host': 'pickledsheep.com'},
+ path='/foo/bar/wee?sna=foo')
+
+ # default Host header
+ self.assertEqual('pickledsheep.com', request.host)
+
+ # user specified headers
+ self.assertEqual('en', request.headers['Accept-Language'])
+
+ def testGetRequestObjectsUserInfo(self):
+ user_id = '123'
+
+ _request, mr = testing_helpers.GetRequestObjects(
+ user_info={'user_id': user_id})
+
+ self.assertEqual(user_id, mr.auth.user_id)
+
+
+class BlankTest(unittest.TestCase):
+
+ def testBlank(self):
+ blank = testing_helpers.Blank(
+ foo='foo',
+ bar=123,
+ inc=lambda x: x + 1)
+
+ self.assertEqual('foo', blank.foo)
+ self.assertEqual(123, blank.bar)
+ self.assertEqual(5, blank.inc(4))
+
+
+if __name__ == '__main__':
+ unittest.main()
« 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