Skip to content

Commit

Permalink
move req mocks to general conftest, and apply global mock to HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
teocns committed Nov 27, 2024
1 parent 50fe4ff commit 39f2038
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
24 changes: 23 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1 +1,23 @@
pass
import pytest
import requests_mock

# from agentops.http_client import HttpStatus, Response
# @pytest.fixture(autouse=True)
# def mock_http_client():
# # Mock the batch method specifically
# with mock.patch("agentops.http_client.HttpClient.post") as mock_post:
# mock_post.return_value = Response(status=HttpStatus.SUCCESS, body={"status": "ok"})
# yield mock_post


@pytest.fixture(autouse=True, scope="session")
def mock_req():
with requests_mock.Mocker() as m:
url = "https://api.agentops.ai"
m.post(url + "/v2/create_events", json={"status": "ok"})
m.post(url + "/v2/create_session", json={"status": "success", "jwt": "some_jwt"})
m.post(url + "/v2/reauthorize_jwt", json={"status": "success", "jwt": "some_jwt"})
m.post(url + "/v2/update_session", json={"status": "success", "token_cost": 5})
m.post(url + "/v2/developer_errors", json={"status": "ok"})
m.post("https://pypi.org/pypi/agentops/json", status_code=404)
yield m
12 changes: 0 additions & 12 deletions tests/session/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,3 @@ def session(mock_req):
# Clear all sessions
agentops.end_all_sessions()


@pytest.fixture(autouse=True, scope="function")
def mock_req():
with requests_mock.Mocker() as m:
url = "https://api.agentops.ai"
m.post(url + "/v2/create_events", json={"status": "ok"})
m.post(url + "/v2/create_session", json={"status": "success", "jwt": "some_jwt"})
m.post(url + "/v2/reauthorize_jwt", json={"status": "success", "jwt": "some_jwt"})
m.post(url + "/v2/update_session", json={"status": "success", "token_cost": 5})
m.post(url + "/v2/developer_errors", json={"status": "ok"})
m.post("https://pypi.org/pypi/agentops/json", status_code=404)
yield m

0 comments on commit 39f2038

Please sign in to comment.