OLD | NEW |
(Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. |
| 4 |
| 5 import logging |
| 6 import os |
| 7 import webtest |
| 8 |
| 9 from google.appengine.api import taskqueue, users |
| 10 from testing_utils import testing |
| 11 |
| 12 import main |
| 13 from components import auth |
| 14 |
| 15 |
| 16 class IsGroupMemberTest(testing.AppengineTestCase): |
| 17 def test_is_group_member(self): |
| 18 # This is a smoke test for coverage. The function is otherwise trivial. |
| 19 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'Development server'}) |
| 20 main.is_group_member('foo') |
| 21 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'GAE production server'}) |
| 22 main.is_group_member('foo') |
| 23 |
| 24 |
| 25 class LoadBalancerTest(testing.AppengineTestCase): |
| 26 def test_choose_module(self): |
| 27 # Smoke test for coverage. |
| 28 self.mock(main.LoadBalancer, '_healthy_modules', lambda _: []) |
| 29 with self.assertRaises(main.NoBackendException): |
| 30 lb = main.LoadBalancer() |
| 31 lb.choose_module() |
| 32 |
| 33 |
| 34 class MonacqHandlerTest(testing.AppengineTestCase): |
| 35 @property |
| 36 def app_module(self): |
| 37 return main.app |
| 38 |
| 39 def setUp(self): |
| 40 super(MonacqHandlerTest, self).setUp() |
| 41 # Disable auth module checks. |
| 42 self.mock(users, 'get_current_user', |
| 43 lambda: users.User('test@user.com', 'auth_domain')) |
| 44 self.mock(main.MonacqHandler, 'xsrf_token_enforce_on', []) |
| 45 self.mock(auth, 'is_group_member', lambda _: True) # pragma: no branch |
| 46 |
| 47 def tearDown(self): |
| 48 super(MonacqHandlerTest, self).tearDown() |
| 49 |
| 50 def test_get(self): |
| 51 # GET request is not allowed. |
| 52 with self.assertRaises(webtest.AppError) as cm: |
| 53 self.test_app.get('/monacq') |
| 54 logging.info('exception = %s', cm.exception) |
| 55 self.assertIn('403', str(cm.exception)) |
| 56 |
| 57 def test_post(self): |
| 58 self.mock(taskqueue, 'add', lambda *_args, **_kw: None) |
| 59 # Dev appserver. |
| 60 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'Development server'}) |
| 61 self.test_app.post('/monacq', 'deadbeafdata') |
| 62 # Production server. |
| 63 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'GAE production server'}) |
| 64 self.test_app.post('/monacq', 'deadbeafdata') |
| 65 |
| 66 |
| 67 class MainHandlerTest(testing.AppengineTestCase): |
| 68 @property |
| 69 def app_module(self): |
| 70 return main.app |
| 71 |
| 72 def test_get(self): |
| 73 response = self.test_app.get('/') |
| 74 logging.info('response = %s', response) |
| 75 self.assertEquals(200, response.status_int) |
OLD | NEW |