def test_files_get_provider_returns_empty_list_if_no_blocks(monkeypatch): with mock.patch("socket.gethostbyname", return_value="127.0.0.1"): files = Files() def return_empty_list(): return [] monkeypatch.setattr(files, "list_blocks", return_empty_list) result = files.get_blocks_from_provider("NonExistingProvider") assert isinstance(result, list) assert not result
def test_files_get_provider(monkeypatch): with mock.patch("socket.gethostbyname", return_value="127.0.0.1"): files = Files() def return_block_names(): return ["doc-00"] monkeypatch.setattr(files, "list_blocks", return_block_names) def return_fake_blocks(block_list): return [MetaBlock(key, providers=["FakeProvider"]) for key in block_list] monkeypatch.setattr(files, "get_blocks", return_fake_blocks) result = files.get_blocks_from_provider("FakeProvider") assert isinstance(result, list) assert len(result) == 1
def test_files_get_provider_with_empty_string_as_provider(): with mock.patch("socket.gethostbyname", return_value="127.0.0.1"): files = Files() with pytest.raises(ValueError, match="provider argument must be a non empty string"): files.get_blocks_from_provider("")