@@ -164,7 +164,7 @@ def test_search_pharmacies_default_search_term(mock_get: MagicMock) -> None:
164164 pharmacy_http .search_pharmacies ()
165165
166166 mock_get .assert_called_once_with (
167- "https://pharmacy-2017071.canvasmedical.com/surescripts/pharmacy/?search=+ " ,
167+ "https://pharmacy-2017071.canvasmedical.com/surescripts/pharmacy/" ,
168168 headers = {},
169169 timeout = 30 ,
170170 )
@@ -176,3 +176,61 @@ def test_search_pharmacies_default_search_term(mock_get: MagicMock) -> None:
176176 headers = {},
177177 timeout = 30 ,
178178 )
179+
180+
181+ @patch ("requests.Session.get" )
182+ def test_search_pharmacies_with_filter_fields (mock_get : MagicMock ) -> None :
183+ """Test that search_pharmacies passes filter fields as query parameters."""
184+ mock_get .return_value = FakeResponse ()
185+
186+ pharmacy_http .search_pharmacies (
187+ search_term = None ,
188+ ncpdp_id = "1234567" ,
189+ organization_name = "CVS" ,
190+ state = "CA" ,
191+ zip_code_prefix = "902" ,
192+ specialty_type = "retail" ,
193+ )
194+
195+ call_url = mock_get .call_args [0 ][0 ]
196+ assert "ncpdp_id=1234567" in call_url
197+ assert "organization_name__icontains=CVS" in call_url
198+ assert "state__iexact=CA" in call_url
199+ assert "zip_code_prefix=902" in call_url
200+ assert "specialty_type__icontains=retail" in call_url
201+ assert "search=" not in call_url
202+
203+
204+ @patch ("requests.Session.get" )
205+ def test_search_pharmacies_with_id (mock_get : MagicMock ) -> None :
206+ """Test that search_pharmacies passes an exact id filter."""
207+ mock_get .return_value = FakeResponse ()
208+
209+ pharmacy_http .search_pharmacies (search_term = None , id = 42 )
210+
211+ call_url = mock_get .call_args [0 ][0 ]
212+ assert "id=42" in call_url
213+
214+
215+ @patch ("requests.Session.get" )
216+ def test_search_pharmacies_with_zip_code_prefix (mock_get : MagicMock ) -> None :
217+ """Test that search_pharmacies passes zip_code_prefix."""
218+ mock_get .return_value = FakeResponse ()
219+
220+ pharmacy_http .search_pharmacies (search_term = None , zip_code_prefix = "902,100,945" )
221+
222+ call_url = mock_get .call_args [0 ][0 ]
223+ assert "zip_code_prefix=902%2C100%2C945" in call_url
224+
225+
226+ @patch ("requests.Session.get" )
227+ def test_search_pharmacies_with_location (mock_get : MagicMock ) -> None :
228+ """Test that latitude and longitude are passed when provided."""
229+ mock_get .return_value = FakeResponse ()
230+
231+ pharmacy_http .search_pharmacies ("walgreens" , latitude = "34.05" , longitude = "-118.24" )
232+
233+ call_url = mock_get .call_args [0 ][0 ]
234+ assert "search=walgreens" in call_url
235+ assert "latitude=34.05" in call_url
236+ assert "longitude=-118.24" in call_url
0 commit comments