|
| 1 | +# Copyright 2015 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 unittest2 |
| 16 | + |
| 17 | + |
| 18 | +class TestConnection(unittest2.TestCase): |
| 19 | + |
| 20 | + def _getTargetClass(self): |
| 21 | + from gcloud.search.connection import Connection |
| 22 | + return Connection |
| 23 | + |
| 24 | + def _makeOne(self, *args, **kw): |
| 25 | + return self._getTargetClass()(*args, **kw) |
| 26 | + |
| 27 | + def test_build_api_url_no_extra_query_params(self): |
| 28 | + conn = self._makeOne() |
| 29 | + URI = '/'.join([ |
| 30 | + conn.API_BASE_URL, |
| 31 | + conn.API_VERSION, |
| 32 | + 'foo', |
| 33 | + ]) |
| 34 | + self.assertEqual(conn.build_api_url('/foo'), URI) |
| 35 | + |
| 36 | + def test_build_api_url_w_extra_query_params(self): |
| 37 | + from six.moves.urllib.parse import parse_qsl |
| 38 | + from six.moves.urllib.parse import urlsplit |
| 39 | + conn = self._makeOne() |
| 40 | + uri = conn.build_api_url('/foo', {'bar': 'baz'}) |
| 41 | + scheme, netloc, path, qs, _ = urlsplit(uri) |
| 42 | + self.assertEqual('%s://%s' % (scheme, netloc), conn.API_BASE_URL) |
| 43 | + self.assertEqual(path, |
| 44 | + '/'.join(['', conn.API_VERSION, 'foo'])) |
| 45 | + parms = dict(parse_qsl(qs)) |
| 46 | + self.assertEqual(parms['bar'], 'baz') |
0 commit comments