Esempio n. 1
0
    def test_match_include_directives(self):
        with octopart_mock_response() as rsps:
            api.match(['MPN1', 'MPN2'],
                      include_imagesets=True,
                      include_cad_models=True)
            called_url = request_url_from_request_mock(rsps)

            # %22mpn%22%3A+%22MPN1%22 is "mpn": "MPN1"
            assert '%22mpn_or_sku%22%3A+%22MPN1%22' in called_url
            # %22mpn%22%3A+%22MPN2%22 is "mpn": "MPN2"
            assert '%22mpn_or_sku%22%3A+%22MPN2%22' in called_url
            assert 'include%5B%5D=imagesets' in called_url  # %5B%5D is []
            assert 'include%5B%5D=cad_models' in called_url
Esempio n. 2
0
    def test_match_parts_by_seller(self):
        """
        Tests that including specific sellers in `match` call
        passes those values to Octopart.
        """
        # Mock out all calls to match endpoint.
        url_regex = re.compile(r'https://octopart\.com/api/v3/parts/match.*')
        responses.add(
            responses.GET,
            url_regex,
            json=fixtures.parts_match_multiple_sellers_response,
            status=200,
            content_type='application/json'
        )

        results = api.match(['RUM001L02T2CL'], sellers=['Digi-Key', 'Mouser'])

        assert len(results) == 2
        for result in results:
            assert isinstance(result, models.PartsMatchResult)
            for part in result.parts:
                assert part.mpn == 'RUM001L02T2CL'
                sellers = [offer.seller for offer in part.offers]
                # NOTE: shouldn't assert that other sellers are absent from
                # this list, since they actually can be present in responses
                # that include the `sellers` field in queries.
                assert 'Digi-Key' in sellers
                assert 'Mouser' in sellers
Esempio n. 3
0
    def test_parts_match(self):
        """Tests that `match` returns part matches"""
        # Mock out all calls to match endpoint.
        url_regex = re.compile(r'https://octopart\.com/api/v3/parts/match.*')
        responses.add(responses.GET,
                      url_regex,
                      json=fixtures.parts_match_response,
                      status=200,
                      content_type='application/json')

        results = api.match(['RUM001L02T2CL'])

        assert len(results) == 1
        result = results[0]
        assert isinstance(result, models.PartsMatchResult)

        assert len(result.parts) == 1
        part = result.parts[0]
        assert isinstance(part, models.Part)
        assert part.mpn == 'RUM001L02T2CL'
        assert part.manufacturer == 'Rohm'

        assert len(part.offers) == 19
        offer = part.offers[0]
        assert isinstance(offer, models.PartOffer)

        assert offer.prices == {
            'USD': {
                8000: 0.05250,
                16000: 0.04463,
                24000: 0.04200,
                56000: 0.03938
            }
        }
Esempio n. 4
0
    def test_parts_match_extra_fields(self):
        """
        Tests that `match` returns matches with additional part-related data.
        """
        # Mock out all calls to match endpoint.
        url_regex = re.compile(r'https://octopart\.com/api/v3/parts/match.*')
        responses.add(
            responses.GET,
            url_regex,
            json=fixtures.parts_match_extra_fields_response,
            status=200,
            content_type='application/json'
        )

        results = api.match(
            ['RUM001L02T2CL'],
            specs=True,
            imagesets=True,
            descriptions=True)

        assert len(results) == 1
        result = results[0]
        assert len(result.parts) == 1
        part = result.parts[0]
        assert part.mpn == 'RUM001L02T2CL'

        assert part.specs['packaging'].value == ['Tape & Reel (TR)']
        assert part.specs['lead_free_status'].value == ['Lead Free']
        assert part.specs['rohs_status'].value == ['Compliant']
        assert part.specs['mounting_style'].value == ['Surface Mount']
        assert part.specs['polarity'].value == ['N-Channel']

        assert len(part.imagesets) == 3
        imageset = part.imagesets[0]
        assert imageset.image_urls == {
            'medium_image': 'https://sigma.octopart.com/67745388/image/Rohm-RUM001L02T2CL.jpg',  # noqa
            'small_image': 'https://sigma.octopart.com/66829790/image/Rohm-RUM001L02T2CL.jpg',  # noqa
            'swatch_image': 'https://sigma.octopart.com/23299222/image/Rohm-RUM001L02T2CL.jpg'  # noqa
        }

        assert len(part.descriptions) == 9
        assert part.descriptions == [
            'MOSFET, N-CH, 20V, 0.1A, VMT',
            'Trans MOSFET N-CH 20V 0.1A 3-Pin VMT T/R',
            'MOSFET N-channel 20V 100mA SOT723',
            'MOSFET N-CH 20V 0.1A VMT3',
            'Trans MOSFET N-CH 20V 0.1A 3-Pin VMT T/R',
            'MOSFET, N-CH, 20V, 0.1A, VMT',
            'Trans MOSFET N-CH 20V 0.1A 3-Pin VMT T/R',
            'Trans MOSFET N-CH 20V 0.1A 3-Pin VMT T/R',
            'RUM001L02 Series 20 V 3.5 Ohm 100 mA N-Ch. Small Signal Mosfet - SOT-723 (VMT3)'  # noqa
        ]