From 8b2e4d3bcff3a62dd9b33a8498ea425564c92473 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 28 Apr 2017 19:57:24 -0400 Subject: [PATCH] Add a test for get_matching_tags --- data/model/test/test_tag.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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)