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

Side by Side Diff: chromium-shortener/new-crbug/app_test.py

Issue 12208137: Add code for www.crbug and new.crbug appengine apps. (Closed) Base URL: https://src.chromium.org/chrome/trunk/tools/
Patch Set: Created 7 years, 10 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
« no previous file with comments | « chromium-shortener/new-crbug/app.yaml ('k') | chromium-shortener/new-crbug/redirect.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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')
OLDNEW
« no previous file with comments | « chromium-shortener/new-crbug/app.yaml ('k') | chromium-shortener/new-crbug/redirect.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698