Skip to content

Commit

Permalink
added concat_method to baseclient and test for requestoptions
Browse files Browse the repository at this point in the history
  • Loading branch information
antdjohns authored and jbonzo committed Dec 9, 2022
1 parent cb14228 commit cf97d0d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
2 changes: 0 additions & 2 deletions polygon/rest/aggs.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ def get_grouped_daily_aggs(
options=options,
)

# TODO: next breaking change release move "market_type" to be 2nd mandatory
# param
def get_daily_open_close_agg(
self,
ticker: str,
Expand Down
10 changes: 6 additions & 4 deletions polygon/rest/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ def _get(
self.BASE + path,
fields=params,
retries=self.retries,
headers={
**option.edge_headers,
**self.headers,
}, # merge supplied headers with standard headers
headers=self._concat_headers(
option.edge_headers
), # merge supplied headers with standard headers
)

if resp.status != 200:
Expand Down Expand Up @@ -160,6 +159,9 @@ def _get_params(

return params

def _concat_headers(self, headers: Dict[str, str]) -> Dict[str, str]:
return {**headers, **self.headers}

def _paginate_iter(
self,
path: str,
Expand Down
21 changes: 21 additions & 0 deletions test_rest/models/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import unittest

from polygon import RESTClient
from polygon.rest.models.request import (
RequestOptionBuilder,
X_POLYGON_EDGE_ID,
Expand Down Expand Up @@ -48,3 +49,23 @@ def test_request_options_builder(self):

options = options.optional_edge_headers("test")
self.assertDictEqual(all_options, options.edge_headers)

def test_header_combination(self):
client = RESTClient(api_key="test")
options = RequestOptionBuilder(
edge_id="test", edge_ip_address="test", edge_user="test"
)

# this mocks the expected behavior during the request.get function call
# in the BaseClient.
headers = client._concat_headers(options.edge_headers)

expected_headers = {
"Authorization": "Bearer test",
"User-Agent": "Polygon.io PythonClient/0.0.0",
"X-Polygon-Edge-ID": "test",
"X-Polygon-Edge-IP-Address": "test",
"X-Polygon-Edge-User-Agent": "test",
}

self.assertDictEqual(headers, expected_headers)

0 comments on commit cf97d0d

Please sign in to comment.