def test_wikimedia_return_page_id(monkeypatch): results = { "batchcomplete": "true", "continue": { "sroffset": 10, "continue": "-||revisions" }, "query": { "searchinfo": { "totalhits": 15622 }, "search": [{ "ns": 0, "title": "Dijon", "pageid": 3235267, "timestamp": "2018-11-19T11:49:51Z" }] } } def mockreturn(request): return mock_requests(results) monkeypatch.setattr(requests, 'get', mockreturn) x = script.wikipedia(results) assert x.Pageid == 3235267
def message(): if request.method == 'POST': msg = request.form['msg'] #get msg from the POST question = module.parsing(msg) print("la quest est : " + msg) #below question with stopwords removed. print(question.new_sentence) url_google = question.google() print(url_google) url_wiki = question.wiki() print(url_wiki) #lg.warning(url_wiki) wiki_description = module.wikipedia(url_wiki) print(wiki_description.Pageid) dico = {"google": url_google, "wiki": wiki_description.wikiword()} json_data = json.dumps(dico) return json_data
class TestParsing: stopword = 'afin a ailleurs oxford' localisation_numero = 'wer ewr 9 rue las cases' localisation = 'asd asd boulevard saint germain' majuscule = 'la super ville que je vois est Paris' ## ##unit tests for object parsing. ## #unit tests for attributes def test_get_msg_stopword(self): question = script.parsing(self.stopword) assert question.new_sentence == ['oxford'] def test_get_msg_localisation_numero(self): #msg = ('wer ewr 9 rue las cases') question = script.parsing(self.localisation_numero) assert question.placeToSearch == ['9','rue','las','cases'] def test_get_msg_localisation(self): #msg = ('asd asd boulevard saint germain') question = script.parsing(self.localisation) assert question.placeToSearch == ['boulevard','saint','germain'] def test_get_msg_majuscule(self): #msg = ('la super ville que je vois est Paris') question = script.parsing(self.majuscule) assert question.placeToSearch == ['Paris'] ##unit test for method "google" for object parsing def test_google_url(self): #msg = ('wer ewr 9 rue las cases') question = script.parsing(self.localisation_numero) assert question.google() == 'https://maps.googleapis.com/maps/api/staticmap?center=9+rue+las+cases&zoom=14&size=400x400&markers=9+rue+las+cases&key=AIzaSyD5nqmDGFH1SUZxJAYVtFHP7RNjjFE9CHg' ##unit test for method "wiki" for object parsing def test_wiki_url(self): #msg = ('wer ewr 9 rue las cases') question = script.parsing(self.localisation_numero) assert question.wiki() == 'https://fr.wikipedia.org/w/api.php?action=query&list=search&srsearch=9%20rue%20las%20cases&formatversion=2&prop=revisions&rvprop=content&format=json&formatversion=2' #***# on doit se connecter a wiki request pour tester. def test_request_api_wiki(monkeypatch): results =[{"batchcomplete":"true","continue":{"sroffset":10,"continue":"-||revisions"},"query":{"searchinfo":{"totalhits":15622},"search":[{"ns":0,"title":"Dijon","pageid":3235267,"timestamp":"2018-11-19T11:49:51Z"}]}}] def mockreturn(requests): return json.dumps(results) monkeypatch.setattr(requests, 'get', mockreturn) x = script.wikipedia(results) assert x.Pageid == '3235267'
def test_get_Pageid( self): ##manque url dans la creation objet wikipedia ... question = script.wikipedia(self.results) assert question.Pageid == '1244052'