Skip to content

Commit

Permalink
fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
siyangqiu committed Apr 4, 2024
1 parent cdcce4a commit d7814eb
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions tests/test_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d7814eb

Please sign in to comment.