Exemplo n.º 1
0
def test_papy_response_google_ok_but_no_wiki():
    wiki_data = Wikipedia()
    maps_data = GoogleMaps()
    maps_data.return_value = Return.RETURN_OK

    ret = papy_response(maps_data, wiki_data)
    assert ret[1:] == (NO_WIKI, True, False)

    wiki_data.return_value = Return.NO_RETURN
    ret = papy_response(maps_data, wiki_data)
    assert ret[1:] == (NO_WIKI_INFO, True, False)
Exemplo n.º 2
0
def test_papy_response_both_api_are_ok():
    wiki_data = Wikipedia()
    maps_data = GoogleMaps()
    wiki_data.return_value = Return.RETURN_OK
    maps_data.return_value = Return.RETURN_OK
    wiki_data.blabla = 's<iuvhvuidshufhfuhquffvslsufguzeeh'
    maps_data.formatted_address = 'Paris, France'

    ret = papy_response(maps_data, wiki_data)
    assert maps_data.formatted_address in ret[0]
    assert wiki_data.blabla[:100] in ret[1]
    assert ret[2]
    assert ret[3]
Exemplo n.º 3
0
def test_papy_response_no_google():
    maps_data = GoogleMaps()
    wiki_data = Wikipedia()
    ret = papy_response(maps_data, wiki_data)
    assert ret == (NO_POSITION, '', False, False)

    maps_data.return_value = Return.SERVER_ERROR
    ret = papy_response(maps_data, wiki_data)
    assert ret == (NO_GOOGLE, '', False, False)
Exemplo n.º 4
0
def test_req_void(monkeypatch):
    mock = Mock_requests(404)

    def Mock_requests_get(*args, **kwargs):
        return requests_get(mock)

    monkeypatch.setattr(requests, 'get', Mock_requests_get)

    lat = 30.3284544
    lng = 35.4443622
    data = Wikipedia().req(lat, lng)

    assert data.return_value == Return.URL_ERROR
Exemplo n.º 5
0
def test_req_no_return(monkeypatch):
    with open(
            os.path.join(os.path.dirname(__file__)) +
            '/mock_wiki_return_no_found.json', 'r') as file:
        test_data = json.load(file)

    mock = Mock_requests(200, position_found=False)

    def Mock_requests_get(*args, **kwargs):
        return requests_get(mock)

    monkeypatch.setattr(requests, 'get', Mock_requests_get)

    lat = 30.3284544
    lng = 35.4443622
    data = Wikipedia().req(lat, lng)
    assert data.return_value == Return.NO_RETURN
    assert data.url == ''
Exemplo n.º 6
0
def api() -> jsonify:
    wiki_data = None
    result = {}

    user_input = request.data.decode('utf-8')
    maps_data = GoogleMaps().req(normalize(user_input))

    if maps_data.return_value == Return.RETURN_OK:
        result['position'] = maps_data.position

        wiki_data = Wikipedia().req(**maps_data.position)
        if wiki_data.return_value == Return.RETURN_OK:
            result['wiki_url'] = wiki_data.url

    result['papy_blabla_1'], result['papy_blabla_2'], \
        result['found_place'], result['found_wiki'] = \
        papy_response(maps_data, wiki_data)

    return jsonify(result)
Exemplo n.º 7
0
def test_req_ok(monkeypatch):
    with open(
            os.path.join(os.path.dirname(__file__)) +
            '/mock_wiki_return_ok.json', 'r') as file:
        test_data = json.load(file)

    mock = Mock_requests(200)

    def Mock_requests_get(*args, **kwargs):
        return requests_get(mock)

    monkeypatch.setattr(requests, 'get', Mock_requests_get)

    lat = 30.3284544
    lng = 35.4443622
    data = Wikipedia().req(lat, lng)
    assert data.return_value == Return.RETURN_OK
    assert data.url == Wiki.SEARCH_URL + "curid=5351"
    assert data.blabla == test_data['query']['pages'][0]['extract']