Best Python code snippet using localstack_python
test_service_call_aggregator.py
Source:test_service_call_aggregator.py
...9 EVENT_NAME,10 ServiceRequestAggregator,11 ServiceRequestInfo,12)13def test_whitebox_create_analytics_payload():14 agg = ServiceRequestAggregator()15 agg.add_request(ServiceRequestInfo("test1", "test", 200, None))16 agg.add_request(ServiceRequestInfo("test1", "test", 200, None))17 agg.add_request(ServiceRequestInfo("test2", "test", 404, "ResourceNotFound"))18 agg.add_request(ServiceRequestInfo("test3", "test", 200, None))19 payload = agg._create_analytics_payload()20 aggregations = payload["api_calls"]21 assert len(aggregations) == 322 period_start = dateutil.parser.isoparse(payload["period_start_time"])23 period_end = dateutil.parser.isoparse(payload["period_end_time"])24 assert period_end > period_start25 for record in aggregations:26 service = record["service"]27 if service == "test1":28 assert record["count"] == 229 assert "err_type" not in record30 elif service == "test2":31 assert record["count"] == 132 assert record["err_type"] == "ResourceNotFound"33 elif service == "test3":...
service_request_aggregator.py
Source:service_request_aggregator.py
...77 with self._mutex:78 try:79 if len(self.counter) == 0:80 return81 analytics_payload = self._create_analytics_payload()82 self._emit_payload(analytics_payload)83 self.counter.clear()84 finally:85 self._period_start_time = datetime.datetime.utcnow()86 def _create_analytics_payload(self):87 return {88 "period_start_time": self._period_start_time.isoformat() + "Z",89 "period_end_time": datetime.datetime.utcnow().isoformat() + "Z",90 "api_calls": self._aggregate_api_calls(self.counter),91 }92 def _aggregate_api_calls(self, counter) -> List:93 aggregations = []94 for api_call_info, count in counter.items():95 doc = api_call_info._asdict()96 for field in OPTIONAL_FIELDS:97 if doc.get(field) is None:98 del doc[field]99 doc["count"] = count100 aggregations.append(doc)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!