Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion test_rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import unittest
from typing import Set
import pook # type: ignore

# mocks are stored in file tree
Expand Down Expand Up @@ -32,6 +33,10 @@


class BaseTest(unittest.TestCase):
# mocks that answer more than once, for tests that repeat a request;
# others answer once, which the pagination tests rely on
persistent_mocks: Set[str] = set()

@classmethod
def setUpClass(cls):
cls.maxDiff = None
Expand All @@ -40,4 +45,14 @@ def setUpClass(cls):
for m in mocks:
url = cls.c.BASE + m[0]
# print("register", url)
pook.get(url, reply=200, response_body=m[1])
pook.get(
url,
reply=200,
response_body=m[1],
persist=m[0] in cls.persistent_mocks,
)

@classmethod
def tearDownClass(cls):
# stop pook and drop the mocks, so they don't leak into later classes
pook.off()
3 changes: 3 additions & 0 deletions test_rest/test_dividends.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@


class DividendsTest(BaseTest):
# test_list_stocks_dividends_ticker_any_of requests this twice
persistent_mocks = {"/stocks/v1/dividends?ticker.any_of=AAPL%2CVZ"}

def test_list_dividends(self):
dividends = [d for d in self.c.list_dividends()]
expected = [
Expand Down
3 changes: 3 additions & 0 deletions test_rest/test_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@


class SnapshotsTest(BaseTest):
# test_get_snapshot_indices requests this twice
persistent_mocks = {"/v3/snapshot/indices?ticker.any_of=SPX%2CAPx%2CAPy"}

def test_list_universal_snapshots(self):
expected = [
UniversalSnapshot(
Expand Down
Loading