Skip to content

Commit 77e1084

Browse files
author
clickingbuttons
authored
move mocks to json files (#147)
* move mocks to json files on disk * fix style
1 parent cd6d379 commit 77e1084

34 files changed

+1525
-121
lines changed

tests/base.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
from polygon import RESTClient
2+
3+
import os
4+
import unittest
5+
import httpretty # type: ignore
6+
7+
# mocks are stored in file tree
8+
mocks = []
9+
dirname = os.path.dirname(__file__)
10+
mockdir = os.path.join(dirname, "mocks")
11+
for dname, _, files in os.walk(mockdir):
12+
for fname in files:
13+
if fname.endswith(".json"):
14+
abspath = os.path.join(dname, fname)
15+
with open(abspath, "r") as f:
16+
urllpath = abspath.replace(mockdir, "").replace(".json", "")
17+
mocks.append((urllpath, f.read()))
18+
# print('load', urllpath)
19+
20+
21+
class BaseTest(unittest.TestCase):
22+
@classmethod
23+
def setUpClass(cls):
24+
cls.maxDiff = None
25+
cls.c = RESTClient("", verbose=True)
26+
httpretty.enable(verbose=True, allow_net_connect=False)
27+
for m in mocks:
28+
url = cls.c.BASE + m[0]
29+
# print('register', url)
30+
httpretty.register_uri(httpretty.GET, url, m[1], match_querystring=True)

tests/mocks.py

Lines changed: 0 additions & 110 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"last": {
3+
"conditions": [
4+
2
5+
],
6+
"exchange": 2,
7+
"price": 39976.89682331,
8+
"size": 0.005,
9+
"timestamp": 1651180409688
10+
},
11+
"request_id": "d67c9bfe1fa0c29db9177d78b3ab713c",
12+
"status": "success",
13+
"symbol": "BTC-USD"
14+
}

