• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2017 Google LLC
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
16try:
17    import grpc
18except ImportError:
19    grpc = None
20
21from google.api_core import client_info
22
23
24def test_constructor_defaults():
25    info = client_info.ClientInfo()
26
27    assert info.python_version is not None
28
29    if grpc is not None:
30        assert info.grpc_version is not None
31    else:
32        assert info.grpc_version is None
33
34    assert info.api_core_version is not None
35    assert info.gapic_version is None
36    assert info.client_library_version is None
37    assert info.rest_version is None
38
39
40def test_constructor_options():
41    info = client_info.ClientInfo(
42        python_version="1",
43        grpc_version="2",
44        api_core_version="3",
45        gapic_version="4",
46        client_library_version="5",
47        user_agent="6",
48        rest_version="7",
49    )
50
51    assert info.python_version == "1"
52    assert info.grpc_version == "2"
53    assert info.api_core_version == "3"
54    assert info.gapic_version == "4"
55    assert info.client_library_version == "5"
56    assert info.user_agent == "6"
57    assert info.rest_version == "7"
58
59
60def test_to_user_agent_minimal():
61    info = client_info.ClientInfo(
62        python_version="1", api_core_version="2", grpc_version=None
63    )
64
65    user_agent = info.to_user_agent()
66
67    assert user_agent == "gl-python/1 gax/2"
68
69
70def test_to_user_agent_full():
71    info = client_info.ClientInfo(
72        python_version="1",
73        grpc_version="2",
74        api_core_version="3",
75        gapic_version="4",
76        client_library_version="5",
77        user_agent="app-name/1.0",
78    )
79
80    user_agent = info.to_user_agent()
81
82    assert user_agent == "app-name/1.0 gl-python/1 grpc/2 gax/3 gapic/4 gccl/5"
83
84
85def test_to_user_agent_rest():
86    info = client_info.ClientInfo(
87        python_version="1",
88        grpc_version=None,
89        rest_version="2",
90        api_core_version="3",
91        gapic_version="4",
92        client_library_version="5",
93        user_agent="app-name/1.0",
94    )
95
96    user_agent = info.to_user_agent()
97
98    assert user_agent == "app-name/1.0 gl-python/1 rest/2 gax/3 gapic/4 gccl/5"
99