| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2014 The LUCI Authors. All rights reserved. | 2 # Copyright 2014 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed under the Apache License, Version 2.0 | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # that can be found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 import datetime | 6 import datetime |
| 7 import logging | 7 import logging |
| 8 import os | 8 import os |
| 9 import random | 9 import random |
| 10 import sys | 10 import sys |
| 11 import unittest | 11 import unittest |
| 12 | 12 |
| 13 import test_env | 13 import test_env |
| 14 test_env.setup_test_env() | 14 test_env.setup_test_env() |
| 15 | 15 |
| 16 from google.appengine.ext import deferred | 16 from google.appengine.ext import deferred |
| 17 from google.appengine.ext import ndb | 17 from google.appengine.ext import ndb |
| 18 | 18 |
| 19 import webtest | 19 import webtest |
| 20 | 20 |
| 21 import event_mon_metrics |
| 22 |
| 21 from components import auth | 23 from components import auth |
| 22 from components import auth_testing | 24 from components import auth_testing |
| 23 from components import datastore_utils | 25 from components import datastore_utils |
| 24 from components import pubsub | 26 from components import pubsub |
| 25 from components import stats_framework | 27 from components import stats_framework |
| 26 from components import utils | 28 from components import utils |
| 27 from test_support import test_case | 29 from test_support import test_case |
| 28 | 30 |
| 29 from server import config | 31 from server import config |
| 30 from server import stats | 32 from server import stats |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 107 self.now = datetime.datetime(2014, 1, 2, 3, 4, 5, 6) | 109 self.now = datetime.datetime(2014, 1, 2, 3, 4, 5, 6) |
| 108 self.mock_now(self.now) | 110 self.mock_now(self.now) |
| 109 self.app = webtest.TestApp( | 111 self.app = webtest.TestApp( |
| 110 deferred.application, | 112 deferred.application, |
| 111 extra_environ={ | 113 extra_environ={ |
| 112 'REMOTE_ADDR': '1.0.1.2', | 114 'REMOTE_ADDR': '1.0.1.2', |
| 113 'SERVER_SOFTWARE': os.environ['SERVER_SOFTWARE'], | 115 'SERVER_SOFTWARE': os.environ['SERVER_SOFTWARE'], |
| 114 }) | 116 }) |
| 115 self.mock(stats_framework, 'add_entry', self._parse_line) | 117 self.mock(stats_framework, 'add_entry', self._parse_line) |
| 116 auth_testing.mock_get_current_identity(self) | 118 auth_testing.mock_get_current_identity(self) |
| 119 event_mon_metrics.initialize() |
| 117 | 120 |
| 118 def _parse_line(self, line): | 121 def _parse_line(self, line): |
| 119 # pylint: disable=W0212 | 122 # pylint: disable=W0212 |
| 120 actual = stats._parse_line(line, stats._Snapshot(), {}, {}, {}) | 123 actual = stats._parse_line(line, stats._Snapshot(), {}, {}, {}) |
| 121 self.assertIs(True, actual, line) | 124 self.assertIs(True, actual, line) |
| 122 | 125 |
| 123 def mock_pub_sub(self, enqueue_successful=True, publish_successful=True): | 126 def mock_pub_sub(self, enqueue_successful=True, publish_successful=True): |
| 124 calls = [] | 127 calls = [] |
| 125 def enqueue_task(**kwargs): | 128 def enqueue_task(**kwargs): |
| 126 calls.append(('via_task_queue', kwargs)) | 129 calls.append(('via_task_queue', kwargs)) |
| (...skipping 1590 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1717 (['1d69b9f088008811'], 0, 0), | 1720 (['1d69b9f088008811'], 0, 0), |
| 1718 task_scheduler.cron_handle_bot_died('f.local')) | 1721 task_scheduler.cron_handle_bot_died('f.local')) |
| 1719 | 1722 |
| 1720 | 1723 |
| 1721 if __name__ == '__main__': | 1724 if __name__ == '__main__': |
| 1722 if '-v' in sys.argv: | 1725 if '-v' in sys.argv: |
| 1723 unittest.TestCase.maxDiff = None | 1726 unittest.TestCase.maxDiff = None |
| 1724 logging.basicConfig( | 1727 logging.basicConfig( |
| 1725 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) | 1728 level=logging.DEBUG if '-v' in sys.argv else logging.CRITICAL) |
| 1726 unittest.main() | 1729 unittest.main() |
| OLD | NEW |