tests/mocks/v1/marketstatus/now.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"market": "extended-hours",
3+
"earlyHours": false,
4+
"afterHours": true,
5+
"serverTime": "2022-04-28T16:48:08-04:00",
6+
"exchanges": {
7+
"nyse": "extended-hours",
8+
"nasdaq": "extended-hours",
9+
"otc": "extended-hours"
10+
},
11+
"currencies": {
12+
"fx": "open",
13+
"crypto": "open"
14+
}
15+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[
2+
{
3+
"exchange": "NYSE",
4+
"name": "Memorial Day",
5+
"date": "2022-05-30",
6+
"status": "closed"
7+
},
8+
{
9+
"exchange": "NASDAQ",
10+
"name": "Memorial Day",
11+
"date": "2022-05-30",
12+
"status": "closed"
13+
},
14+
{
15+
"exchange": "NASDAQ",
16+
"name": "Juneteenth",
17+
"date": "2022-06-20",
18+
"status": "closed"
19+
},
20+
{
21+
"exchange": "NYSE",
22+
"name": "Juneteenth",
23+
"date": "2022-06-20",
24+
"status": "closed"
25+
},
26+
{
27+
"exchange": "NYSE",
28+
"name": "Independence Day",
29+
"date": "2022-07-04",
30+
"status": "closed"
31+
},
32+
{
33+
"exchange": "NASDAQ",
34+
"name": "Independence Day",
35+
"date": "2022-07-04",
36+
"status": "closed"
37+
},
38+
{
39+
"exchange": "NYSE",
40+
"name": "Labor Day",
41+
"date": "2022-09-05",
42+
"status": "closed"
43+
},
44+
{
45+
"exchange": "NASDAQ",
46+
"name": "Labor Day",
47+
"date": "2022-09-05",
48+
"status": "closed"
49+
},
50+
{
51+
"exchange": "NYSE",
52+
"name": "Thanksgiving",
53+
"date": "2022-11-24",
54+
"status": "closed"
55+
},
56+
{
57+
"exchange": "NASDAQ",
58+
"name": "Thanksgiving",
59+
"date": "2022-11-24",
60+
"status": "closed"
61+
},
62+
{
63+
"exchange": "NYSE",
64+
"name": "Thanksgiving",
65+
"date": "2022-11-25",
66+
"status": "early-close",
67+
"open": "2022-11-25T14:30:00.000Z",
68+
"close": "2022-11-25T18:00:00.000Z"
69+
},
70+
{
71+
"exchange": "NASDAQ",
72+
"name": "Thanksgiving",
73+
"date": "2022-11-25",
74+
"status": "early-close",
75+
"open": "2022-11-25T14:30:00.000Z",
76+
"close": "2022-11-25T18:00:00.000Z"
77+
},
78+
{
79+
"exchange": "NYSE",
80+
"name": "Christmas",
81+
"date": "2022-12-26",
82+
"status": "closed"
83+
},
84+
{
85+
"exchange": "NASDAQ",
86+
"name": "Christmas",
87+
"date": "2022-12-26",
88+
"status": "closed"
89+
}
90+
]
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"status": "OK",
3+
"from": "2021-04-01",
4+
"symbol": "AAPL",
5+
"open": 123.66,
6+
"high": 124.18,
7+
"low": 122.49,
8+
"close": 123,
9+
"volume": 75089134,
10+
"afterHours": 123,
11+
"preMarket": 123.45
12+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"queryCount": 1,
3+
"resultsCount": 1,
4+
"adjusted": true,
5+
"results": [
6+
{
7+
"T": "GIK",
8+
"v": 895345,
9+
"vw": 9.9979,
10+
"o": 9.99,
11+
"c": 10.02,
12+
"h": 10.02,
13+
"l": 9.9,
14+
"t": 1602705600000,
15+
"n": 96
16+
}
17+
],
18+
"status": "OK",
19+
"request_id": "eae3ded2d6d43f978125b7a8a609fad9",
20+
"count": 1
21+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"ticker": "AAPL",
3+
"queryCount": 1,
4+
"resultsCount": 1,
5+
"adjusted": true,
6+
"results": [
7+
{
8+
"T": "AAPL",
9+
"v": 95595226.0,
10+
"vw": 158.6074,
11+
"o": 162.25,
12+
"c": 156.8,
13+
"h": 162.34,
14+
"l": 156.72,
15+
"t": 1651003200000,
16+
"n": 899965
17+
}
18+
],
19+
"status": "OK",
20+
"request_id": "5e5378d5ecaf3df794bb52e45d015d2e",
21+
"count": 1
22+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"ticker": "AAPL",
3+
"queryCount": 2,
4+
"resultsCount": 2,
5+
"adjusted": true,
6+
"results": [
7+
{
8+
"v": 642646396.0,
9+
"vw": 1.469,
10+
"o": 1.5032,
11+
"c": 1.4604,
12+
"h": 1.5064,
13+
"l": 1.4489,
14+
"t": 1112331600000,
15+
"n": 82132
16+
},
17+
{
18+
"v": 578172308.0,
19+
"vw": 1.4589,
20+
"o": 1.4639,
21+
"c": 1.4675,
22+
"h": 1.4754,
23+
"l": 1.4343,
24+
"t": 1112587200000,
25+
"n": 65543
26+
}
27+
],
28+
"status": "OK",
29+
"request_id": "12afda77aab3b1936c5fb6ef4241ae42",
30+
"count": 2
31+
}

tests/mocks/v2/last/trade/AAPL.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"results": {
3+
"c": [
4+
12,
5+
37
6+
],
7+
"i": "237688",
8+
"p": 166.25,
9+
"s": 2,
10+
"x": 4,
11+
"r": 202,
12+
"z": 3,
13+
"T": "AAPL",
14+
"t": 1651179319310617300,
15+
"y": 1651179319308000000,
16+
"f": 1651179319310588400,
17+
"q": 7084210
18+
},
19+
"status": "OK",
20+
"request_id": "d4bafa50e72cf9ed19ac538ae1a3185a"
21+
}

0 commit comments

Comments
 (0)