コード例 #1
0
ファイル: test_client.py プロジェクト: peeter123/octopart
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
コード例 #2
0
def get_seller(uid: str) -> models.Seller:
    client = OctopartClient()
    slr_dict = client.get_seller(uid)
    return models.Seller(slr_dict, strict=False)