Exemplo n.º 1
0
 def testWikidataCityStates(self):
     '''
     test getting region information from wikidata
     '''
     wikidata = Wikidata()
     try:
         regionList = wikidata.getCityStates()
         self.assertTrue(len(regionList) >= 2)
         cityStateNames = [r.get('name') for r in regionList]
         self.assertTrue("Singapore" in cityStateNames)
     except Exception as ex:
         self.handleWikidataException(ex)
         pass
 def testCityFromCityStates(self):
     '''
     tests if city states are queried correctly if given the region
     For city states the city is region and city (in some cases also country).
     This test ensures that by querying for the cities of a region the city states include themself in the result
     (the result for cities in city-states often includes the municipalities)
     '''
     wd = Wikidata()
     cityStateRecords = wd.getCityStates()
     for cityStateRecord in cityStateRecords:
         regionId = cityStateRecord.get('wikidataid')
         regionCities = wd.getCitiesForRegion(
             regionId,
             msg=f"Query for cities in {cityStateRecord.get('name')}")
         foundCities = [c.get('wikidataid') for c in regionCities]
         self.assertTrue(regionId in foundCities)