| Conditions | 6 |
| Total Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 1 | Features | 0 |
| 1 | """Unit tests for the HTTP backend in Annif""" |
||
| 7 | def test_http_analyze(): |
||
| 8 | with unittest.mock.patch('requests.post') as mock_request: |
||
| 9 | # create a mock response whose .json() method returns the list that we |
||
| 10 | # define here |
||
| 11 | mock_response = unittest.mock.Mock() |
||
| 12 | mock_response.json.return_value = [ |
||
| 13 | {'uri': 'http://example.org/http', 'label': 'http', 'score': 1.0}] |
||
| 14 | mock_request.return_value = mock_response |
||
| 15 | |||
| 16 | http_type = annif.backend.get_backend_type("http") |
||
| 17 | http = http_type( |
||
| 18 | backend_id='http', |
||
| 19 | config={ |
||
| 20 | 'endpoint': 'http://api.example.org/analyze', |
||
| 21 | 'project': 'dummy'}) |
||
| 22 | result = http.analyze('this is some text') |
||
| 23 | assert len(result) == 1 |
||
| 24 | assert result[0].uri == 'http://example.org/http' |
||
| 25 | assert result[0].label == 'http' |
||
| 26 | assert result[0].score == 1.0 |
||
| 27 |