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 urllib2 |
| 8 import webtest |
| 9 |
| 10 from google.appengine.api import taskqueue, users |
| 11 from testing_utils import testing |
| 12 |
| 13 import common |
| 14 import main |
| 15 from components import auth |
| 16 |
| 17 |
| 18 class MonacqHandlerTest(testing.AppengineTestCase): |
| 19 |
| 20 @property |
| 21 def app_module(self): |
| 22 return main.app |
| 23 |
| 24 def setUp(self): |
| 25 super(MonacqHandlerTest, self).setUp() |
| 26 # Disable auth module checks. |
| 27 self.mock(users, 'get_current_user', |
| 28 lambda: users.User('test@user.com', 'auth_domain')) |
| 29 self.mock(main.MonacqHandler, 'xsrf_token_enforce_on', []) |
| 30 self.mock(auth, 'is_group_member', lambda _: True) # pragma: no branch |
| 31 |
| 32 def tearDown(self): |
| 33 super(MonacqHandlerTest, self).tearDown() |
| 34 |
| 35 def test_require_group_membership(self): |
| 36 # This is a smoke test for coverage. The function is otherwise trivial. |
| 37 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'Development server'}) |
| 38 main.require_group_membership('foo') |
| 39 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'GAE production server'}) |
| 40 main.require_group_membership('foo') |
| 41 |
| 42 def test_get(self): |
| 43 # GET request is not allowed. |
| 44 with self.assertRaises(webtest.AppError) as cm: |
| 45 self.test_app.get('/monacq') |
| 46 logging.info('exception = %s', cm.exception) |
| 47 self.assertIn('405', str(cm.exception)) |
| 48 |
| 49 def test_post(self): |
| 50 # self.mock(taskqueue, 'add', lambda *_args, **_kw: None) |
| 51 self.mock(urllib2, 'urlopen', lambda _: None) |
| 52 # Dev appserver. |
| 53 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'Development server'}) |
| 54 self.test_app.post('/monacq', 'deadbeafdata') |
| 55 # Production server. |
| 56 self.mock(os, 'environ', {'SERVER_SOFTWARE': 'GAE production server'}) |
| 57 self.test_app.post('/monacq', 'deadbeafdata') |
| 58 |
| 59 |
| 60 class MainHandlerTest(testing.AppengineTestCase): |
| 61 |
| 62 @property |
| 63 def app_module(self): |
| 64 return main.app |
| 65 |
| 66 def test_get(self): |
| 67 response = self.test_app.get('/') |
| 68 logging.info('response = %s', response) |
| 69 self.assertEquals(200, response.status_int) |
OLD | NEW |