def answer_user_query(self, query): parser = pars.Parser() locater = loct.Locater() storyteller = steller.StoryTeller() manage = answer_man.AnswerManager() self._answer['Parser'] = manage.check_parser(query) parser.set_question(query) parser.remove_accents() parser.remove_punctuations() parser.remove_current_word() locater.set_keyword(parser.question) self._answer['Locater'] = { 'say': manage.check_locater(locater.get_address(), locater.get_location()), 'data': { 'address': locater.get_address(), 'location': locater.get_location() } } storyteller.set_position(locater.get_location()[0], locater.get_location()[1]) self._answer['StoryTeller'] = { 'say': manage.check_storyteller(storyteller.get_informations()), 'data': { 'summary': storyteller.get_informations()[0], 'url': storyteller.get_informations()[1] } } return self._answer
def test_set_position_failed(monkeypatch): def fake_geosearch(self, latitude, longitude): return data_list_empty monkeypatch.setattr("grandpy.storyteller.MediaWiki.geosearch", fake_geosearch) lat = None lng = None storyteller = stell.StoryTeller() storyteller.set_position(lat, lng) assert storyteller._response == data_list_empty
def test_set_position(monkeypatch): def fake_geosearch(self, latitude, longitude): return data_list monkeypatch.setattr("grandpy.storyteller.MediaWiki.geosearch", fake_geosearch) lat = 48.85837009999999 lng = 2.2944813 storyteller = stell.StoryTeller() storyteller.set_position(lat, lng) assert storyteller._response == data_list
def test_location_failed(monkeypatch): def fake_geosearch(self, latitude, longitude): return data_list monkeypatch.setattr("grandpy.storyteller.MediaWiki.geosearch", fake_geosearch) lat = None lng = None storyteller = stell.StoryTeller() storyteller.set_position(lat, lng) location = (storyteller._latitude, storyteller._longitude) assert location == (lat, lng)
def test_choice_title(monkeypatch): def fake_geosearch(self, latitude, longitude): return data_list def fake_random(self): return 'Tour Eiffel' monkeypatch.setattr("grandpy.storyteller.MediaWiki.geosearch", fake_geosearch) monkeypatch.setattr("grandpy.storyteller.random.choice", fake_random) lat = 48.85837009999999 lng = 2.2944813 storyteller = stell.StoryTeller() storyteller.set_position(lat, lng) assert storyteller.choice_title() == 'Tour Eiffel'
def test_get_informations(monkeypatch): class FakePage: url = "url Wikipédia" summary = "resumé Wikipédia" def fake_page(self, title): return FakePage() def fake_geosearch(self, latitude, longitude): return data_list monkeypatch.setattr("grandpy.storyteller.MediaWiki.geosearch", fake_geosearch) monkeypatch.setattr("grandpy.storyteller.MediaWiki.page", fake_page) storyteller = stell.StoryTeller() lat = 48.85837009999999 lng = 2.2944813 storyteller.set_position(lat, lng) result = storyteller.get_informations() assert result == [FakePage.summary, FakePage.url]