def test_query_data_ref(): """ test_fastrun.test_query_data_ref This hits live wikidata and may change !! This tests that the fast run container correctly queries data from wikidata and stores it in the appropriate format WITH getting references """ frc = wdi_fastrun.FastRunContainer(base_filter={'P699': ''}, base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine, use_refs=True) frc._query_data('P699') # https://www.wikidata.org/wiki/Q10874 assert 'Q10874' in frc.prop_data assert 'P699' in frc.prop_data['Q10874'] # the ID may change, so retrieve it statement_id = list(frc.prop_data['Q10874']['P699'].keys())[0] d = frc.prop_data['Q10874']['P699'][statement_id] # d looks like: """ {'qual': set(), 'ref': {'16c138dfc51df49853f1a9d79f31e2234853842c': {('P248', 'Q30988716'), ('P699', 'DOID:1432'), ('P813', '+2017-07-05T00:00:00Z')}}, 'v': 'DOID:1432'} """ assert all(x in d for x in {'qual', 'ref', 'v'}) assert frc.prop_data['Q10874']['P699'][statement_id]['v'].startswith( 'DOID:') assert len(d['ref']) > 0 ref_id = list(d['ref'].keys())[0] ref = d['ref'][ref_id] assert len(ref) > 1
def test_fast_run(self): qid = 'Q27552312' statements = [ wdi_core.WDExternalID(value='P40095', prop_nr='P352'), wdi_core.WDExternalID(value='YER158C', prop_nr='P705') ] frc = wdi_fastrun.FastRunContainer( base_filter={ 'P352': '', 'P703': 'Q27510868' }, base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine) fast_run_result = frc.write_required(data=statements) if fast_run_result: message = 'fastrun failed' else: message = 'successful fastrun' print(fast_run_result, message) # here, fastrun should succeed, if not, test failed if fast_run_result: raise ValueError
def test_query_data(): """ test_fastrun.test_query_data This hits live wikidata and may change !! This tests that the fast run container correctly queries data from wikidata and stores it in the appropriate format without getting references """ frc = wdi_fastrun.FastRunContainer(base_filter={'P699': ''}, base_data_type=wdi_core.WDBaseDataType, engine=wdi_core.WDItemEngine) # get a string value frc._query_data('P699') # wikidata-item value frc._query_data('P31') # uri value frc._query_data('P1709') # https://www.wikidata.org/wiki/Q10874 assert 'Q10874' in frc.prop_data assert 'P699' in frc.prop_data['Q10874'] # the ID may change, so retrieve it statement_id = list(frc.prop_data['Q10874']['P699'].keys())[0] d = frc.prop_data['Q10874']['P699'][statement_id] # d looks like: {'qual': set(), 'ref': {}, 'v': 'DOID:1432'} assert all(x in d for x in {'qual', 'ref', 'v'}) assert frc.prop_data['Q10874']['P699'][statement_id]['v'].startswith( 'DOID:') # item assert list(frc.prop_data['Q10874']['P31'].values())[0]['v'] == "Q12136" # uri v = set([x['v'] for x in frc.prop_data['Q18211153']['P1709'].values()]) assert all(y.startswith("http") for y in v)