@@ -7,30 +7,38 @@ class TestUserAgent:
7
7
def test_user_agent (self ):
8
8
config = ConfigBuilder .build (api_key = "my-api-key" , host = "https://my-controller-host" )
9
9
useragent = get_user_agent (config )
10
- assert re .search (r"python-client-\d+\.\d+\.\d+" , useragent ) is not None
11
- assert re .search (r"urllib3:\d+\.\d+\.\d+" , useragent ) is not None
10
+ assert re .search (r"^python-client-\d+\.\d+\.\d+$" , useragent ) is not None
12
11
13
12
def test_user_agent_with_source_tag (self ):
14
13
config = ConfigBuilder .build (
15
14
api_key = "my-api-key" , host = "https://my-controller-host" , source_tag = "my_source_tag"
16
15
)
17
16
useragent = get_user_agent (config )
18
- assert re .search (r"python-client-\d+\.\d+\.\d+" , useragent ) is not None
19
- assert re .search (r"urllib3:\d+\.\d+\.\d+" , useragent ) is not None
20
- assert re .search (r"source_tag=my_source_tag" , useragent ) is not None
17
+ assert (
18
+ re .search (r"^python-client-\d+\.\d+\.\d+; source_tag=my_source_tag$" , useragent )
19
+ is not None
20
+ )
21
21
22
22
def test_source_tag_is_normalized (self ):
23
23
config = ConfigBuilder .build (
24
24
api_key = "my-api-key" , host = "https://my-controller-host" , source_tag = "my source tag!!!!"
25
25
)
26
26
useragent = get_user_agent (config )
27
- assert re .search (r"source_tag=my_source_tag" , useragent ) is not None
27
+ assert (
28
+ re .search (r"^python-client-\d+\.\d+\.\d+; source_tag=my_source_tag$" , useragent )
29
+ is not None
30
+ )
31
+ assert "!!!!" not in useragent
28
32
29
33
config = ConfigBuilder .build (
30
34
api_key = "my-api-key" , host = "https://my-controller-host" , source_tag = "My Source Tag"
31
35
)
32
36
useragent = get_user_agent (config )
33
- assert re .search (r"source_tag=my_source_tag" , useragent ) is not None
37
+ assert (
38
+ re .search (r"^python-client-\d+\.\d+\.\d+; source_tag=my_source_tag$" , useragent )
39
+ is not None
40
+ )
41
+ assert "My Source Tag" not in useragent
34
42
35
43
config = ConfigBuilder .build (
36
44
api_key = "my-api-key" ,
@@ -46,25 +54,31 @@ def test_source_tag_is_normalized(self):
46
54
source_tag = " My Source Tag 123 #### !! " ,
47
55
)
48
56
useragent = get_user_agent (config )
49
- assert re .search (r"source_tag=my_source_tag_123" , useragent ) is not None
57
+ assert (
58
+ re .search (r"^python-client-\d+\.\d+\.\d+; source_tag=my_source_tag_123$" , useragent )
59
+ is not None
60
+ )
50
61
51
62
config = ConfigBuilder .build (
52
63
api_key = "my-api-key" , host = "https://my-controller-host" , source_tag = "colon:allowed"
53
64
)
54
65
useragent = get_user_agent (config )
55
- assert re .search (r"source_tag=colon:allowed" , useragent ) is not None
66
+ assert (
67
+ re .search (r"^python-client-\d+\.\d+\.\d+; source_tag=colon:allowed$" , useragent )
68
+ is not None
69
+ )
56
70
57
71
def test_user_agent_grpc (self ):
58
72
config = ConfigBuilder .build (api_key = "my-api-key" , host = "https://my-controller-host" )
59
73
useragent = get_user_agent_grpc (config )
60
74
assert re .search (r"python-client\[grpc\]-\d+\.\d+\.\d+" , useragent ) is not None
61
- assert re .search (r"urllib3:\d+\.\d+\.\d+" , useragent ) is not None
62
75
63
76
def test_user_agent_grpc_with_source_tag (self ):
64
77
config = ConfigBuilder .build (
65
78
api_key = "my-api-key" , host = "https://my-controller-host" , source_tag = "my_source_tag"
66
79
)
67
80
useragent = get_user_agent_grpc (config )
68
- assert re .search (r"python-client\[grpc\]-\d+\.\d+\.\d+" , useragent ) is not None
69
- assert re .search (r"urllib3:\d+\.\d+\.\d+" , useragent ) is not None
70
- assert re .search (r"source_tag=my_source_tag" , useragent ) is not None
81
+ assert (
82
+ re .search (r"^python-client\[grpc\]-\d+\.\d+\.\d+; source_tag=my_source_tag$" , useragent )
83
+ is not None
84
+ )
0 commit comments