OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. |
| 5 |
| 6 import unittest |
| 7 |
| 8 import redirect as app |
| 9 |
| 10 |
| 11 class GaeTestCase(unittest.TestCase): |
| 12 def setUp(self, *args, **kwargs): |
| 13 self.clear_datastore() |
| 14 super(GaeTestCase, self).setUp(*args, **kwargs) |
| 15 |
| 16 @staticmethod |
| 17 def clear_datastore(): |
| 18 from google.appengine.api import apiproxy_stub_map, datastore_file_stub |
| 19 from google.appengine.api import memcache |
| 20 |
| 21 # See http://code.google.com/p/gaeunit/issues/detail?id=15 for clue. |
| 22 for key in ['datastore', 'datastore_v3']: |
| 23 # W0212: 23,16:GaeTestCase.clear_datastore: Access to a protected member |
| 24 # _APIProxyStubMap__stub_map of a client class |
| 25 # pylint: disable=W0212 |
| 26 # E1101: 50,16:GaeTestCase.clear_datastore: Instance of 'APIProxyStubMap' |
| 27 # has no '_APIProxyStubMap__stub_map' member |
| 28 # pylint: disable=E1101 |
| 29 if key in apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map: |
| 30 # W0212: 24,12:GaeTestCase.clear_datastore: Access to a protected |
| 31 # member _APIProxyStubMap__stub_map of a client class |
| 32 # pylint: disable=W0212 |
| 33 # E1101: 54,12:GaeTestCase.clear_datastore: Instance of |
| 34 # 'APIProxyStubMap' has no '_APIProxyStubMap__stub_map' member |
| 35 # pylint: disable=E1101 |
| 36 del apiproxy_stub_map.apiproxy._APIProxyStubMap__stub_map[key] |
| 37 |
| 38 # Use a fresh stub datastore. |
| 39 stub = datastore_file_stub.DatastoreFileStub( |
| 40 app.APP_NAME, '/dev/null', '/dev/null') |
| 41 apiproxy_stub_map.apiproxy.RegisterStub('datastore', stub) |
| 42 |
| 43 # Flush memcache. |
| 44 memcache.flush_all() |
| 45 |
| 46 |
| 47 class RedirectTestCase(GaeTestCase): |
| 48 def setUp(self): |
| 49 from google.appengine.ext import testbed |
| 50 self.testbed = testbed.Testbed() |
| 51 self.testbed.activate() |
| 52 self.testbed.init_user_stub() |
| 53 |
| 54 def tearDown(self): |
| 55 self.testbed.deactivate() |
| 56 |
| 57 def redirect_helper(self, path): |
| 58 from webtest import TestApp |
| 59 testapp = TestApp(app.application) |
| 60 response = testapp.get(path) |
| 61 self.assertEquals('302 Moved Temporarily', response.status) |
| 62 self.assertEquals('', response.body) |
| 63 return response |
| 64 |
| 65 def user_helper(self, email, uid): |
| 66 self.testbed.setup_env( |
| 67 USER_EMAIL = email, |
| 68 USER_ID = uid, |
| 69 USER_IS_ADMIN = '0', |
| 70 overwrite = True) |
| 71 |
| 72 def test_main_page_redirect_logged_out(self): |
| 73 self.assertEquals(app.users.get_current_user(), None) |
| 74 page = self.redirect_helper('/') |
| 75 self.assertEquals(page.headers['Location'], |
| 76 app.users.create_login_url('http://localhost/')) |
| 77 |
| 78 def test_main_page_redirect_logged_in(self): |
| 79 self.user_helper('tester@gmail.com', '123') |
| 80 page = self.redirect_helper('/') |
| 81 self.assertEquals(page.headers['Location'], |
| 82 'http://code.google.com/p/chromium/issues') |
| 83 |
| 84 def test_main_page_redirect_logged_in_chromium(self): |
| 85 self.user_helper('tester@chromium.org', '123') |
| 86 page = self.redirect_helper('/') |
| 87 self.assertEquals(page.headers['Location'], |
| 88 'http://chromiumbugs.appspot.com') |
| 89 |
| 90 def test_dev_page_redirect_logged_out(self): |
| 91 self.user_helper('', '') |
| 92 page = self.redirect_helper('/detailed') |
| 93 self.assertEquals(page.headers['Location'], |
| 94 'http://code.google.com/p/chromium/issues/entry') |
| 95 |
| 96 def test_dev_page_redirect_logged_in(self): |
| 97 self.user_helper('tester@gmail.com', '123') |
| 98 page = self.redirect_helper('/detailed') |
| 99 self.assertEquals(page.headers['Location'], |
| 100 'http://code.google.com/p/chromium/issues/entry') |
OLD | NEW |