def test_search_raises_error_when_db_not_found(self, app): with app.app_context(): kwargs = {"query": "q", "size": 10, "position": 1} with pytest.raises(ValueError) as excinfo: view._handle_search_request("nope", kwargs) msg = "No database with that identifier could be found" assert str(excinfo.value) == msg
def test_search_raises_error_when_db_not_found(self, app): with app.app_context(): kwargs = {'query': 'q', 'size': 10, 'position': 1} with pytest.raises(ValueError) as excinfo: view._handle_search_request('nope', kwargs) msg = 'No database with that identifier could be found' assert str(excinfo.value) == msg
def test_search_raises_error_when_z3950manager_not_initialised(self, app): with app.app_context(): app.extensions = {} kwargs = {'query': 'q', 'size': 10, 'position': 1} with pytest.raises(RuntimeError) as excinfo: view._handle_search_request('loc', kwargs) msg = 'The Z3950Manager has not been initialised' assert str(excinfo.value) == msg
def test_search_raises_error_when_z3950manager_not_initialised(self, app): with app.app_context(): app.extensions = {} kwargs = {"query": "q", "size": 10, "position": 1} with pytest.raises(RuntimeError) as excinfo: view._handle_search_request("loc", kwargs) msg = "The Z3950Manager has not been initialised" assert str(excinfo.value) == msg
def test_successful_search_response_contains_correct_data(self, app, dataset): with app.app_context(): mock_db = MagicMock() mock_db.search.return_value = dataset mock_manager = MagicMock() mock_manager.databases = {"db": mock_db} app.extensions["z3950"]["z3950_manager"] = mock_manager kwargs = {"query": "q", "size": 10, "position": 1} resp = view._handle_search_request("db", kwargs) metadata = set(dataset.metadata.values()) assert resp[0] is None assert resp[1] == dataset assert metadata.issubset(set(resp[2].values()))
def test_successful_search_response_contains_correct_data( self, app, dataset): with app.app_context(): mock_db = MagicMock() mock_db.search.return_value = dataset mock_manager = MagicMock() mock_manager.databases = {'db': mock_db} app.extensions['z3950']['z3950_manager'] = mock_manager kwargs = {'query': 'q', 'size': 10, 'position': 1} resp = view._handle_search_request('db', kwargs) metadata = set(dataset.metadata.values()) assert resp[0] is None assert resp[1] == dataset assert metadata.issubset(set(resp[2].values()))
def test_search_raises_error_when_position_is_not_a_number(self): kwargs = {'query': 'q', 'size': 10, 'position': 'not a number'} with pytest.raises(ValueError) as excinfo: view._handle_search_request('loc', kwargs) msg = 'The "position" parameter must be a valid integer' assert str(excinfo.value) == msg
def test_search_raises_error_when_size_is_less_then_one(self): kwargs = {'query': 'q', 'size': 0, 'position': 1} with pytest.raises(ValueError) as excinfo: view._handle_search_request('loc', kwargs) msg = 'The "size" parameter must be a positive integer' assert str(excinfo.value) == msg
def test_search_raises_error_when_query_missing(self): kwargs = {'query': '', 'size': 10, 'position': 1} with pytest.raises(ValueError) as excinfo: view._handle_search_request('loc', kwargs) msg = 'The "query" parameter is missing' assert str(excinfo.value) == msg
def test_search_raises_error_when_position_is_not_a_number(self): kwargs = {"query": "q", "size": 10, "position": "not a number"} with pytest.raises(ValueError) as excinfo: view._handle_search_request("loc", kwargs) msg = 'The "position" parameter must be a valid integer' assert str(excinfo.value) == msg
def test_search_raises_error_when_position_is_less_then_one(self): kwargs = {"query": "q", "size": 10, "position": 0} with pytest.raises(ValueError) as excinfo: view._handle_search_request("loc", kwargs) msg = 'The "position" parameter must be a positive integer' assert str(excinfo.value) == msg
def test_search_raises_error_when_query_missing(self): kwargs = {"query": "", "size": 10, "position": 1} with pytest.raises(ValueError) as excinfo: view._handle_search_request("loc", kwargs) msg = 'The "query" parameter is missing' assert str(excinfo.value) == msg