def test_clean_sentence(): """ Test the entire method. Must return the last word of the sentence. """ sentence = Parser("Bonjour, savez-vous où se situe la Tour Eiffel ?") assert sentence.clean_sentence() == "tour eiffel"
def test_clean_sentence_returns_no_data(): """ Test if no parser returns no data """ sentence = Parser("Bonjour !") with pytest.raises(ValueError): sentence.clean_sentence()
def test_clean_sentence_send_no_value(): """ Test if no sentence is send """ sentence = Parser("") with pytest.raises(ValueError): sentence.clean_sentence()
def test_clean_sentence_return_str(): """ Test if the sentence doesn't contain words """ sentence = Parser("! , . / =") with pytest.raises(ValueError): sentence.clean_sentence()
def osm_ajax_request(): """ Get the Ajax call Treat all requests (OSM + Wiki + bot answer) Return json responses """ result = request.form['address_request'] # Initialize an object to parse the data sent in form client_ask = Parser(result) # Get the main address keyword try: address_keyword = client_ask.clean_sentence() except ValueError: return jsonify({'answer_error': True}) # Call OSM API address = Map(address_keyword) # Call Wiki API address_informations = Wiki(address_keyword) # Get a random answer pybot_answer = BotAnswer() # Get address informations try: address_latitude = address.latitude address_longitude = address.longitude address_details = address.details address_answer = pybot_answer.random_address_answer wiki_entity = address_informations.entity wiki_informations = address_informations.details wiki_link = address_informations.wiki_link wiki_answer = pybot_answer.random_wiki_answer return jsonify({ 'address': { 'latitude': address_latitude, 'longitude': address_longitude, 'details': address_details, 'address_answer': address_answer, 'wiki_entity': wiki_entity, 'wiki_informations': wiki_informations, 'wiki_link': wiki_link, 'wiki_answer': wiki_answer } }) except: error_answer = pybot_answer.random_error_answer return jsonify({ 'error_answer': error_answer, 'address_keyword': address_keyword })
def test_clean_sentence_word_with_punctuation(): """ Test if word with punctation is correctly processed """ sentence = Parser("Salut, je veux découvrir Paris!") assert sentence.clean_sentence() == "paris"
def test_clean_sentence_str_lower(): """ Test if the sentence is changed to lower case """ sentence = Parser("Je veux aller à Paris") assert sentence.clean_sentence() == "paris"
def test_clean_sentence_without_stop_words(): """ Test if the stop words treatment is not killing the main method """ sentence = Parser("Ordinateurs soutiennent utilisateur") assert sentence.clean_sentence() == "ordinateurs soutiennent utilisateur"