diff --git a/data/model/test/test_tag.py b/data/model/test/test_tag.py index 9d372efab..623db281a 100644 --- a/data/model/test/test_tag.py +++ b/data/model/test/test_tag.py @@ -1,8 +1,25 @@ +from data.database import Image, RepositoryTag from data.model.repository import create_repository -from data.model.tag import list_active_repo_tags, create_or_update_tag, delete_tag +from data.model.tag import (list_active_repo_tags, create_or_update_tag, delete_tag, + get_matching_tags, _tag_alive) from data.model.image import find_create_or_link_image + from test.fixtures import * +def test_get_matching_tags(initialized_db): + # Test for every image in the test database. + for image in Image.select(): + matching_query = get_matching_tags(image.docker_image_id, image.storage.uuid) + expected_query = (RepositoryTag + .select() + .join(Image) + .where(RepositoryTag.hidden == False) + .where((Image.id == image.id) | (Image.ancestors ** ('%%/%s/%%' % image.id)))) + + matching_tags = set([tag.id for tag in matching_query]) + expected_tags = set([tag.id for tag in _tag_alive(expected_query)]) + assert matching_tags == expected_tags, "mismatch for image %s" % image.id + def assert_tags(repository, *args): tags = list(list_active_repo_tags(repository)) assert len(tags) == len(args)