diff --git a/tests/test_session.py b/tests/test_session.py index b61e715f..be91f310 100644 --- a/tests/test_session.py +++ b/tests/test_session.py @@ -21,32 +21,28 @@ def setup_method(self): agentops.init(api_key=self.api_key, max_wait_time=5, auto_start_session=False) def test_session(self, mock_req): - # Arrange agentops.start_session() - # Act 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). The action event should still be in queue assert len(mock_req.request_history) == 1 - # Act agentops.record(ActionEvent(self.event_type)) time.sleep(0.1) - # Assert an event has been added - assert len(mock_req.request_history) == 2 + # We should have 3 requests (session and 2 events) + 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() assert request_json['events'][0]['event_type'] == self.event_type - # Act end_state = 'Success' agentops.end_session(end_state) time.sleep(0.1) - # Since a session has ended, no more events should be recorded, but end_session should be called - assert len(mock_req.request_history) == 3 + # We should have 4 requests (additional end session) + assert len(mock_req.request_history) == 4 assert mock_req.last_request.headers['X-Agentops-Auth'] == self.api_key request_json = mock_req.last_request.json() assert request_json['session']['end_state'] == end_state