Skip to content

Commit ba9a0cd

Browse files
committed
test: fix 100% coverage on Python 3.13
Add tests for copytrack fetch username resolution, fetch SimError path, and web resolve get_profile exception fallback.
1 parent c0283c3 commit ba9a0cd

2 files changed

Lines changed: 45 additions & 0 deletions

File tree

tests/test_cli.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1178,6 +1178,37 @@ def test_copytrack_fetch(self, runner, data_dir, httpx_mock):
11781178
assert data["data"]["trades_fetched"] == 1
11791179
assert data["data"]["redeems_fetched"] == 0
11801180

1181+
def test_copytrack_fetch_username_resolution(self, runner, data_dir, httpx_mock):
1182+
"""Cover username resolution path in copytrack_fetch (line 929)."""
1183+
_invoke(runner, ["init"], data_dir)
1184+
httpx_mock.add_response(
1185+
url="https://polymarket.com/@testuser",
1186+
text='<script id="__NEXT_DATA__" type="application/json">{"props":{"pageProps":{"address":"0xresolved"}}}</script>',
1187+
)
1188+
httpx_mock.add_response(
1189+
url="https://data-api.polymarket.com/activity?user=0xresolved&type=TRADE&limit=500&sortBy=TIMESTAMP&sortDirection=DESC",
1190+
json=[],
1191+
)
1192+
httpx_mock.add_response(
1193+
url="https://data-api.polymarket.com/activity?user=0xresolved&type=REDEEM&limit=500&sortBy=TIMESTAMP&sortDirection=DESC",
1194+
json=[],
1195+
)
1196+
result = _invoke(runner, ["copytrack", "fetch", "@testuser"], data_dir)
1197+
data = _parse(result)
1198+
assert data["ok"] is True
1199+
assert data["data"]["trades_fetched"] == 0
1200+
1201+
def test_copytrack_fetch_error(self, runner, data_dir, httpx_mock):
1202+
"""Cover the SimError catch in copytrack_fetch (lines 937-939)."""
1203+
httpx_mock.add_response(
1204+
url="https://polymarket.com/@baduser",
1205+
text="<html>no data</html>",
1206+
)
1207+
result = _invoke(runner, ["copytrack", "fetch", "@baduser"], data_dir)
1208+
data = _parse(result)
1209+
assert data["ok"] is False
1210+
assert result.exit_code == 1
1211+
11811212
def test_copytrack_replay(self, runner, data_dir):
11821213
# Init account and add target
11831214
_invoke(runner, ["init"], data_dir)

tests/test_web/test_copytrack.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,20 @@ def test_resolve_username(self, initialized_client, httpx_mock):
227227
assert data["data"]["address"] == "0xabc123"
228228
assert data["data"]["username"] == "testuser"
229229

230+
def test_resolve_address_profile_error(self, initialized_client, httpx_mock):
231+
"""Cover exception fallback in resolve when get_profile fails (lines 110-111)."""
232+
httpx_mock.add_response(
233+
url="https://gamma-api.polymarket.com/public-profile?address=0xd8f8c13644ea84d62e1ec88c5d1215e436eb0f11",
234+
status_code=500,
235+
)
236+
resp = initialized_client.post("/api/copytrack/resolve", json={
237+
"identifier": "0xd8f8c13644ea84d62e1ec88c5d1215e436eb0f11",
238+
})
239+
data = resp.json()
240+
assert data["ok"] is True
241+
assert data["data"]["address"] == "0xd8f8c13644ea84d62e1ec88c5d1215e436eb0f11"
242+
assert data["data"]["username"] == "0xd8f8c136..."
243+
230244
def test_resolve_bad_username(self, initialized_client, httpx_mock):
231245
httpx_mock.add_response(url="https://polymarket.com/@bad", status_code=404)
232246
resp = initialized_client.post("/api/copytrack/resolve", json={

0 commit comments

Comments
 (0)