def test_get_wiki_page_fail(monkeypatch): def mock_return(request): class MockResponse: def __init__(self): self.status_code = 404 self.results = """ { "query": { "geosearch": [{ "pageid": 509178 }] } } """ def json(self): return json.loads(self.results) return MockResponse() monkeypatch.setattr(requests, 'get', mock_return) lat = 48.8747578 lng = 2.350564700000001 wiki = script.MediaWikiAPI() assert wiki.get_wiki_page(lat, lng) == False
def test_request_media_wiki_fail(monkeypatch): def mock_return(request): class MockResponse: def __init__(self): with open('ocapp/tests/requests.json', 'r') as f: self.results = f.read() self.status_code = 404 def json(self): return json.loads(self.results) return MockResponse() monkeypatch.setattr(requests, 'get', mock_return) wiki = script.MediaWikiAPI() wiki.idPage = 5091748 assert wiki.request_media_wiki() == False
class TestMediaWikiAPI: wiki = script.MediaWikiAPI() def test_idPage(self): assert self.wiki.idPage == -1 def test_set_idPage(self): self.wiki.idPage = 84 assert self.wiki.idPage == 84 def test_textBot(self): assert self.wiki.textBot == '' def test_set_textBot(self): self.wiki.textBot = "Lorem ipsum is a long text" assert self.wiki.textBot == "Lorem ipsum is a long text" def test_link_wikipedia(self): assert self.wiki.linkWikipedia == '' def test_set_link_wikipedia(self): self.wiki.linkWikipedia = 'https://wikipedia.org' assert self.wiki.linkWikipedia == 'https://wikipedia.org'