OXIESEC PANEL
- Current Dir:
/
/
opt
/
gsutil
/
third_party
/
apitools
/
apitools
/
base
/
py
Server IP: 2a02:4780:11:1594:0:ef5:22d7:a
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/11/2025 08:19:48 AM
rwxr-xr-x
📄
__init__.py
1.22 KB
10/23/2024 10:32:22 PM
rw-r--r--
📁
__pycache__
-
02/11/2025 08:19:48 AM
rwxr-xr-x
📄
base_api.py
29.29 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
base_api_test.py
14.12 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
batch.py
17.93 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
batch_test.py
24.73 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
buffered_stream.py
2.52 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
buffered_stream_test.py
2.4 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
compression.py
5.02 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
compression_test.py
5.19 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
credentials_lib.py
29.42 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
credentials_lib_test.py
7.58 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
encoding.py
1.16 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
encoding_helper.py
30 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
encoding_test.py
31.97 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
exceptions.py
4.98 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
exceptions_test.py
2.88 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
extra_types.py
9.74 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
extra_types_test.py
7.81 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
gzip.py
21.39 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
gzip_test.py
17.17 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
http_wrapper.py
15.09 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
http_wrapper_test.py
5.09 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
list_pager.py
5.49 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
list_pager_test.py
13.08 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
stream_slice.py
2.67 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
stream_slice_test.py
2.2 KB
10/23/2024 10:32:22 PM
rw-r--r--
📁
testing
-
10/23/2024 10:32:22 PM
rwxr-xr-x
📄
transfer.py
45.42 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
transfer_test.py
26.06 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
util.py
8.28 KB
10/23/2024 10:32:22 PM
rw-r--r--
📄
util_test.py
7.01 KB
10/23/2024 10:32:22 PM
rw-r--r--
Editing: util_test.py
Close
# # Copyright 2015 Google Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. """Tests for util.py.""" import unittest from apitools.base.protorpclite import messages from apitools.base.py import encoding from apitools.base.py import exceptions from apitools.base.py import util class MockedMethodConfig(object): def __init__(self, relative_path, path_params): self.relative_path = relative_path self.path_params = path_params class MessageWithRemappings(messages.Message): class AnEnum(messages.Enum): value_one = 1 value_two = 2 str_field = messages.StringField(1) enum_field = messages.EnumField('AnEnum', 2) enum_field_remapping = messages.EnumField('AnEnum', 3) encoding.AddCustomJsonFieldMapping( MessageWithRemappings, 'str_field', 'path_field') encoding.AddCustomJsonFieldMapping( MessageWithRemappings, 'enum_field_remapping', 'enum_field_remapped') encoding.AddCustomJsonEnumMapping( MessageWithRemappings.AnEnum, 'value_one', 'ONE') class UtilTest(unittest.TestCase): def testExpand(self): method_config_xy = MockedMethodConfig(relative_path='{x}/y/{z}', path_params=['x', 'z']) self.assertEqual( util.ExpandRelativePath(method_config_xy, {'x': '1', 'z': '2'}), '1/y/2') self.assertEqual( util.ExpandRelativePath( method_config_xy, {'x': '1', 'z': '2'}, relative_path='{x}/y/{z}/q'), '1/y/2/q') def testReservedExpansion(self): method_config_reserved = MockedMethodConfig(relative_path='{+x}/baz', path_params=['x']) self.assertEqual('foo/:bar:/baz', util.ExpandRelativePath( method_config_reserved, {'x': 'foo/:bar:'})) method_config_no_reserved = MockedMethodConfig(relative_path='{x}/baz', path_params=['x']) self.assertEqual('foo%2F%3Abar%3A/baz', util.ExpandRelativePath( method_config_no_reserved, {'x': 'foo/:bar:'})) def testCalculateWaitForRetry(self): try0 = util.CalculateWaitForRetry(0) self.assertTrue(try0 >= 1.0) self.assertTrue(try0 <= 1.5) try1 = util.CalculateWaitForRetry(1) self.assertTrue(try1 >= 1.0) self.assertTrue(try1 <= 3.0) try2 = util.CalculateWaitForRetry(2) self.assertTrue(try2 >= 2.0) self.assertTrue(try2 <= 6.0) try3 = util.CalculateWaitForRetry(3) self.assertTrue(try3 >= 4.0) self.assertTrue(try3 <= 12.0) try4 = util.CalculateWaitForRetry(4) self.assertTrue(try4 >= 8.0) self.assertTrue(try4 <= 24.0) self.assertAlmostEqual(10, util.CalculateWaitForRetry(5, max_wait=10)) def testTypecheck(self): class Class1(object): pass class Class2(object): pass class Class3(object): pass instance_of_class1 = Class1() self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, Class1)) self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, ((Class1, Class2), Class3))) self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, (Class1, (Class2, Class3)))) self.assertEqual( instance_of_class1, util.Typecheck(instance_of_class1, Class1, 'message')) self.assertEqual( instance_of_class1, util.Typecheck( instance_of_class1, ((Class1, Class2), Class3), 'message')) self.assertEqual( instance_of_class1, util.Typecheck( instance_of_class1, (Class1, (Class2, Class3)), 'message')) with self.assertRaises(exceptions.TypecheckError): util.Typecheck(instance_of_class1, Class2) with self.assertRaises(exceptions.TypecheckError): util.Typecheck(instance_of_class1, (Class2, Class3)) with self.assertRaises(exceptions.TypecheckError): util.Typecheck(instance_of_class1, Class2, 'message') with self.assertRaises(exceptions.TypecheckError): util.Typecheck(instance_of_class1, (Class2, Class3), 'message') def testAcceptableMimeType(self): valid_pairs = ( ('*', 'text/plain'), ('*/*', 'text/plain'), ('text/*', 'text/plain'), ('*/plain', 'text/plain'), ('text/plain', 'text/plain'), ) for accept, mime_type in valid_pairs: self.assertTrue(util.AcceptableMimeType([accept], mime_type)) invalid_pairs = ( ('text/*', 'application/json'), ('text/plain', 'application/json'), ) for accept, mime_type in invalid_pairs: self.assertFalse(util.AcceptableMimeType([accept], mime_type)) self.assertTrue(util.AcceptableMimeType(['application/json', '*/*'], 'text/plain')) self.assertFalse(util.AcceptableMimeType(['application/json', 'img/*'], 'text/plain')) def testMalformedMimeType(self): self.assertRaises( exceptions.InvalidUserInputError, util.AcceptableMimeType, ['*/*'], 'abcd') def testUnsupportedMimeType(self): self.assertRaises( exceptions.GeneratedClientError, util.AcceptableMimeType, ['text/html;q=0.9'], 'text/html') def testMapRequestParams(self): params = { 'str_field': 'foo', 'enum_field': MessageWithRemappings.AnEnum.value_one, 'enum_field_remapping': MessageWithRemappings.AnEnum.value_one, } remapped_params = { 'path_field': 'foo', 'enum_field': 'ONE', 'enum_field_remapped': 'ONE', } self.assertEqual(remapped_params, util.MapRequestParams(params, MessageWithRemappings)) params['enum_field'] = MessageWithRemappings.AnEnum.value_two remapped_params['enum_field'] = 'value_two' self.assertEqual(remapped_params, util.MapRequestParams(params, MessageWithRemappings)) def testMapParamNames(self): params = ['path_field', 'enum_field'] remapped_params = ['str_field', 'enum_field'] self.assertEqual(remapped_params, util.MapParamNames(params, MessageWithRemappings))