diff --git a/cid/crud.py b/cid/crud.py index 33ebe9d..1a3ae9b 100644 --- a/cid/crud.py +++ b/cid/crud.py @@ -345,7 +345,11 @@ def find_available_google_versions(db: Session) -> list: """ versions = [x.version for x in db.query(GoogleImage.version).distinct()] - return sorted(versions, key=Version, reverse=True) + def version_key(version: str) -> Version: + parts = [part for part in version.split(".") if part.isdigit()] + return Version(".".join(parts)) + + return sorted(versions, key=version_key, reverse=True) def find_images_for_version(db: Session, version: str) -> list: diff --git a/tests/test_crud.py b/tests/test_crud.py index 9d33965..b333f1c 100644 --- a/tests/test_crud.py +++ b/tests/test_crud.py @@ -434,14 +434,31 @@ def test_find_available_google_versions(db): GoogleImage(id="id-a", version="8.2.0"), GoogleImage(id="id-b", version="7.9.0"), GoogleImage(id="id-c", version="9.5.0"), - GoogleImage(id="id-d", version="10.0.0"), - GoogleImage(id="id-e", version="9.5.0"), + GoogleImage(id="id-d", version="9.7.3"), + GoogleImage(id="id-e", version="10.0.0"), + GoogleImage(id="id-g", version="9.5.0"), + GoogleImage(id="id-h", version="9.7.arm64"), + GoogleImage(id="id-i", version="9.7.arm64"), + GoogleImage(id="id-j", version="9.arm64"), + GoogleImage(id="id-k", version="9.arm64"), + GoogleImage(id="id-l", version="9.7.1.arm64"), + GoogleImage(id="id-m", version="9.7.1.arm64"), ] db.add_all(images) db.commit() result = crud.find_available_google_versions(db) - assert result == ["10.0.0", "9.5.0", "8.2.0", "7.9.0"] + + assert result == [ + "10.0.0", + "9.7.3", + "9.7.1.arm64", + "9.7.arm64", + "9.5.0", + "9.arm64", + "8.2.0", + "7.9.0", + ] def test_find_images_for_version(db):