def given_by_user_country_and_subregion(step, country, subregion): kwargs = {'place_pk': 1, 'place_name': None, 'place_coordinates': None, 'place_region': None, 'place_subregion': subregion, 'create_missing_log': False, 'place_country': country} log = UserGeoNamePlugin(None).run_matching(**kwargs) assert_equals(len(log.matched.all()), 1) assert_equals(log.matched.all()[0].united_geoname.main_name, 'Paris') log.delete()
def given_by_user_country_and_coordinates_x_y(step, country, x, y): coordinates = Point(float(x), float(y)) kwargs = {'place_pk': 1, 'place_name': None, 'place_coordinates': coordinates, 'place_region': None, 'place_subregion': None, 'create_missing_log': False, 'place_country': country} log = UserGeoNamePlugin(None).run_matching(**kwargs) assert_equals(len(log.matched.all()), 1) assert_equals(log.matched.all()[0].united_geoname.main_name, 'Vilnius') log.delete()
def user_run_matching_country_name(step, country, name): # By UnitedGeoName kwargs = {'place_pk': 1, 'place_name': name, 'place_coordinates': None, 'place_region': None, 'place_subregion': None, 'create_missing_log': False, 'place_country': country} log = UserGeoNamePlugin(None).run_matching(**kwargs) assert_equals(len(log.matched.all()), 1) assert_equals(log.matched.all()[0].united_geoname.main_name, name) log.delete()
def run_metching_for_name(step, name): # By UnitedGeoNameSynonym kwargs = {'place_pk': 1, 'place_name': name, 'place_coordinates': None, 'place_region': None, 'place_subregion': None, 'create_missing_log': False, 'place_country': None} log = UserGeoNamePlugin(None).run_matching(**kwargs) if len(log.matched.all()) == 1: assert_equals(log.matched.all()[0].united_geoname.main_name, "Vilnius") else: raise Exception('It is necessary to improve the test.') log.delete()
def get_matching_object(instance): cont_type = ContentType.objects.get_for_model(UserGeoName) if instance.name: name = instance.name else: name = None if instance.region: region = instance.region else: region = None if instance.subregion: subregion = instance.subregion else: subregion = None if instance.coordinates: coordinates = instance.coordinates else: coordinates = None if instance.country: country = instance.country else: country = None if instance.name: name = name.encode("utf-8") matched_log = UserGeoNamePlugin(cont_type).run_matching( instance.pk, name, coordinates, region, subregion, False, country) update_best_match(matched_log) return matched_log