def query_suggestion(o: Suggestion): try: en = get_wikidata_result(o.query, o.entity.WIKIDATA_CLASSIFIER_PID) except TooManyResults as e: o.status = Suggestion.Status.MANY_RESULTS o.result = [en.data for en in e.results] o.save() return False except NoResults as e: o.status = Suggestion.Status.NO_RESULTS o.result = None o.save() return False o.status = Suggestion.Status.FOUND_UNVERIFIED o.result = en.data o.source_key = en.id o.source_url = f"http://www.wikidata.org/entity/{en.id}" o.save() return o
def test_get_many_wikidata_result(self): q = "אבא גנוב" msg = 'Too many results: Q6956016, Q12403282, Q7052172' with self.assertRaisesMessage(TooManyResults, msg): get_wikidata_result(q, FILM)
def test_get_no_wikidata_result(self): q = "שדגךלחכישגךלחכישגדךלחכישגךלחכי" with self.assertRaises(NoResults): get_wikidata_result(q, FILM)
def test_get_one_wikidata_result(self): q = "קלרה הקדושה" en = get_wikidata_result(q, FILM) self.assertEqual(en.id, "Q1145082")