Fix bug where we weren't properly caching enum values and we were always looking up the media type when constructing manifests

This commit is contained in:
Joseph Schorr 2019-01-22 14:46:38 -05:00
parent ed75daf3d9
commit bbfb0211dc
5 changed files with 51 additions and 21 deletions

View file

@ -1,6 +1,9 @@
import pytest
from playhouse.test_utils import assert_query_count
from data.registry_model import registry_model
from data.database import Manifest
from endpoints.api.test.shared import conduct_api_call
from endpoints.test.shared import client_with_identity
@ -75,16 +78,23 @@ def test_move_tag(image_exists, test_tag, expected_status, client, app):
conduct_api_call(cl, RepositoryTag, 'put', params, request_body, expected_status)
@pytest.mark.parametrize('repo_namespace, repo_name', [
('devtable', 'simple'),
('devtable', 'history'),
('devtable', 'complex'),
('buynlarge', 'orgrepo'),
@pytest.mark.parametrize('repo_namespace, repo_name, query_count', [
('devtable', 'simple', 7),
('devtable', 'history', 7),
('devtable', 'complex', 7),
('devtable', 'gargantuan', 7),
('buynlarge', 'orgrepo', 9), # +2 for permissions checks.
('buynlarge', 'anotherorgrepo', 9), # +2 for permissions checks.
])
def test_list_repo_tags(repo_namespace, repo_name, client, app):
def test_list_repo_tags(repo_namespace, repo_name, client, query_count, app):
# Pre-cache media type loads to ensure consistent query count.
Manifest.media_type.get_name(1)
params = {'repository': repo_namespace + '/' + repo_name}
with client_with_identity('devtable', client) as cl:
tags = conduct_api_call(cl, ListRepositoryTags, 'get', params).json['tags']
with assert_query_count(query_count):
tags = conduct_api_call(cl, ListRepositoryTags, 'get', params).json['tags']
repo_ref = registry_model.lookup_repository(repo_namespace, repo_name)
history, _ = registry_model.list_repository_tag_history(repo_ref)
assert len(tags) == len(history)