-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_refresh_external_signals_script.py
More file actions
65 lines (59 loc) · 2.56 KB
/
test_refresh_external_signals_script.py
File metadata and controls
65 lines (59 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import json
import os
import subprocess
import tempfile
import unittest
from pathlib import Path
class RefreshExternalSignalsScriptTests(unittest.TestCase):
def test_script_defaults_oddpool_free_to_search_endpoint_and_quota(self):
root = Path(__file__).resolve().parents[1]
with tempfile.TemporaryDirectory() as tmp:
tmp_path = Path(tmp)
fake_bin = tmp_path / "fake-python"
capture = tmp_path / "args.json"
input_payload = tmp_path / "oddpool.json"
input_payload.write_text(json.dumps({"arbitrages": []}))
fake_bin.write_text(
"#!/usr/bin/env python3\n"
"import json, os, sys\n"
"open(os.environ['CAPTURE'], 'w').write(json.dumps(sys.argv))\n"
)
fake_bin.chmod(0o755)
env_path = root / ".env.local"
old_env = env_path.read_text() if env_path.exists() else None
try:
env_path.write_text(
"ODDPOOL_API_KEY=test-key\n"
"ODDPOOL_API_URL=https://api.oddpool.com/arbitrage/current?min_net_cents=0.5\n"
"ODDPOOL_PLAN=free\n"
"ODDPOOL_SEARCH_LIMIT=7\n"
"SOURCE=oddpool\n"
"PROXY=127.0.0.1:10808\n"
)
env = os.environ.copy()
env.update(
{
"PYTHON_BIN": str(fake_bin),
"CAPTURE": str(capture),
"OUT": str(tmp_path / "external.ndjson"),
"REFRESH_WATCHLIST": "0",
}
)
subprocess.run(["bash", "scripts/refresh_external_signals.sh"], cwd=root, env=env, check=True, capture_output=True, text=True)
argv = json.loads(capture.read_text())
finally:
if old_env is None:
env_path.unlink(missing_ok=True)
else:
env_path.write_text(old_env)
self.assertIn("--url", argv)
self.assertIn("https://api.oddpool.com/search/recent/markets?limit=7", argv)
self.assertNotIn("https://api.oddpool.com/arbitrage/current?min_net_cents=0.5", argv)
self.assertIn("--header", argv)
self.assertIn("X-API-Key=test-key", argv)
self.assertIn("--oddpool-quota-state", argv)
self.assertIn("--oddpool-monthly-quota", argv)
self.assertIn("--proxy", argv)
self.assertIn("127.0.0.1:10808", argv)
if __name__ == "__main__":
unittest.main()