Пример #1
0
def test_http_error_calling_keyword():
    """
    Tests re raising of status code 400 when calling keywords endpoint
    """
    mock_url_keyword = "http://somerealurl.com/"
    responses.add(responses.POST, mock_url_keyword, status=400)

    with mock.patch('env.get_keywords_endpoint',
                    return_value=mock_url_keyword):
        with pytest.raises(requests.HTTPError):
            connector.get_keywords("Some super real query")
    assert len(responses.calls) == 1
    assert responses.calls[0].request.url == mock_url_keyword
    assert responses.calls[0].response.status_code == 400
Пример #2
0
def test_if_got_error_from_keywords_service(mock_get):
    text_to_keywordize = 'es forzoso en bicicleta usar casco?'
    mock_get.return_value.json.return_value = {
        'error': {
            'message': "something happened"
        }
    }  # noqa: E501
    with pytest.raises(Exception):
        assert connector.get_keywords(text_to_keywordize)
Пример #3
0
def test_get_keywords_from_nlp(mock_get):
    with mock.patch('env.get_keywords_endpoint',
                    return_value="http://example.org"):
        text_to_keywordize = 'es forzoso en bicicleta usar casco?'
        output_to_assert_nlp_keywords = [
            'ser', 'forzoso', 'bicicleta', 'usar', 'casco'
        ]
        mock_get.return_value.json.return_value = {
            "lan":
            "es",
            "tokens": [{
                "lemma": "ser",
                "part_of_speech": "VERB",
                "word": "es"
            }, {
                "lemma": "forzoso",
                "part_of_speech": "ADJ",
                "word": "forzoso"
            }, {
                "lemma": "bicicleta",
                "part_of_speech": "NOUN",
                "word": "bicicleta"
            }, {
                "lemma": "usar",
                "part_of_speech": "VERB",
                "word": "usar"
            }, {
                "lemma": "casco",
                "part_of_speech": "NOUN",
                "word": "casco"
            }]
        }  # noqa: E501
        result = connector.get_keywords(text_to_keywordize)
        mock_get.assert_called_once_with(env.get_keywords_endpoint(),
                                         json={"text": text_to_keywordize})
        assert result == output_to_assert_nlp_keywords