2018-07-18 21:22:05 +00:00
|
|
|
from datetime import timedelta
|
|
|
|
|
2017-03-22 17:20:43 +00:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from peewee import IntegrityError
|
|
|
|
|
2017-06-07 19:05:29 +00:00
|
|
|
from data.model.repository import create_repository, purge_repository, is_empty
|
2017-11-30 20:50:21 +00:00
|
|
|
from data.model.repository import get_filtered_matching_repositories
|
2017-04-24 17:49:29 +00:00
|
|
|
from test.fixtures import *
|
2017-03-22 17:20:43 +00:00
|
|
|
|
2018-04-06 17:48:01 +00:00
|
|
|
|
2017-04-24 17:49:29 +00:00
|
|
|
def test_duplicate_repository_different_kinds(initialized_db):
|
2017-03-22 17:20:43 +00:00
|
|
|
# Create an image repo.
|
|
|
|
create_repository('devtable', 'somenewrepo', None, repo_kind='image')
|
|
|
|
|
|
|
|
# Try to create an app repo with the same name, which should fail.
|
|
|
|
with pytest.raises(IntegrityError):
|
|
|
|
create_repository('devtable', 'somenewrepo', None, repo_kind='application')
|
2017-06-07 19:05:29 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_is_empty(initialized_db):
|
|
|
|
create_repository('devtable', 'somenewrepo', None, repo_kind='image')
|
|
|
|
|
|
|
|
assert is_empty('devtable', 'somenewrepo')
|
|
|
|
assert not is_empty('devtable', 'simple')
|
2017-11-30 20:50:21 +00:00
|
|
|
|
|
|
|
@pytest.mark.skipif(os.environ.get('TEST_DATABASE_URI', '').find('mysql') >= 0,
|
|
|
|
reason='MySQL requires specialized indexing of newly created repos')
|
|
|
|
@pytest.mark.parametrize('query', [
|
|
|
|
(''),
|
|
|
|
('e'),
|
|
|
|
])
|
|
|
|
@pytest.mark.parametrize('authed_username', [
|
|
|
|
(None),
|
|
|
|
('devtable'),
|
|
|
|
])
|
|
|
|
def test_search_pagination(query, authed_username, initialized_db):
|
|
|
|
# Create some public repos.
|
|
|
|
repo1 = create_repository('devtable', 'somenewrepo', None, repo_kind='image', visibility='public')
|
|
|
|
repo2 = create_repository('devtable', 'somenewrepo2', None, repo_kind='image', visibility='public')
|
|
|
|
repo3 = create_repository('devtable', 'somenewrepo3', None, repo_kind='image', visibility='public')
|
|
|
|
|
|
|
|
repositories = get_filtered_matching_repositories(query, filter_username=authed_username)
|
|
|
|
assert len(repositories) > 3
|
|
|
|
|
|
|
|
next_repos = get_filtered_matching_repositories(query, filter_username=authed_username, offset=1)
|
|
|
|
assert repositories[0].id != next_repos[0].id
|
|
|
|
assert repositories[1].id == next_repos[0].id
|
2018-07-18 21:22:05 +00:00
|
|
|
|
|
|
|
|
|
|
|
def test_popular_repo_list(initialized_db):
|
|
|
|
onlypublic = model.repository.list_popular_public_repos(0, timedelta(weeks=1))
|
|
|
|
assert len(onlypublic) == 1
|
|
|
|
assert onlypublic[0] == ('public', 'publicrepo')
|