class BrandSearchTests(TestCase): """Tests for the client's search_brand() and get_brand() methods""" def setUp(self): self.client = OctopartClient(api_key='TEST_TOKEN') def test_get_brand(self): response_body = { "__class__": "Brand", "homepage_url": "http://www.newark.com", "name": "Newark", "uid": "98785972bc7c4fbf" } with octopart_mock_response(response_body) as response: brand = self.client.get_brand('98785972bc7c4fbf') assert brand['uid'] == '98785972bc7c4fbf' called_url = request_url_from_request_mock(response) assert '/brands/98785972bc7c4fbf' in called_url def test_search_brand(self): response_body = { "__class__": "SearchResponse", "results": [{ "__class__": "SearchResult", "item": { "__class__": "Brand", "homepage_url": "http://www.newark.com", "name": "Newark", "uid": "98785972bc7c4fbf" } }] } with octopart_mock_response(response_body) as response: response_data = self.client.search_brand('Newark') [result] = response_data['results'] assert result['item']['name'] == 'Newark' called_url = request_url_from_request_mock(response) assert '/brands/search' in called_url assert 'q=Newark' in called_url
def get_brand(uid: str) -> models.Brand: client = OctopartClient() brand_dict = client.get_brand(uid) return models.Brand(brand_dict)