From 0cfdf4f12ef7b707eaa7031fd86a48fc87c570b4 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Mon, 19 Aug 2019 11:18:56 +0200 Subject: digikey-search-parts: assert that the part we got was actually the one we searched for. --- src/ee/digikey/search_parts.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/ee') diff --git a/src/ee/digikey/search_parts.py b/src/ee/digikey/search_parts.py index 144b254..eace4e3 100644 --- a/src/ee/digikey/search_parts.py +++ b/src/ee/digikey/search_parts.py @@ -2,6 +2,7 @@ import functools from pathlib import Path from typing import List, MutableSet, Mapping +from ee import EeException from ee.db import ObjDb from ee.digikey import Digikey, DigikeyParser, DigikeyClient, SearchResponseTypes, DigikeyProduct, DigikeyStore from ee.part import PartDb, load_db, save_db, Part @@ -92,6 +93,13 @@ class QueryEngine(object): result = "exception" elif response.response_type == SearchResponseTypes.SINGLE: out_part = resolved(self.store.url, response.products[0]) + + out_pn = out_part.get_exactly_one_spn() if is_spn else out_part.get_exactly_one_mpn() + out_pn = out_pn.valueProp + if out_pn != pn: + raise EeException("Internal error: returned PN/SPN didn't match expected parts: " + "query: {} vs returned: {}".format(pn, out_pn)) + result = "found" elif response.response_type == SearchResponseTypes.MANY: # TODO: order by spn/mpn so the output is consistent between runs. -- cgit v1.2.3