diff --git a/tests/test_session.py b/tests/test_session.py index b61e715f..2efe82a4 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -18,34 +18,30 @@ class TestSessions: def setup_method(self): self.api_key = "random_api_key" self.event_type = 'test_event_type' - agentops.init(api_key=self.api_key, max_wait_time=5, auto_start_session=False) + self.config = agentops.Configuration(api_key=self.api_key, max_wait_time=50) def test_session(self, mock_req): - # Arrange - agentops.start_session() + agentops.start_session(config=self.config) - # Act + agentops.record(ActionEvent(self.event_type)) agentops.record(ActionEvent(self.event_type)) - # Assert the session has been initiated and the id has been created on backend. + # We should have 1 requests (session start). assert len(mock_req.request_history) == 1 + time.sleep(0.15) - # Act - agentops.record(ActionEvent(self.event_type)) - time.sleep(0.1) - - # Assert an event has been added + # We should have 2 requests (session and 2 events combined into 1) + print(mock_req.last_request.json()) assert len(mock_req.request_history) == 2 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['events'][0]['event_type'] == self.event_type - # Act end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.1) + time.sleep(0.15) - # Since a session has ended, no more events should be recorded, but end_session should be called + # We should have 3 requests (additional end session) assert len(mock_req.request_history) == 3 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() @@ -55,13 +51,14 @@ def test_session(self, mock_req): def test_tags(self, mock_req): # Arrange tags = ['GPT-4'] - agentops.start_session(tags=tags) + agentops.start_session(tags=tags, config=self.config) # Act agentops.record(ActionEvent(self.event_type)) - time.sleep(0.1) + time.sleep(0.15) # Assert 2 requests - 1 for session init, 1 for event + print(mock_req.last_request.json()) assert len(mock_req.request_history) == 2 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() @@ -70,7 +67,7 @@ def test_tags(self, mock_req): # Act end_state = 'Success' agentops.end_session(end_state) - time.sleep(0.1) + time.sleep(0.15) # Assert 3 requets, 1 for session init, 1 for event, 1 for end session assert len(mock_req.request_history) == 3