1212# See the License for the specific language governing permissions and
1313# limitations under the License.
1414
15- import pytest
1615import functools
1716import time
1817
18+ import pytest
1919from testing_support .fixtures import override_generic_settings
20- from newrelic .core .config import global_settings
21- from newrelic .core .agent_protocol import AgentProtocol
20+
2221from newrelic .common .agent_http import DeveloperModeClient
2322from newrelic .common .encoding_utils import json_encode
24-
23+ from newrelic .core .agent_protocol import AgentProtocol
24+ from newrelic .core .config import global_settings
2525
2626DEFAULT = object ()
2727LINKED_APPLICATIONS = []
2828ENVIRONMENT = []
2929NOW = time .time ()
3030EMPTY_SAMPLES = {
31- ' reservoir_size' : 100 ,
32- ' events_seen' : 0 ,
31+ " reservoir_size" : 100 ,
32+ " events_seen" : 0 ,
3333}
3434
3535
3636_all_endpoints = (
37- (' send_metric_data' , (NOW , NOW + 1 , ())),
38- (' send_transaction_events' , (EMPTY_SAMPLES , ())),
39- (' send_custom_events' , (EMPTY_SAMPLES , ())),
40- (' send_error_events' , (EMPTY_SAMPLES , ())),
41- (' send_transaction_traces' , ([[]],)),
42- (' send_sql_traces' , ([[]],)),
43- (' get_agent_commands' , ()),
44- (' send_profile_data' , ([[]],)),
45- (' send_errors' , ([[]],)),
46- (' send_agent_command_results' , ({0 : {}},)),
47- (' agent_settings' , ({},)),
48- (' send_span_events' , (EMPTY_SAMPLES , ())),
49- (' shutdown_session' , ()),
37+ (" send_metric_data" , (NOW , NOW + 1 , ())),
38+ (" send_transaction_events" , (EMPTY_SAMPLES , ())),
39+ (" send_custom_events" , (EMPTY_SAMPLES , ())),
40+ (" send_error_events" , (EMPTY_SAMPLES , ())),
41+ (" send_transaction_traces" , ([[]],)),
42+ (" send_sql_traces" , ([[]],)),
43+ (" get_agent_commands" , ()),
44+ (" send_profile_data" , ([[]],)),
45+ (" send_errors" , ([[]],)),
46+ (" send_agent_command_results" , ({0 : {}},)),
47+ (" agent_settings" , ({},)),
48+ (" send_span_events" , (EMPTY_SAMPLES , ())),
49+ (" shutdown_session" , ()),
5050)
5151
5252
@@ -85,22 +85,17 @@ def send_request(
8585 )
8686
8787
88- @pytest .mark .parametrize (' headers_map_present' , (True , False ))
88+ @pytest .mark .parametrize (" headers_map_present" , (True , False ))
8989def test_no_blob_behavior (headers_map_present ):
9090 if headers_map_present :
91- connect_response_fields = {u"request_headers_map" : None }
92- client_cls = functools .partial (
93- CustomTestClient , connect_response_fields = connect_response_fields )
91+ connect_response_fields = {"request_headers_map" : None }
92+ client_cls = functools .partial (CustomTestClient , connect_response_fields = connect_response_fields )
9493 else :
95- client_cls = functools .partial (
96- CustomTestClient , connect_response_fields = DEFAULT )
94+ client_cls = functools .partial (CustomTestClient , connect_response_fields = DEFAULT )
9795
9896 protocol = AgentProtocol .connect (
99- 'app_name' ,
100- LINKED_APPLICATIONS ,
101- ENVIRONMENT ,
102- global_settings (),
103- client_cls = client_cls )
97+ "app_name" , LINKED_APPLICATIONS , ENVIRONMENT , global_settings (), client_cls = client_cls
98+ )
10499
105100 protocol .send ("shutdown" )
106101
@@ -111,19 +106,14 @@ def test_no_blob_behavior(headers_map_present):
111106
112107
113108def test_blob ():
114- request_headers_map = {u' X-Foo' : u' Bar' }
115- connect_response_fields = {u "request_headers_map" : request_headers_map }
109+ request_headers_map = {" X-Foo" : " Bar" }
110+ connect_response_fields = {"request_headers_map" : request_headers_map }
116111
117- client_cls = functools .partial (
118- CustomTestClient ,
119- connect_response_fields = connect_response_fields )
112+ client_cls = functools .partial (CustomTestClient , connect_response_fields = connect_response_fields )
120113
121114 protocol = AgentProtocol .connect (
122- 'app_name' ,
123- LINKED_APPLICATIONS ,
124- ENVIRONMENT ,
125- global_settings (),
126- client_cls = client_cls )
115+ "app_name" , LINKED_APPLICATIONS , ENVIRONMENT , global_settings (), client_cls = client_cls
116+ )
127117
128118 protocol .send ("shutdown" )
129119
@@ -134,52 +124,71 @@ def test_blob():
134124 }
135125
136126
137- @override_generic_settings (global_settings (), {
138- 'developer_mode' : True ,
139- })
127+ @override_generic_settings (
128+ global_settings (),
129+ {
130+ "developer_mode" : True ,
131+ },
132+ )
140133def test_server_side_config_precedence ():
141134 connect_response_fields = {
142- u' agent_config' : {u' span_events.enabled' : True },
143- u' span_events.enabled' : False ,
135+ " agent_config" : {" span_events.enabled" : True },
136+ " span_events.enabled" : False ,
144137 }
145- client_cls = functools .partial (
146- CustomTestClient ,
147- connect_response_fields = connect_response_fields )
138+ client_cls = functools .partial (CustomTestClient , connect_response_fields = connect_response_fields )
148139
149140 protocol = AgentProtocol .connect (
150- 'app_name' ,
151- LINKED_APPLICATIONS ,
152- ENVIRONMENT ,
153- global_settings (),
154- client_cls = client_cls )
141+ "app_name" , LINKED_APPLICATIONS , ENVIRONMENT , global_settings (), client_cls = client_cls
142+ )
155143
156144 assert protocol .configuration .span_events .enabled is False
157145
158146
159- @override_generic_settings (global_settings (), {
160- 'developer_mode' : True ,
161- })
162- @pytest .mark .parametrize ("connect_response_fields" ,
163- (
164- {},
165- {"span_event_harvest_config" : {"report_period_ms" : 60000 , "harvest_limit" : 123 }},
166- {"span_event_harvest_config" : {}})
147+ @override_generic_settings (
148+ global_settings (),
149+ {
150+ "developer_mode" : True ,
151+ },
152+ )
153+ @pytest .mark .parametrize (
154+ "connect_response_fields" ,
155+ (
156+ {},
157+ {"span_event_harvest_config" : {"report_period_ms" : 60000 , "harvest_limit" : 123 }},
158+ {"span_event_harvest_config" : {}},
159+ ),
167160)
168161def test_span_event_harvest_config (connect_response_fields ):
169- client_cls = functools .partial (
170- CustomTestClient ,
171- connect_response_fields = connect_response_fields )
162+ client_cls = functools .partial (CustomTestClient , connect_response_fields = connect_response_fields )
172163
173164 protocol = AgentProtocol .connect (
174- 'app_name' ,
175- LINKED_APPLICATIONS ,
176- ENVIRONMENT ,
177- global_settings (),
178- client_cls = client_cls )
165+ "app_name" , LINKED_APPLICATIONS , ENVIRONMENT , global_settings (), client_cls = client_cls
166+ )
179167
180168 if connect_response_fields and connect_response_fields ["span_event_harvest_config" ]:
181169 expected = 123
182170 else :
183171 from newrelic .core .config import SPAN_EVENT_RESERVOIR_SIZE
172+
184173 expected = SPAN_EVENT_RESERVOIR_SIZE
185174 assert protocol .configuration .event_harvest_config .harvest_limits .span_event_data == expected
175+
176+
177+ @override_generic_settings (
178+ global_settings (),
179+ {
180+ "developer_mode" : True ,
181+ },
182+ )
183+ @pytest .mark .parametrize ("connect_response_fields" , ({}, {"collect_ai" : True }, {"collect_ai" : False }))
184+ def test_account_level_aim (connect_response_fields ):
185+ client_cls = functools .partial (CustomTestClient , connect_response_fields = connect_response_fields )
186+
187+ protocol = AgentProtocol .connect (
188+ "app_name" , LINKED_APPLICATIONS , ENVIRONMENT , global_settings (), client_cls = client_cls
189+ )
190+
191+ if connect_response_fields and connect_response_fields ["collect_ai" ]:
192+ assert protocol .configuration .ai_monitoring .enabled == connect_response_fields ["collect_ai" ]
193+ else :
194+ assert protocol .configuration .ai_monitoring .enabled is False
0 commit comments