##// END OF EJS Templates
Use master branch on master bookmark to test with travis
marcink -
r3975:69377d1d default
parent child Browse files
Show More
@@ -1,42 +1,42 b''
1 language: python
1 language: python
2 python:
2 python:
3 - "2.5"
3 - "2.5"
4 - "2.6"
4 - "2.6"
5 - "2.7"
5 - "2.7"
6
6
7 env:
7 env:
8 - TEST_DB=sqlite:////tmp/rhodecode_test.sqlite
8 - TEST_DB=sqlite:////tmp/rhodecode_test.sqlite
9 - TEST_DB=mysql://root@127.0.0.1/rhodecode_test
9 - TEST_DB=mysql://root@127.0.0.1/rhodecode_test
10 - TEST_DB=postgresql://postgres@127.0.0.1/rhodecode_test
10 - TEST_DB=postgresql://postgres@127.0.0.1/rhodecode_test
11
11
12 services:
12 services:
13 - mysql
13 - mysql
14 - postgresql
14 - postgresql
15
15
16 # command to install dependencies
16 # command to install dependencies
17 before_script:
17 before_script:
18 - mysql -e 'create database rhodecode_test;'
18 - mysql -e 'create database rhodecode_test;'
19 - psql -c 'create database rhodecode_test;' -U postgres
19 - psql -c 'create database rhodecode_test;' -U postgres
20 - git --version
20 - git --version
21
21
22 before_install:
22 before_install:
23 - sudo apt-get remove git
23 - sudo apt-get remove git
24 - sudo add-apt-repository ppa:pdoes/ppa -y
24 - sudo add-apt-repository ppa:pdoes/ppa -y
25 - sudo apt-get update -y
25 - sudo apt-get update -y
26 - sudo apt-get install git -y
26 - sudo apt-get install git -y
27
27
28 install:
28 install:
29 - pip install mysql-python psycopg2 mock unittest2
29 - pip install mysql-python psycopg2 mock unittest2
30 - pip install . --use-mirrors
30 - pip install . --use-mirrors
31
31
32 # command to run tests
32 # command to run tests
33 script: nosetests
33 script: nosetests
34
34
35 notifications:
35 notifications:
36 email:
36 email:
37 - marcinkuz@gmail.com
37 - marcinkuz@gmail.com
38 irc: "irc.freenode.org#rhodecode"
38 irc: "irc.freenode.org#rhodecode"
39
39
40 branches:
40 branches:
41 only:
41 only:
42 - dev
42 - master
@@ -1,162 +1,190 b''
1 import functools
1 import functools
2 from rhodecode.tests import *
2 from rhodecode.tests import *
3
3
4 from rhodecode.model.repos_group import ReposGroupModel
4 from rhodecode.model.repos_group import ReposGroupModel
5 from rhodecode.model.db import RepoGroup, Repository, User
5 from rhodecode.model.db import RepoGroup, Repository, User
6
6
7 from rhodecode.model.meta import Session
7 from rhodecode.model.meta import Session
8 from nose.tools import with_setup
8 from nose.tools import with_setup
9 from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \
9 from rhodecode.tests.models.common import _create_project_tree, check_tree_perms, \
10 _get_perms, _check_expected_count, expected_count, _destroy_project_tree
10 _get_perms, _check_expected_count, expected_count, _destroy_project_tree
11
11
12
12
13 test_u1_id = None
13 test_u1_id = None
14 _get_repo_perms = None
14 _get_repo_perms = None
15 _get_group_perms = None
15 _get_group_perms = None
16
16
17
17
18 def permissions_setup_func(group_name='g0', perm='group.read', recursive=True):
18 def permissions_setup_func(group_name='g0', perm='group.read', recursive=True,
19 user_id=None):
19 """
20 """
20 Resets all permissions to perm attribute
21 Resets all permissions to perm attribute
21 """
22 """
23 if not user_id:
24 user_id = test_u1_id
22 repos_group = RepoGroup.get_by_group_name(group_name=group_name)
25 repos_group = RepoGroup.get_by_group_name(group_name=group_name)
23 if not repos_group:
26 if not repos_group:
24 raise Exception('Cannot get group %s' % group_name)
27 raise Exception('Cannot get group %s' % group_name)
25 perms_updates = [[test_u1_id, perm, 'user']]
28 perms_updates = [[user_id, perm, 'user']]
26 ReposGroupModel()._update_permissions(repos_group,
29 ReposGroupModel()._update_permissions(repos_group,
27 perms_updates=perms_updates,
30 perms_updates=perms_updates,
28 recursive=recursive,
31 recursive=recursive,
29 check_perms=False)
32 check_perms=False)
30 Session().commit()
33 Session().commit()
31
34
32
35
33 def setup_module():
36 def setup_module():
34 global test_u1_id, _get_repo_perms, _get_group_perms
37 global test_u1_id, _get_repo_perms, _get_group_perms
35 test_u1 = _create_project_tree()
38 test_u1 = _create_project_tree()
36 Session().commit()
39 Session().commit()
37 test_u1_id = test_u1.user_id
40 test_u1_id = test_u1.user_id
38 _get_repo_perms = functools.partial(_get_perms, key='repositories',
41 _get_repo_perms = functools.partial(_get_perms, key='repositories',
39 test_u1_id=test_u1_id)
42 test_u1_id=test_u1_id)
40 _get_group_perms = functools.partial(_get_perms, key='repositories_groups',
43 _get_group_perms = functools.partial(_get_perms, key='repositories_groups',
41 test_u1_id=test_u1_id)
44 test_u1_id=test_u1_id)
42
45
43
46
44 def teardown_module():
47 def teardown_module():
45 _destroy_project_tree(test_u1_id)
48 _destroy_project_tree(test_u1_id)
46
49
47
50
48 @with_setup(permissions_setup_func)
51 @with_setup(permissions_setup_func)
49 def test_user_permissions_on_group_without_recursive_mode():
52 def test_user_permissions_on_group_without_recursive_mode():
50 # set permission to g0 non-recursive mode
53 # set permission to g0 non-recursive mode
51 recursive = False
54 recursive = False
52 group = 'g0'
55 group = 'g0'
53 permissions_setup_func(group, 'group.write', recursive=recursive)
56 permissions_setup_func(group, 'group.write', recursive=recursive)
54
57
55 items = [x for x in _get_repo_perms(group, recursive)]
58 items = [x for x in _get_repo_perms(group, recursive)]
56 expected = 0
59 expected = 0
57 assert len(items) == expected, ' %s != %s' % (len(items), expected)
60 assert len(items) == expected, ' %s != %s' % (len(items), expected)
58 for name, perm in items:
61 for name, perm in items:
59 yield check_tree_perms, name, perm, group, 'repository.read'
62 yield check_tree_perms, name, perm, group, 'repository.read'
60
63
61 items = [x for x in _get_group_perms(group, recursive)]
64 items = [x for x in _get_group_perms(group, recursive)]
62 expected = 1
65 expected = 1
63 assert len(items) == expected, ' %s != %s' % (len(items), expected)
66 assert len(items) == expected, ' %s != %s' % (len(items), expected)
64 for name, perm in items:
67 for name, perm in items:
65 yield check_tree_perms, name, perm, group, 'group.write'
68 yield check_tree_perms, name, perm, group, 'group.write'
66
69
67
70
68 @with_setup(permissions_setup_func)
71 @with_setup(permissions_setup_func)
69 def test_user_permissions_on_group_without_recursive_mode_subgroup():
72 def test_user_permissions_on_group_without_recursive_mode_subgroup():
70 # set permission to g0 non-recursive mode
73 # set permission to g0 non-recursive mode
71 recursive = False
74 recursive = False
72 group = 'g0/g0_1'
75 group = 'g0/g0_1'
73 permissions_setup_func(group, 'group.write', recursive=recursive)
76 permissions_setup_func(group, 'group.write', recursive=recursive)
74
77
75 items = [x for x in _get_repo_perms(group, recursive)]
78 items = [x for x in _get_repo_perms(group, recursive)]
76 expected = 0
79 expected = 0
77 assert len(items) == expected, ' %s != %s' % (len(items), expected)
80 assert len(items) == expected, ' %s != %s' % (len(items), expected)
78 for name, perm in items:
81 for name, perm in items:
79 yield check_tree_perms, name, perm, group, 'repository.read'
82 yield check_tree_perms, name, perm, group, 'repository.read'
80
83
81 items = [x for x in _get_group_perms(group, recursive)]
84 items = [x for x in _get_group_perms(group, recursive)]
82 expected = 1
85 expected = 1
83 assert len(items) == expected, ' %s != %s' % (len(items), expected)
86 assert len(items) == expected, ' %s != %s' % (len(items), expected)
84 for name, perm in items:
87 for name, perm in items:
85 yield check_tree_perms, name, perm, group, 'group.write'
88 yield check_tree_perms, name, perm, group, 'group.write'
86
89
87
90
88 @with_setup(permissions_setup_func)
91 @with_setup(permissions_setup_func)
89 def test_user_permissions_on_group_with_recursive_mode():
92 def test_user_permissions_on_group_with_recursive_mode():
90
93
91 # set permission to g0 recursive mode, all children including
94 # set permission to g0 recursive mode, all children including
92 # other repos and groups should have this permission now set !
95 # other repos and groups should have this permission now set !
93 recursive = True
96 recursive = True
94 group = 'g0'
97 group = 'g0'
95 permissions_setup_func(group, 'group.write', recursive=recursive)
98 permissions_setup_func(group, 'group.write', recursive=recursive)
96
99
97 repo_items = [x for x in _get_repo_perms(group, recursive)]
100 repo_items = [x for x in _get_repo_perms(group, recursive)]
98 items = [x for x in _get_group_perms(group, recursive)]
101 items = [x for x in _get_group_perms(group, recursive)]
99 _check_expected_count(items, repo_items, expected_count(group, True))
102 _check_expected_count(items, repo_items, expected_count(group, True))
100
103
101 for name, perm in repo_items:
104 for name, perm in repo_items:
102 if name == 'g0/g0_3/g0_3_r1_private':
105 yield check_tree_perms, name, perm, group, 'repository.write'
103 yield check_tree_perms, name, perm, group, 'repository.none'
106
104 else:
107 for name, perm in items:
108 yield check_tree_perms, name, perm, group, 'group.write'
109
110
111 @with_setup(permissions_setup_func)
112 def test_user_permissions_on_group_with_recursive_mode_for_default_user():
113
114 # set permission to g0 recursive mode, all children including
115 # other repos and groups should have this permission now set !
116 recursive = True
117 group = 'g0'
118 default_user_id = User.get_default_user().user_id
119 permissions_setup_func(group, 'group.write', recursive=recursive,
120 user_id=default_user_id)
121
122 # change default to get perms for default user
123 _get_repo_perms = functools.partial(_get_perms, key='repositories',
124 test_u1_id=default_user_id)
125 _get_group_perms = functools.partial(_get_perms, key='repositories_groups',
126 test_u1_id=default_user_id)
127
128 repo_items = [x for x in _get_repo_perms(group, recursive)]
129 items = [x for x in _get_group_perms(group, recursive)]
130 _check_expected_count(items, repo_items, expected_count(group, True))
131
132 for name, perm in repo_items:
105 yield check_tree_perms, name, perm, group, 'repository.write'
133 yield check_tree_perms, name, perm, group, 'repository.write'
106
134
107 for name, perm in items:
135 for name, perm in items:
108 yield check_tree_perms, name, perm, group, 'group.write'
136 yield check_tree_perms, name, perm, group, 'group.write'
109
137
110
138
111 @with_setup(permissions_setup_func)
139 @with_setup(permissions_setup_func)
112 def test_user_permissions_on_group_with_recursive_mode_inner_group():
140 def test_user_permissions_on_group_with_recursive_mode_inner_group():
113 ## set permission to g0_3 group to none
141 ## set permission to g0_3 group to none
114 recursive = True
142 recursive = True
115 group = 'g0/g0_3'
143 group = 'g0/g0_3'
116 permissions_setup_func(group, 'group.none', recursive=recursive)
144 permissions_setup_func(group, 'group.none', recursive=recursive)
117
145
118 repo_items = [x for x in _get_repo_perms(group, recursive)]
146 repo_items = [x for x in _get_repo_perms(group, recursive)]
119 items = [x for x in _get_group_perms(group, recursive)]
147 items = [x for x in _get_group_perms(group, recursive)]
120 _check_expected_count(items, repo_items, expected_count(group, True))
148 _check_expected_count(items, repo_items, expected_count(group, True))
121
149
122 for name, perm in repo_items:
150 for name, perm in repo_items:
123 yield check_tree_perms, name, perm, group, 'repository.none'
151 yield check_tree_perms, name, perm, group, 'repository.none'
124
152
125 for name, perm in items:
153 for name, perm in items:
126 yield check_tree_perms, name, perm, group, 'group.none'
154 yield check_tree_perms, name, perm, group, 'group.none'
127
155
128
156
129 @with_setup(permissions_setup_func)
157 @with_setup(permissions_setup_func)
130 def test_user_permissions_on_group_with_recursive_mode_deepest():
158 def test_user_permissions_on_group_with_recursive_mode_deepest():
131 ## set permission to g0_3 group to none
159 ## set permission to g0_3 group to none
132 recursive = True
160 recursive = True
133 group = 'g0/g0_1/g0_1_1'
161 group = 'g0/g0_1/g0_1_1'
134 permissions_setup_func(group, 'group.write', recursive=recursive)
162 permissions_setup_func(group, 'group.write', recursive=recursive)
135
163
136 repo_items = [x for x in _get_repo_perms(group, recursive)]
164 repo_items = [x for x in _get_repo_perms(group, recursive)]
137 items = [x for x in _get_group_perms(group, recursive)]
165 items = [x for x in _get_group_perms(group, recursive)]
138 _check_expected_count(items, repo_items, expected_count(group, True))
166 _check_expected_count(items, repo_items, expected_count(group, True))
139
167
140 for name, perm in repo_items:
168 for name, perm in repo_items:
141 yield check_tree_perms, name, perm, group, 'repository.write'
169 yield check_tree_perms, name, perm, group, 'repository.write'
142
170
143 for name, perm in items:
171 for name, perm in items:
144 yield check_tree_perms, name, perm, group, 'group.write'
172 yield check_tree_perms, name, perm, group, 'group.write'
145
173
146
174
147 @with_setup(permissions_setup_func)
175 @with_setup(permissions_setup_func)
148 def test_user_permissions_on_group_with_recursive_mode_only_with_repos():
176 def test_user_permissions_on_group_with_recursive_mode_only_with_repos():
149 ## set permission to g0_3 group to none
177 ## set permission to g0_3 group to none
150 recursive = True
178 recursive = True
151 group = 'g0/g0_2'
179 group = 'g0/g0_2'
152 permissions_setup_func(group, 'group.admin', recursive=recursive)
180 permissions_setup_func(group, 'group.admin', recursive=recursive)
153
181
154 repo_items = [x for x in _get_repo_perms(group, recursive)]
182 repo_items = [x for x in _get_repo_perms(group, recursive)]
155 items = [x for x in _get_group_perms(group, recursive)]
183 items = [x for x in _get_group_perms(group, recursive)]
156 _check_expected_count(items, repo_items, expected_count(group, True))
184 _check_expected_count(items, repo_items, expected_count(group, True))
157
185
158 for name, perm in repo_items:
186 for name, perm in repo_items:
159 yield check_tree_perms, name, perm, group, 'repository.admin'
187 yield check_tree_perms, name, perm, group, 'repository.admin'
160
188
161 for name, perm in items:
189 for name, perm in items:
162 yield check_tree_perms, name, perm, group, 'group.admin'
190 yield check_tree_perms, name, perm, group, 'group.admin'
General Comments 0
You need to be logged in to leave comments. Login now