Fix build by pre-calling the caches
They were being called in a test-dependent order, which caused any tests which relied on query count to fail
This commit is contained in:
parent
cdd7cb9321
commit
8dcea30d58
3 changed files with 23 additions and 14 deletions
|
@ -54,9 +54,13 @@ def get_public_repo_visibility():
|
||||||
return Visibility.get(name='public')
|
return Visibility.get(name='public')
|
||||||
|
|
||||||
|
|
||||||
@lru_cache(maxsize=3)
|
|
||||||
def _lookup_team_role(name):
|
def _lookup_team_role(name):
|
||||||
return TeamRole.get(name=name)
|
return _lookup_team_roles()[name]
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache(maxsize=1)
|
||||||
|
def _lookup_team_roles():
|
||||||
|
return {role.name:role for role in TeamRole.select()}
|
||||||
|
|
||||||
|
|
||||||
def filter_to_repos_for_user(query, username=None, namespace=None, repo_kind='image',
|
def filter_to_repos_for_user(query, username=None, namespace=None, repo_kind='image',
|
||||||
|
|
|
@ -7,29 +7,29 @@ from endpoints.api.search import ConductRepositorySearch, ConductSearch
|
||||||
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
from endpoints.api.test.shared import client_with_identity, conduct_api_call
|
||||||
from test.fixtures import *
|
from test.fixtures import *
|
||||||
|
|
||||||
@pytest.mark.parametrize('query, expected_query_count', [
|
@pytest.mark.parametrize('query', [
|
||||||
('simple', 7),
|
('simple'),
|
||||||
('public', 6),
|
('public'),
|
||||||
('repository', 6),
|
('repository'),
|
||||||
])
|
])
|
||||||
def test_repository_search(query, expected_query_count, client):
|
def test_repository_search(query, client):
|
||||||
with client_with_identity('devtable', client) as cl:
|
with client_with_identity('devtable', client) as cl:
|
||||||
params = {'query': query}
|
params = {'query': query}
|
||||||
with assert_query_count(expected_query_count):
|
with assert_query_count(6):
|
||||||
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
result = conduct_api_call(cl, ConductRepositorySearch, 'GET', params, None, 200).json
|
||||||
assert result['start_index'] == 0
|
assert result['start_index'] == 0
|
||||||
assert result['page'] == 1
|
assert result['page'] == 1
|
||||||
assert len(result['results'])
|
assert len(result['results'])
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('query, expected_query_count', [
|
@pytest.mark.parametrize('query', [
|
||||||
('simple', 8),
|
('simple'),
|
||||||
('public', 8),
|
('public'),
|
||||||
('repository', 8),
|
('repository'),
|
||||||
])
|
])
|
||||||
def test_search_query_count(query, expected_query_count, client):
|
def test_search_query_count(query, client):
|
||||||
with client_with_identity('devtable', client) as cl:
|
with client_with_identity('devtable', client) as cl:
|
||||||
params = {'query': query}
|
params = {'query': query}
|
||||||
with assert_query_count(expected_query_count):
|
with assert_query_count(8):
|
||||||
result = conduct_api_call(cl, ConductSearch, 'GET', params, None, 200).json
|
result = conduct_api_call(cl, ConductSearch, 'GET', params, None, 200).json
|
||||||
assert len(result['results'])
|
assert len(result['results'])
|
||||||
|
|
|
@ -125,6 +125,11 @@ def initialized_db(appconfig):
|
||||||
# Configure the database.
|
# Configure the database.
|
||||||
configure(appconfig)
|
configure(appconfig)
|
||||||
|
|
||||||
|
# Initialize caches.
|
||||||
|
model._basequery._lookup_team_roles()
|
||||||
|
model._basequery.get_public_repo_visibility()
|
||||||
|
model.log.get_log_entry_kinds()
|
||||||
|
|
||||||
# If under a test *real* database, setup a savepoint.
|
# If under a test *real* database, setup a savepoint.
|
||||||
under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI'))
|
under_test_real_database = bool(os.environ.get('TEST_DATABASE_URI'))
|
||||||
if under_test_real_database:
|
if under_test_real_database:
|
||||||
|
|
Reference in a new issue