##// END OF EJS Templates
fixed issue with renaming repos group together with changing parents with multiple nested trees...
marcink -
r3459:94f251fd beta
parent child Browse files
Show More
@@ -1345,15 +1345,13 b' class RepoGroup(Base, BaseModel):'
1345 1345
1346 1346 return cnt + children_count(self)
1347 1347
1348 def recursive_groups_and_repos(self):
1349 """
1350 Recursive return all groups, with repositories in those groups
1351 """
1348 def _recursive_objects(self, include_repos=True):
1352 1349 all_ = []
1353 1350
1354 1351 def _get_members(root_gr):
1355 for r in root_gr.repositories:
1356 all_.append(r)
1352 if include_repos:
1353 for r in root_gr.repositories:
1354 all_.append(r)
1357 1355 childs = root_gr.children.all()
1358 1356 if childs:
1359 1357 for gr in childs:
@@ -1363,6 +1361,18 b' class RepoGroup(Base, BaseModel):'
1363 1361 _get_members(self)
1364 1362 return [self] + all_
1365 1363
1364 def recursive_groups_and_repos(self):
1365 """
1366 Recursive return all groups, with repositories in those groups
1367 """
1368 return self._recursive_objects()
1369
1370 def recursive_groups(self):
1371 """
1372 Returns all children groups for this group including children of children
1373 """
1374 return self._recursive_objects(include_repos=False)
1375
1366 1376 def get_new_name(self, group_name):
1367 1377 """
1368 1378 returns new full group name based on parent and new name
@@ -249,27 +249,37 b' class ReposGroupModel(BaseModel):'
249 249
250 250 # change properties
251 251 repos_group.group_description = form_data['group_description']
252 repos_group.parent_group = RepoGroup.get(form_data['group_parent_id'])
253 252 repos_group.group_parent_id = form_data['group_parent_id']
254 253 repos_group.enable_locking = form_data['enable_locking']
254
255 repos_group.parent_group = RepoGroup.get(form_data['group_parent_id'])
255 256 repos_group.group_name = repos_group.get_new_name(form_data['group_name'])
256 257 new_path = repos_group.full_path
257
258 258 self.sa.add(repos_group)
259 259
260 # iterate over all members of this groups and set the locking !
260 # iterate over all members of this groups and do fixes
261 # set locking if given
262 # if obj is a repoGroup also fix the name of the group according
263 # to the parent
264 # if obj is a Repo fix it's name
261 265 # this can be potentially heavy operation
262 266 for obj in repos_group.recursive_groups_and_repos():
263 267 #set the value from it's parent
264 268 obj.enable_locking = repos_group.enable_locking
269 if isinstance(obj, RepoGroup):
270 new_name = obj.get_new_name(obj.name)
271 log.debug('Fixing group %s to new name %s' \
272 % (obj.group_name, new_name))
273 obj.group_name = new_name
274 elif isinstance(obj, Repository):
275 # we need to get all repositories from this new group and
276 # rename them accordingly to new group path
277 new_name = obj.get_new_name(obj.just_name)
278 log.debug('Fixing repo %s to new name %s' \
279 % (obj.repo_name, new_name))
280 obj.repo_name = new_name
265 281 self.sa.add(obj)
266 282
267 # we need to get all repositories from this new group and
268 # rename them accordingly to new group path
269 for r in repos_group.repositories:
270 r.repo_name = r.get_new_name(r.just_name)
271 self.sa.add(r)
272
273 283 self.__rename_group(old_path, new_path)
274 284
275 285 return repos_group
@@ -47,7 +47,8 b' log = logging.getLogger(__name__)'
47 47 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
48 48 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
49 49 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
50 'GIT_REMOTE_REPO', 'SCM_TESTS', '_get_repo_create_params'
50 'GIT_REMOTE_REPO', 'SCM_TESTS', '_get_repo_create_params',
51 '_get_group_create_params'
51 52 ]
52 53
53 54 # Invoke websetup with the current config file
@@ -183,3 +184,18 b' def _get_repo_create_params(**custom):'
183 184 defs.update({'repo_name_full': defs['repo_name']})
184 185
185 186 return defs
187
188
189 def _get_group_create_params(**custom):
190 defs = dict(
191 group_name=None,
192 group_description='DESC',
193 group_parent_id=None,
194 perms_updates=[],
195 perms_new=[],
196 enable_locking=False,
197 recursive=False
198 )
199 defs.update(custom)
200
201 return defs
@@ -21,6 +21,33 b" def _make_group(path, desc='desc', paren"
21 21 return gr
22 22
23 23
24 def _update_group(id_, group_name, desc='desc', parent_id=None):
25 form_data = _get_group_create_params(group_name=group_name,
26 group_desc=desc,
27 group_parent_id=parent_id)
28 gr = ReposGroupModel().update(id_, form_data)
29 return gr
30
31
32 def _make_repo(name, **kwargs):
33 form_data = _get_repo_create_params(repo_name=name, **kwargs)
34 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
35 r = RepoModel().create(form_data, cur_user)
36 return r
37
38
39 def _update_repo(name, **kwargs):
40 form_data = _get_repo_create_params(**kwargs)
41 if not 'repo_name' in kwargs:
42 form_data['repo_name'] = name
43 if not 'perms_new' in kwargs:
44 form_data['perms_new'] = []
45 if not 'perms_updates' in kwargs:
46 form_data['perms_updates'] = []
47 r = RepoModel().update(name, **form_data)
48 return r
49
50
24 51 class TestReposGroups(unittest.TestCase):
25 52
26 53 def setUp(self):
@@ -32,7 +59,7 b' class TestReposGroups(unittest.TestCase)'
32 59 Session().commit()
33 60
34 61 def tearDown(self):
35 print 'out'
62 Session.remove()
36 63
37 64 def __check_path(self, *path):
38 65 """
@@ -48,21 +75,9 b' class TestReposGroups(unittest.TestCase)'
48 75 def __delete_group(self, id_):
49 76 ReposGroupModel().delete(id_)
50 77
51 def __update_group(self, id_, path, desc='desc', parent_id=None):
52 form_data = dict(
53 group_name=path,
54 group_description=desc,
55 group_parent_id=parent_id,
56 perms_updates=[],
57 perms_new=[],
58 enable_locking=False,
59 recursive=False
60 )
61 gr = ReposGroupModel().update(id_, form_data)
62 return gr
63
64 78 def test_create_group(self):
65 79 g = _make_group('newGroup')
80 Session().commit()
66 81 self.assertEqual(g.full_path, 'newGroup')
67 82
68 83 self.assertTrue(self.__check_path('newGroup'))
@@ -73,23 +88,27 b' class TestReposGroups(unittest.TestCase)'
73 88
74 89 def test_same_subgroup(self):
75 90 sg1 = _make_group('sub1', parent_id=self.g1.group_id)
91 Session().commit()
76 92 self.assertEqual(sg1.parent_group, self.g1)
77 93 self.assertEqual(sg1.full_path, 'test1/sub1')
78 94 self.assertTrue(self.__check_path('test1', 'sub1'))
79 95
80 96 ssg1 = _make_group('subsub1', parent_id=sg1.group_id)
97 Session().commit()
81 98 self.assertEqual(ssg1.parent_group, sg1)
82 99 self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1')
83 100 self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1'))
84 101
85 102 def test_remove_group(self):
86 103 sg1 = _make_group('deleteme')
104 Session().commit()
87 105 self.__delete_group(sg1.group_id)
88 106
89 107 self.assertEqual(RepoGroup.get(sg1.group_id), None)
90 108 self.assertFalse(self.__check_path('deteteme'))
91 109
92 110 sg1 = _make_group('deleteme', parent_id=self.g1.group_id)
111 Session().commit()
93 112 self.__delete_group(sg1.group_id)
94 113
95 114 self.assertEqual(RepoGroup.get(sg1.group_id), None)
@@ -97,24 +116,26 b' class TestReposGroups(unittest.TestCase)'
97 116
98 117 def test_rename_single_group(self):
99 118 sg1 = _make_group('initial')
119 Session().commit()
100 120
101 new_sg1 = self.__update_group(sg1.group_id, 'after')
121 new_sg1 = _update_group(sg1.group_id, 'after')
102 122 self.assertTrue(self.__check_path('after'))
103 123 self.assertEqual(RepoGroup.get_by_group_name('initial'), None)
104 124
105 125 def test_update_group_parent(self):
106 126
107 127 sg1 = _make_group('initial', parent_id=self.g1.group_id)
128 Session().commit()
108 129
109 new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
130 new_sg1 = _update_group(sg1.group_id, 'after', parent_id=self.g1.group_id)
110 131 self.assertTrue(self.__check_path('test1', 'after'))
111 132 self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None)
112 133
113 new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
134 new_sg1 = _update_group(sg1.group_id, 'after', parent_id=self.g3.group_id)
114 135 self.assertTrue(self.__check_path('test3', 'after'))
115 136 self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None)
116 137
117 new_sg1 = self.__update_group(sg1.group_id, 'hello')
138 new_sg1 = _update_group(sg1.group_id, 'hello')
118 139 self.assertTrue(self.__check_path('hello'))
119 140
120 141 self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1)
@@ -123,23 +144,17 b' class TestReposGroups(unittest.TestCase)'
123 144
124 145 g1 = _make_group('g1')
125 146 g2 = _make_group('g2')
126
147 Session().commit()
127 148 # create new repo
128 form_data = _get_repo_create_params(repo_name='john')
129 cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN)
130 r = RepoModel().create(form_data, cur_user)
131
149 r = _make_repo('john')
150 Session().commit()
132 151 self.assertEqual(r.repo_name, 'john')
133
134 152 # put repo into group
135 form_data = form_data
136 form_data['repo_group'] = g1.group_id
137 form_data['perms_new'] = []
138 form_data['perms_updates'] = []
139 RepoModel().update(r.repo_name, **form_data)
153 r = _update_repo('john', repo_group=g1.group_id)
154 Session().commit()
140 155 self.assertEqual(r.repo_name, 'g1/john')
141 156
142 self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id)
157 _update_group(g1.group_id, 'g1', parent_id=g2.group_id)
143 158 self.assertTrue(self.__check_path('g2', 'g1'))
144 159
145 160 # test repo
@@ -155,7 +170,7 b' class TestReposGroups(unittest.TestCase)'
155 170 self.assertEqual(g2.full_path, 't11/t22')
156 171 self.assertTrue(self.__check_path('t11', 't22'))
157 172
158 g2 = self.__update_group(g2.group_id, 'g22', parent_id=None)
173 g2 = _update_group(g2.group_id, 'g22', parent_id=None)
159 174 Session().commit()
160 175
161 176 self.assertEqual(g2.group_name, 'g22')
@@ -163,3 +178,65 b' class TestReposGroups(unittest.TestCase)'
163 178 self.assertEqual(g2.full_path, 'g22')
164 179 self.assertFalse(self.__check_path('t11', 't22'))
165 180 self.assertTrue(self.__check_path('g22'))
181
182 def test_rename_top_level_group_in_nested_setup(self):
183 g1 = _make_group('L1')
184 Session().commit()
185 g2 = _make_group('L2', parent_id=g1.group_id)
186 Session().commit()
187 g3 = _make_group('L3', parent_id=g2.group_id)
188 Session().commit()
189
190 r = _make_repo('L1/L2/L3/L3_REPO', repo_group=g3.group_id)
191 Session().commit()
192
193 ##rename L1 all groups should be now changed
194 _update_group(g1.group_id, 'L1_NEW')
195 Session().commit()
196 self.assertEqual(g1.full_path, 'L1_NEW')
197 self.assertEqual(g2.full_path, 'L1_NEW/L2')
198 self.assertEqual(g3.full_path, 'L1_NEW/L2/L3')
199 self.assertEqual(r.repo_name, 'L1_NEW/L2/L3/L3_REPO')
200
201 def test_change_parent_of_top_level_group_in_nested_setup(self):
202 g1 = _make_group('R1')
203 Session().commit()
204 g2 = _make_group('R2', parent_id=g1.group_id)
205 Session().commit()
206 g3 = _make_group('R3', parent_id=g2.group_id)
207 Session().commit()
208
209 g4 = _make_group('R1_NEW')
210 Session().commit()
211
212 r = _make_repo('R1/R2/R3/R3_REPO', repo_group=g3.group_id)
213 Session().commit()
214 ##rename L1 all groups should be now changed
215 _update_group(g1.group_id, 'R1', parent_id=g4.group_id)
216 Session().commit()
217 self.assertEqual(g1.full_path, 'R1_NEW/R1')
218 self.assertEqual(g2.full_path, 'R1_NEW/R1/R2')
219 self.assertEqual(g3.full_path, 'R1_NEW/R1/R2/R3')
220 self.assertEqual(r.repo_name, 'R1_NEW/R1/R2/R3/R3_REPO')
221
222 def test_change_parent_of_top_level_group_in_nested_setup_with_rename(self):
223 g1 = _make_group('X1')
224 Session().commit()
225 g2 = _make_group('X2', parent_id=g1.group_id)
226 Session().commit()
227 g3 = _make_group('X3', parent_id=g2.group_id)
228 Session().commit()
229
230 g4 = _make_group('X1_NEW')
231 Session().commit()
232
233 r = _make_repo('X1/X2/X3/X3_REPO', repo_group=g3.group_id)
234 Session().commit()
235
236 ##rename L1 all groups should be now changed
237 _update_group(g1.group_id, 'X1_PRIM', parent_id=g4.group_id)
238 Session().commit()
239 self.assertEqual(g1.full_path, 'X1_NEW/X1_PRIM')
240 self.assertEqual(g2.full_path, 'X1_NEW/X1_PRIM/X2')
241 self.assertEqual(g3.full_path, 'X1_NEW/X1_PRIM/X2/X3')
242 self.assertEqual(r.repo_name, 'X1_NEW/X1_PRIM/X2/X3/X3_REPO')
General Comments 0
You need to be logged in to leave comments. Login now