##// END OF EJS Templates
git-lfs: added tests for git-lfs protocol detection...
marcink -
r1567:3205319d default
parent child Browse files
Show More
@@ -25,61 +25,86 b' from rhodecode.tests.lib.middleware impo'
25 import rhodecode.lib.middleware.simplegit as simplegit
25 import rhodecode.lib.middleware.simplegit as simplegit
26
26
27
27
28 def get_environ(url):
28 def get_environ(url, request_method):
29 """Construct a minimum WSGI environ based on the URL."""
29 """Construct a minimum WSGI environ based on the URL."""
30 parsed_url = urlparse.urlparse(url)
30 parsed_url = urlparse.urlparse(url)
31 environ = {
31 environ = {
32 'PATH_INFO': parsed_url.path,
32 'PATH_INFO': parsed_url.path,
33 'QUERY_STRING': parsed_url.query,
33 'QUERY_STRING': parsed_url.query,
34 'REQUEST_METHOD': request_method,
34 }
35 }
35
36
36 return environ
37 return environ
37
38
38
39
39 @pytest.mark.parametrize(
40 @pytest.mark.parametrize(
40 'url, expected_action',
41 'url, expected_action, request_method',
41 [
42 [
42 ('/foo/bar/info/refs?service=git-upload-pack', 'pull'),
43 ('/foo/bar/info/refs?service=git-upload-pack', 'pull', 'GET'),
43 ('/foo/bar/info/refs?service=git-receive-pack', 'push'),
44 ('/foo/bar/info/refs?service=git-receive-pack', 'push', 'GET'),
44 ('/foo/bar/git-upload-pack', 'pull'),
45 ('/foo/bar/git-upload-pack', 'pull', 'GET'),
45 ('/foo/bar/git-receive-pack', 'push'),
46 ('/foo/bar/git-receive-pack', 'push', 'GET'),
46 # Edge case: missing data for info/refs
47 # Edge case: missing data for info/refs
47 ('/foo/info/refs?service=', 'pull'),
48 ('/foo/info/refs?service=', 'pull', 'GET'),
48 ('/foo/info/refs', 'pull'),
49 ('/foo/info/refs', 'pull', 'GET'),
49 # Edge case: git command comes with service argument
50 # Edge case: git command comes with service argument
50 ('/foo/git-upload-pack?service=git-receive-pack', 'pull'),
51 ('/foo/git-upload-pack?service=git-receive-pack', 'pull', 'GET'),
51 ('/foo/git-receive-pack?service=git-upload-pack', 'push'),
52 ('/foo/git-receive-pack?service=git-upload-pack', 'push', 'GET'),
52 # Edge case: repo name conflicts with git commands
53 # Edge case: repo name conflicts with git commands
53 ('/git-receive-pack/git-upload-pack', 'pull'),
54 ('/git-receive-pack/git-upload-pack', 'pull', 'GET'),
54 ('/git-receive-pack/git-receive-pack', 'push'),
55 ('/git-receive-pack/git-receive-pack', 'push', 'GET'),
55 ('/git-upload-pack/git-upload-pack', 'pull'),
56 ('/git-upload-pack/git-upload-pack', 'pull', 'GET'),
56 ('/git-upload-pack/git-receive-pack', 'push'),
57 ('/git-upload-pack/git-receive-pack', 'push', 'GET'),
57 ('/foo/git-receive-pack', 'push'),
58 ('/foo/git-receive-pack', 'push', 'GET'),
58 # Edge case: not a smart protocol url
59 # Edge case: not a smart protocol url
59 ('/foo/bar', 'pull'),
60 ('/foo/bar', 'pull', 'GET'),
61 # GIT LFS cases, batch
62 ('/foo/bar/info/lfs/objects/batch', 'push', 'GET'),
63 ('/foo/bar/info/lfs/objects/batch', 'pull', 'POST'),
64 # GIT LFS oid, dl/upl
65 ('/foo/bar/info/lfs/abcdeabcde', 'pull', 'GET'),
66 ('/foo/bar/info/lfs/abcdeabcde', 'push', 'PUT'),
67 ('/foo/bar/info/lfs/abcdeabcde', 'push', 'POST'),
68 # Edge case: repo name conflicts with git commands
69 ('/info/lfs/info/lfs/objects/batch', 'push', 'GET'),
70 ('/info/lfs/info/lfs/objects/batch', 'pull', 'POST'),
71
60 ])
72 ])
61 def test_get_action(url, expected_action, pylonsapp):
73 def test_get_action(url, expected_action, request_method, pylonsapp):
62 app = simplegit.SimpleGit(application=None,
74 app = simplegit.SimpleGit(application=None,
63 config={'auth_ret_code': '', 'base_path': ''},
75 config={'auth_ret_code': '', 'base_path': ''},
64 registry=None)
76 registry=None)
65 assert expected_action == app._get_action(get_environ(url))
77 assert expected_action == app._get_action(get_environ(url, request_method))
66
78
67
79
68 @pytest.mark.parametrize(
80 @pytest.mark.parametrize(
69 'url, expected_repo_name',
81 'url, expected_repo_name, request_method',
70 [
82 [
71 ('/foo/info/refs?service=git-upload-pack', 'foo'),
83 ('/foo/info/refs?service=git-upload-pack', 'foo', 'GET'),
72 ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar'),
84 ('/foo/bar/info/refs?service=git-receive-pack', 'foo/bar', 'GET'),
73 ('/foo/git-upload-pack', 'foo'),
85 ('/foo/git-upload-pack', 'foo', 'GET'),
74 ('/foo/git-receive-pack', 'foo'),
86 ('/foo/git-receive-pack', 'foo', 'GET'),
75 ('/foo/bar/git-upload-pack', 'foo/bar'),
87 ('/foo/bar/git-upload-pack', 'foo/bar', 'GET'),
76 ('/foo/bar/git-receive-pack', 'foo/bar'),
88 ('/foo/bar/git-receive-pack', 'foo/bar', 'GET'),
89
90 # GIT LFS cases, batch
91 ('/foo/bar/info/lfs/objects/batch', 'foo/bar', 'GET'),
92 ('/example-git/info/lfs/objects/batch', 'example-git', 'POST'),
93 # GIT LFS oid, dl/upl
94 ('/foo/info/lfs/abcdeabcde', 'foo', 'GET'),
95 ('/foo/bar/info/lfs/abcdeabcde', 'foo/bar', 'PUT'),
96 ('/my-git-repo/info/lfs/abcdeabcde', 'my-git-repo', 'POST'),
97 # Edge case: repo name conflicts with git commands
98 ('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'GET'),
99 ('/info/lfs/info/lfs/objects/batch', 'info/lfs', 'POST'),
100
77 ])
101 ])
78 def test_get_repository_name(url, expected_repo_name, pylonsapp):
102 def test_get_repository_name(url, expected_repo_name, request_method, pylonsapp):
79 app = simplegit.SimpleGit(application=None,
103 app = simplegit.SimpleGit(application=None,
80 config={'auth_ret_code': '', 'base_path': ''},
104 config={'auth_ret_code': '', 'base_path': ''},
81 registry=None)
105 registry=None)
82 assert expected_repo_name == app._get_repository_name(get_environ(url))
106 assert expected_repo_name == app._get_repository_name(
107 get_environ(url, request_method))
83
108
84
109
85 def test_get_config(pylonsapp):
110 def test_get_config(pylonsapp):
@@ -93,6 +118,8 b' def test_get_config(pylonsapp):'
93 expected_config = dict(extras)
118 expected_config = dict(extras)
94 expected_config.update({
119 expected_config.update({
95 'git_update_server_info': False,
120 'git_update_server_info': False,
121 'git_lfs_enabled': True,
122 'git_lfs_store_path': simplegit.default_lfs_store()
96 })
123 })
97
124
98 assert config == expected_config
125 assert config == expected_config
General Comments 0
You need to be logged in to leave comments. Login now