|
| 1 | +# Copyright 2016 Google Inc. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +import unittest |
| 16 | + |
| 17 | + |
| 18 | +class Test_build_flask_context(unittest.TestCase): |
| 19 | + |
| 20 | + def _call_fut(self, request): |
| 21 | + from google.cloud.error_reporting.util import build_flask_context |
| 22 | + return build_flask_context(request) |
| 23 | + |
| 24 | + def test_flask_helper(self): |
| 25 | + import mock |
| 26 | + |
| 27 | + user_agent = mock.Mock(string='Google Cloud Unit Tests Agent') |
| 28 | + request = _Request('http://google.com', 'GET', |
| 29 | + user_agent, |
| 30 | + 'http://gmail.com', |
| 31 | + '127.0.0.1') |
| 32 | + |
| 33 | + context = self._call_fut(request) |
| 34 | + self.assertEqual(request.url, context.url) |
| 35 | + self.assertEqual(request.method, context.method) |
| 36 | + self.assertEqual(request.user_agent.string, context.userAgent) |
| 37 | + self.assertEqual(request.referrer, context.referrer) |
| 38 | + self.assertEqual(request.remote_addr, context.remoteIp) |
| 39 | + |
| 40 | + |
| 41 | +class _Request(object): |
| 42 | + |
| 43 | + def __init__(self, url, method, user_agent, referrer, remote_addr): |
| 44 | + self.url = url |
| 45 | + self.method = method |
| 46 | + self.user_agent = user_agent |
| 47 | + self.referrer = referrer |
| 48 | + self.remote_addr = remote_addr |
0 commit comments