def search_seller(query: str, start: t.Optional[int] = None, limit: t.Optional[int] = None, sortby: t.Optional[t.List[t.Tuple[str, str]]] = None, ) -> t.List[models.Seller]: client = OctopartClient() res = client.search_seller( query=query, start=start, limit=limit, sortby=sortby) return [ models.Seller(res.get('item', {}), strict=False) for res in res.get('results', []) ]
class SellerSearchTests(TestCase): """Tests for the client's search_seller() and get_seller() methods""" def setUp(self): self.client = OctopartClient(api_key='TEST_TOKEN') def test_get_seller(self): with octopart_mock_response() as response: self.client.get_seller('seller_uuid') called_url = request_url_from_request_mock(response) assert '/sellers/seller_uuid' in called_url def test_search_seller(self): response_body = { "__class__": "SearchResponse", "results": [{ "__class__": "SearchResult", "item": { "__class__": "Seller", "display_flag": "US", "has_ecommerce": True, "homepage_url": "http://www.mouser.com", "id": "2401", "name": "Mouser", "uid": "a5e060ea85e77627" } }] } with octopart_mock_response(response_body) as response: dict_ = self.client.search_seller('Mouser') [result] = dict_['results'] assert result['item']['name'] == 'Mouser' called_url = request_url_from_request_mock(response) assert '/sellers/search' in called_url assert 'q=Mouser' in called_url def test_search_seller_with_sortby(self): response_body = { "__class__": "SearchResponse", "results": [{ "__class__": "SearchResult", "item": { "__class__": "Seller", "display_flag": "US", "has_ecommerce": True, "homepage_url": "http://www.mouser.com", "id": "2401", "name": "Mouser", "uid": "a5e060ea85e77627" } }] } with octopart_mock_response(response_body) as response: dict_ = self.client.search_seller('Mouser', sortby=[('name', 'asc')]) assert 'results' in dict_ called_url = request_url_from_request_mock(response) assert '/sellers/search' in called_url assert 'q=Mouser' in called_url assert 'sortby=name+asc' in called_url