def test_maui_suggest_error(maui, project): with unittest.mock.patch('requests.post') as mock_request: mock_request.side_effect = requests.exceptions.RequestException( 'failed') result = maui.suggest('this is some text') assert len(result) == 0
def test_maui_suggest_unexpected_json(maui, project): responses.add(responses.POST, 'http://api.example.org/mauiservice/dummy/suggest', json=["spanish inquisition"]) result = maui.suggest('this is some text') assert len(result) == 0 assert len(responses.calls) == 1
def test_maui_suggest_json_fails(maui, project): with unittest.mock.patch('requests.post') as mock_request: # create a mock response whose .json() method raises a ValueError mock_response = unittest.mock.Mock() mock_response.json.side_effect = ValueError("JSON decode failed") mock_request.return_value = mock_response result = maui.suggest('this is some text') assert len(result) == 0
def test_maui_suggest_unknown_uri(maui, project): responses.add(responses.POST, 'http://api.example.org/mauiservice/dummy/suggest', json={ 'title': '1 recommendation from dummy', 'topics': [{ 'id': 'http://example.org/unknown', 'label': 'unknown', 'probability': 1.0 }] }) result = maui.suggest('this is some text') assert len(result) == 0 assert len(responses.calls) == 1
def test_maui_suggest_no_input(maui): responses.add(responses.POST, 'http://api.example.org/mauiservice/dummy/suggest', json={ 'title': '1 recommendation from dummy', 'topics': [{ 'id': 'http://example.org/dummy', 'label': 'dummy', 'probability': 1.0 }] }) result = maui.suggest('') assert len(result) == 0 assert len(responses.calls) == 0
def test_maui_suggest(maui): responses.add(responses.POST, 'http://api.example.org/mauiservice/dummy/suggest', json={ 'title': '1 recommendation from dummy', 'topics': [{ 'id': 'http://example.org/dummy', 'label': 'dummy', 'probability': 1.0 }] }) result = maui.suggest('this is some text') assert len(result) == 1 assert result[0].uri == 'http://example.org/dummy' assert result[0].label == 'dummy' assert result[0].notation is None assert result[0].score == 1.0 assert len(responses.calls) == 1
def test_maui_suggest_with_notation(maui, subject_index): responses.add(responses.POST, 'http://api.example.org/mauiservice/dummy/suggest', json={ 'title': '1 recommendation from dummy', 'topics': [{ 'id': 'http://example.org/dummy-with-notation', 'label': 'dummy', 'probability': 1.0 }] }) maui.project.subjects.append('http://example.org/dummy-with-notation', 'dummy', '42.42') result = maui.suggest('this is some text') assert len(result) == 1 hits = result.as_list(subject_index) assert hits[0].uri == 'http://example.org/dummy-with-notation' assert hits[0].label == 'dummy' assert hits[0].notation == '42.42' assert hits[0].score == 1.0 assert len(responses.calls) == 1