##// END OF EJS Templates
dependencies: bumped docutils to 0.13.1
dependencies: bumped docutils to 0.13.1

File last commit:

r1570:f2271c3d default
r1878:4f82258a default
Show More
test_simplegit.py
142 lines | 5.8 KiB | text/x-python | PythonLexer
project: added all source files and assets
r1 # -*- coding: utf-8 -*-
license: updated copyright year to 2017
r1271 # Copyright (C) 2010-2017 RhodeCode GmbH
project: added all source files and assets
r1 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import pytest
import urlparse
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 import mock
import simplejson as json
project: added all source files and assets
r1
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 from rhodecode.lib.vcs.backends.base import Config
project: added all source files and assets
r1 from rhodecode.tests.lib.middleware import mock_scm_app
import rhodecode.lib.middleware.simplegit as simplegit
git-lfs: added tests for git-lfs protocol detection...
r1567 def get_environ(url, request_method):
project: added all source files and assets
r1 """Construct a minimum WSGI environ based on the URL."""
parsed_url = urlparse.urlparse(url)
environ = {
'PATH_INFO': parsed_url.path,
'QUERY_STRING': parsed_url.query,
git-lfs: added tests for git-lfs protocol detection...
r1567 'REQUEST_METHOD': request_method,
project: added all source files and assets
r1 }
return environ
@pytest.mark.parametrize(
git-lfs: added tests for git-lfs protocol detection...
r1567 'url, expected_action, request_method',
project: added all source files and assets
r1 [
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/foo/bar/info/refs?service=git-upload-pack', 'pull', 'GET'),
('/foo/bar/info/refs?service=git-receive-pack', 'push', 'GET'),
('/foo/bar/git-upload-pack', 'pull', 'GET'),
('/foo/bar/git-receive-pack', 'push', 'GET'),
project: added all source files and assets
r1 # Edge case: missing data for info/refs
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/foo/info/refs?service=', 'pull', 'GET'),
('/foo/info/refs', 'pull', 'GET'),
project: added all source files and assets
r1 # Edge case: git command comes with service argument
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/foo/git-upload-pack?service=git-receive-pack', 'pull', 'GET'),
('/foo/git-receive-pack?service=git-upload-pack', 'push', 'GET'),
project: added all source files and assets
r1 # Edge case: repo name conflicts with git commands
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/git-receive-pack/git-upload-pack', 'pull', 'GET'),
('/git-receive-pack/git-receive-pack', 'push', 'GET'),
('/git-upload-pack/git-upload-pack', 'pull', 'GET'),
('/git-upload-pack/git-receive-pack', 'push', 'GET'),
('/foo/git-receive-pack', 'push', 'GET'),
project: added all source files and assets
r1 # Edge case: not a smart protocol url
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/foo/bar', 'pull', 'GET'),
# GIT LFS cases, batch
('/foo/bar/info/lfs/objects/batch', 'push', 'GET'),
('/foo/bar/info/lfs/objects/batch', 'pull', 'POST'),
# GIT LFS oid, dl/upl
('/foo/bar/info/lfs/abcdeabcde', 'pull', 'GET'),
('/foo/bar/info/lfs/abcdeabcde', 'push', 'PUT'),
('/foo/bar/info/lfs/abcdeabcde', 'push', 'POST'),
# Edge case: repo name conflicts with git commands
('/info/lfs/info/lfs/objects/batch', 'push', 'GET'),
('/info/lfs/info/lfs/objects/batch', 'pull', 'POST'),
project: added all source files and assets
r1 ])
git-lfs: added tests for git-lfs protocol detection...
r1567 def test_get_action(url, expected_action, request_method, pylonsapp):
project: added all source files and assets
r1 app = simplegit.SimpleGit(application=None,
Martin Bornhold
tests: Adapt tests to recent changes.
r592 config={'auth_ret_code': '', 'base_path': ''},
registry=None)
git-lfs: added tests for git-lfs protocol detection...
r1567 assert expected_action == app._get_action(get_environ(url, request_method))
project: added all source files and assets
r1
@pytest.mark.parametrize(
git-lfs: added tests for git-lfs protocol detection...
r1567 'url, expected_repo_name, request_method',
project: added all source files and assets
r1 [
git-lfs: added tests for git-lfs protocol detection...
r1567 ('/foo/info/refs?service=git-upload-pack', 'foo', 'GET'),
('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar', 'GET'),
('/foo/git-upload-pack', 'foo', 'GET'),
('/foo/git-receive-pack', 'foo', 'GET'),
('/foo/bar/git-upload-pack', 'foo/bar', 'GET'),
('/foo/bar/git-receive-pack', 'foo/bar', 'GET'),
# GIT LFS cases, batch
('/foo/bar/info/lfs/objects/batch', 'foo/bar', 'GET'),
('/example-git/info/lfs/objects/batch', 'example-git', 'POST'),
# GIT LFS oid, dl/upl
('/foo/info/lfs/abcdeabcde', 'foo', 'GET'),
('/foo/bar/info/lfs/abcdeabcde', 'foo/bar', 'PUT'),
('/my-git-repo/info/lfs/abcdeabcde', 'my-git-repo', 'POST'),
# Edge case: repo name conflicts with git commands
('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'GET'),
('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'POST'),
project: added all source files and assets
r1 ])
git-lfs: added tests for git-lfs protocol detection...
r1567 def test_get_repository_name(url, expected_repo_name, request_method, pylonsapp):
project: added all source files and assets
r1 app = simplegit.SimpleGit(application=None,
Martin Bornhold
tests: Adapt tests to recent changes.
r592 config={'auth_ret_code': '', 'base_path': ''},
registry=None)
git-lfs: added tests for git-lfs protocol detection...
r1567 assert expected_repo_name == app._get_repository_name(
get_environ(url, request_method))
project: added all source files and assets
r1
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 def test_get_config(pylonsapp, user_util):
repo = user_util.create_repo(repo_type='git')
project: added all source files and assets
r1 app = simplegit.SimpleGit(application=None,
Martin Bornhold
tests: Adapt tests to recent changes.
r592 config={'auth_ret_code': '', 'base_path': ''},
registry=None)
project: added all source files and assets
r1 extras = {'foo': 'FOO', 'bar': 'BAR'}
# We copy the extras as the method below will change the contents.
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 git_config = app._create_config(dict(extras), repo_name=repo.repo_name)
project: added all source files and assets
r1 expected_config = dict(extras)
expected_config.update({
'git_update_server_info': False,
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 'git_lfs_enabled': False,
'git_lfs_store_path': git_config['git_lfs_store_path']
project: added all source files and assets
r1 })
git-lfs: settings for GIT repos to enable git-lfs and set store location...
r1570 assert git_config == expected_config
project: added all source files and assets
r1
Martin Bornhold
tests: Adapt tests to recent changes.
r592 def test_create_wsgi_app_uses_scm_app_from_simplevcs(pylonsapp):
project: added all source files and assets
r1 config = {
'auth_ret_code': '',
'base_path': '',
'vcs.scm_app_implementation':
'rhodecode.tests.lib.middleware.mock_scm_app',
}
Martin Bornhold
tests: Adapt tests to recent changes.
r592 app = simplegit.SimpleGit(application=None, config=config, registry=None)
project: added all source files and assets
r1 wsgi_app = app._create_wsgi_app('/tmp/test', 'test_repo', {})
assert wsgi_app is mock_scm_app.mock_git_wsgi