def test_requestCoordinates(self): REQUET_ADDRESS_LIST.append(TEST_SEARCH) REQUET_ADDRESS_LIST.append(TEST_SEARCH) GeonamesRequestSender.requestCoordinates( REQUET_ADDRESS_LIST, GEONAMES_LOGIN, callback_test) self.assertEqual(RESPONSE_REQUEST_COORDINATES[0], RESPONSE_SINGLE1) self.assertEqual(RESPONSE_REQUEST_COORDINATES[1], RESPONSE_SINGLE1)
def test_exceed_limit_week_period(self): try: GeonamesRequestSender.checkResponseForException( json.dumps(RESPONSE_FOR_LIMIT_EXCEED_WEEK)) except GeocoderRequestLimitExceed as e: self.assertEqual(WEEK_PERIOD, e.lenght_to_period) self.assertEqual(e.getReturnObject(), WEEK_ERROR_MESSAGE)
def geocoderImport(self, channelName, serviceName): # Checking for service existence getServiceIdByName(serviceName) # Getting channel id channel = getChannelByName(serviceName, channelName) channel_id = channel[ID] # Initialising requester and parser greqv = GeonamesRequestSender() gpars = GeocoderResponseParser() # Getting points collection points_coll = getDbObject(serviceName)[POINTS_COLL] # Getting first slice of <= 5000 points proc_step = 0 point_block = list(points_coll.find({ CHANNEL_ID: channel_id, JSON + '.' + ADDRESS: {"$exists": True} }).skip(proc_step).limit(PROC_BLOCK)) login = PluginConfigReader(PLUGIN_NAME).getConfigContent()[ SECTION_GEOCODING][GEONAMES_LOGIN] while point_block: current_size = len(point_block) addresses = [point[JSON][ADDRESS] for point in point_block] ids = [point[ID] for point in point_block] string_addresses = greqv.requestCoordinates( addresses, login, json_list_to_list_of_strings) json_coords = gpars.parseList(string_addresses) for i in range(0, current_size): # If no coords was found - we change nothing if json_coords[i] is None: continue points_coll.update( {ID: ids[i]}, {'$set': {'location.coordinates': json_coords[i]}} ) # Getting next slice of <= 5000 points proc_step += PROC_BLOCK point_block = list( points_coll.find().skip(proc_step).limit(PROC_BLOCK)) # Task is done self.done = True # And thread is done too after return return []
def test_exceed_limit_data(self): with self.assertRaises(GeocoderRequestLimitExceed): GeonamesRequestSender.checkResponseForException( json.dumps(RESPONSE_FOR_LIMIT_EXCEED))
def test_requestSingleCoordinates_syntax(self): response = GeonamesRequestSender.requestSingleCoordinates( TEST_SEARCH, GEONAMES_LOGIN) response = json.loads(response) self.assertEqual(COUNTRY_ID_VAL, response[GEONAMES][0][COUNTRY_ID])
def test_requestSingleCoordinates(self): response = GeonamesRequestSender.requestSingleCoordinates( TEST_SEARCH, GEONAMES_LOGIN) response = json.loads(response) self.assertEqual((response), RESPONSE_SINGLE)
def test_createRequestUrl(self): url = GeonamesRequestSender.createRequestUrl( TEST_SEARCH, GEONAMES_LOGIN) self.assertEqual(url, RESPONSE_TEST_SEARCH)
def test_exceed_other_data(self): with self.assertRaises(GeocoderRequestOtherExceed): GeonamesRequestSender.checkResponseForException( json.dumps(RESPONSE_FOR_OTHER_EXCEED))
def test_exceed_other(self): try: GeonamesRequestSender.checkResponseForException( json.dumps(RESPONSE_FOR_OTHER_ERROR)) except GeocoderRequestOtherExceed as e: self.assertEqual(e.getReturnObject(), OTHER_ERROR_MESSAGE)