mirror of
				https://github.com/arcan1s/ahriman.git
				synced 2025-10-30 21:33:43 +00:00 
			
		
		
		
	feat: filter out obvious duplicates from multisearch
This commit is contained in:
		| @ -94,6 +94,15 @@ class Remote(SyncHttpClient): | ||||
|                 for package in portion | ||||
|                 if package.name in packages or not packages | ||||
|             } | ||||
|  | ||||
|         # simple check for duplicates. This method will remove all packages under base if there is | ||||
|         # a package named exactly as its base | ||||
|         packages = { | ||||
|             package.name: package | ||||
|             for package in packages.values() | ||||
|             if package.package_base not in packages or package.package_base == package.name | ||||
|         } | ||||
|  | ||||
|         return list(packages.values()) | ||||
|  | ||||
|     @classmethod | ||||
|  | ||||
| @ -70,7 +70,7 @@ class SearchView(BaseView): | ||||
|         if not packages: | ||||
|             raise HTTPNotFound(reason=f"No packages found for terms: {search}") | ||||
|  | ||||
|         comparator: Callable[[AURPackage], str] = lambda item: str(item.package_base) | ||||
|         comparator: Callable[[AURPackage], str] = lambda item: item.package_base | ||||
|         response = [ | ||||
|             { | ||||
|                 "package": package.package_base, | ||||
|  | ||||
| @ -1,5 +1,6 @@ | ||||
| import pytest | ||||
|  | ||||
| from dataclasses import replace | ||||
| from pytest_mock import MockerFixture | ||||
| from unittest.mock import call as MockCall | ||||
|  | ||||
| @ -88,6 +89,17 @@ def test_multisearch_single(aur_package_ahriman: AURPackage, pacman: Pacman, moc | ||||
|     search_mock.assert_called_once_with("ahriman", pacman=pacman, search_by=None) | ||||
|  | ||||
|  | ||||
| def test_multisearch_remove_duplicates(aur_package_ahriman: AURPackage, pacman: Pacman, mocker: MockerFixture) -> None: | ||||
|     """ | ||||
|     must remove duplicates from search result | ||||
|     """ | ||||
|     package1 = replace(aur_package_ahriman) | ||||
|     package2 = replace(aur_package_ahriman, name="ahriman-triggers") | ||||
|     mocker.patch("ahriman.core.alpm.remote.Remote.package_search", return_value=[package1, package2]) | ||||
|  | ||||
|     assert Remote.multisearch("ahriman", pacman=pacman) == [package1] | ||||
|  | ||||
|  | ||||
| def test_remote_git_url(remote: Remote) -> None: | ||||
|     """ | ||||
|     must raise NotImplemented for missing remote git url | ||||
|  | ||||
		Reference in New Issue
	
	Block a user