55import httpx
66import pytest
77
8- from edgar .httpclient import async_http_client
8+ from edgar .httpclient import async_http_client , get_edgar_verify_ssl
99
1010from edgar .httprequests import (
1111 get_with_retry ,
1616 TooManyRequestsError ,
1717 IdentityNotSetException ,
1818 download_file ,
19- download_text_between_tags
19+ download_text_between_tags ,
2020)
2121
2222
@@ -48,16 +48,17 @@ def test_get_with_retry_for_redirect(status_code, monkeypatch):
4848 with patch ("httpx.Client.get" , return_value = mock_response ):
4949 with patch ("edgar.httprequests.get_with_retry" ) as mock_retry :
5050 get_with_retry (url = "http://example.com" )
51- mock_retry .assert_called_once_with (url = "http://example.com/redirected" ,
52- identity = os .environ ['EDGAR_IDENTITY' ],
53- headers = {'User-Agent' : 'Dev Gunning developer-gunning@gmail.com' },
54- identity_callable = None )
51+ mock_retry .assert_called_once_with (
52+ url = "http://example.com/redirected" ,
53+ identity = os .environ ["EDGAR_IDENTITY" ],
54+ headers = {"User-Agent" : "Dev Gunning developer-gunning@gmail.com" },
55+ identity_callable = None ,
56+ )
5557
5658
5759@pytest .mark .asyncio
5860@pytest .mark .parametrize ("status_code" , [200 , 429 ])
5961async def test_get_with_retry_async (status_code ):
60-
6162 async with async_http_client () as client :
6263 mock_response = httpx .Response (status_code = status_code )
6364 with patch ("httpx.AsyncClient.get" , return_value = mock_response ):
@@ -84,10 +85,13 @@ async def test_get_with_retry_async_for_redirect(status_code):
8485 with patch ("httpx.Client.get" , return_value = mock_response ):
8586 with patch ("edgar.httprequests.get_with_retry" ) as mock_retry :
8687 get_with_retry (url = "http://example.com" )
87- mock_retry .assert_called_once_with (url = "http://example.com/redirected" ,
88- identity = os .environ ['EDGAR_IDENTITY' ],
89- headers = {'User-Agent' : 'Dev Gunning developer-gunning@gmail.com' },
90- identity_callable = None )
88+ mock_retry .assert_called_once_with (
89+ url = "http://example.com/redirected" ,
90+ identity = os .environ ["EDGAR_IDENTITY" ],
91+ headers = {"User-Agent" : "Dev Gunning developer-gunning@gmail.com" },
92+ identity_callable = None ,
93+ )
94+
9195
9296def test_post_with_retry ():
9397 mock_response = httpx .Response (status_code = 200 )
@@ -139,9 +143,10 @@ def test_identity_from_environment_variable(monkeypatch):
139143@pytest .mark .asyncio
140144async def test_get_daily_index_url_async ():
141145 async with async_http_client () as client :
142-
143- urls = ['https://www.sec.gov/Archives/edgar/daily-index/2024/QTR2/form.20240502.idx' ,
144- 'https://www.sec.gov/Archives/edgar/daily-index/2024/QTR2/form.20240502.idx' ]
146+ urls = [
147+ "https://www.sec.gov/Archives/edgar/daily-index/2024/QTR2/form.20240502.idx" ,
148+ "https://www.sec.gov/Archives/edgar/daily-index/2024/QTR2/form.20240502.idx" ,
149+ ]
145150 # Use asyncio to run get_with_retry_async
146151 tasks = [get_with_retry_async (client = client , url = url ) for url in urls ]
147152 results = await asyncio .gather (* tasks )
@@ -150,18 +155,33 @@ async def test_get_daily_index_url_async():
150155
151156
152157def test_download_index_file ():
153- xbrl_gz = download_file (' https://www.sec.gov/Archives/edgar/full-index/2021/QTR1/xbrl.gz' )
158+ xbrl_gz = download_file (" https://www.sec.gov/Archives/edgar/full-index/2021/QTR1/xbrl.gz" )
154159 assert isinstance (xbrl_gz , bytes )
155160 assert len (xbrl_gz ) > 10000
156161
157- xbrl_idx = download_file (' https://www.sec.gov/Archives/edgar/full-index/2021/QTR1/xbrl.idx' )
162+ xbrl_idx = download_file (" https://www.sec.gov/Archives/edgar/full-index/2021/QTR1/xbrl.idx" )
158163 assert isinstance (xbrl_idx , str )
159164
160165
161166def test_get_text_between_tags ():
162- text = download_text_between_tags (
163- 'https://www.sec.gov/Archives/edgar/data/1009672/000156459018004771/0001564590-18-004771.txt' ,
164- 'SEC-HEADER' )
165- assert 'ACCESSION NUMBER: 0001564590-18-004771' in text
167+ text = download_text_between_tags ("https://www.sec.gov/Archives/edgar/data/1009672/000156459018004771/0001564590-18-004771.txt" , "SEC-HEADER" )
168+ assert "ACCESSION NUMBER: 0001564590-18-004771" in text
166169 assert text .strip ().endswith ("77079" )
167170
171+
172+ def test_edgar_verify_ssl (monkeypatch ):
173+ # True when env variable doesn't exist
174+ monkeypatch .delenv ("EDGAR_VERIFY_SSL" , raising = False )
175+ assert get_edgar_verify_ssl ()
176+
177+ # True when env variable set to true
178+ monkeypatch .setenv ("EDGAR_VERIFY_SSL" , "true" )
179+ assert get_edgar_verify_ssl ()
180+
181+ # True when env variable set to undefined value
182+ monkeypatch .setenv ("EDGAR_VERIFY_SSL" , "unknown" )
183+ assert get_edgar_verify_ssl ()
184+
185+ # False when env variable set to false
186+ monkeypatch .setenv ("EDGAR_VERIFY_SSL" , "false" )
187+ assert not get_edgar_verify_ssl ()
0 commit comments