Show More
@@ -1,199 +1,199 b'' | |||
|
1 | 1 | import os |
|
2 | 2 | from sqlalchemy.exc import IntegrityError |
|
3 | 3 | |
|
4 | 4 | from kallithea.tests import * |
|
5 | 5 | from kallithea.tests.fixture import Fixture |
|
6 | 6 | |
|
7 | 7 | from kallithea.model.repo_group import RepoGroupModel |
|
8 | 8 | from kallithea.model.repo import RepoModel |
|
9 | 9 | from kallithea.model.db import RepoGroup |
|
10 | 10 | from kallithea.model.meta import Session |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 | fixture = Fixture() |
|
14 | 14 | |
|
15 | 15 | |
|
16 | 16 | def _update_group(id_, group_name, desc=u'desc', parent_id=None): |
|
17 | 17 | form_data = fixture._get_group_create_params(group_name=group_name, |
|
18 | 18 | group_desc=desc, |
|
19 | 19 | group_parent_id=parent_id) |
|
20 | 20 | gr = RepoGroupModel().update(id_, form_data) |
|
21 | 21 | return gr |
|
22 | 22 | |
|
23 | 23 | |
|
24 | 24 | def _update_repo(name, **kwargs): |
|
25 | 25 | form_data = fixture._get_repo_create_params(**kwargs) |
|
26 | 26 | if not 'repo_name' in kwargs: |
|
27 | 27 | form_data['repo_name'] = name |
|
28 | 28 | if not 'perms_new' in kwargs: |
|
29 | 29 | form_data['perms_new'] = [] |
|
30 | 30 | if not 'perms_updates' in kwargs: |
|
31 | 31 | form_data['perms_updates'] = [] |
|
32 | 32 | r = RepoModel().update(name, **form_data) |
|
33 | 33 | return r |
|
34 | 34 | |
|
35 | 35 | |
|
36 | 36 | class TestRepoGroups(TestControllerPytest): |
|
37 | 37 | |
|
38 | 38 | def setup_method(self, method): |
|
39 | 39 | self.g1 = fixture.create_repo_group(u'test1', skip_if_exists=True) |
|
40 | 40 | self.g2 = fixture.create_repo_group(u'test2', skip_if_exists=True) |
|
41 | 41 | self.g3 = fixture.create_repo_group(u'test3', skip_if_exists=True) |
|
42 | 42 | |
|
43 | 43 | def teardown_method(self, method): |
|
44 | 44 | Session.remove() |
|
45 | 45 | |
|
46 | 46 | def __check_path(self, *path): |
|
47 | 47 | """ |
|
48 |
Checks the path for exist |
|
|
48 | Checks the path for existence ! | |
|
49 | 49 | """ |
|
50 | 50 | path = [TESTS_TMP_PATH] + list(path) |
|
51 | 51 | path = os.path.join(*path) |
|
52 | 52 | return os.path.isdir(path) |
|
53 | 53 | |
|
54 | 54 | def _check_folders(self): |
|
55 | 55 | print os.listdir(TESTS_TMP_PATH) |
|
56 | 56 | |
|
57 | 57 | def __delete_group(self, id_): |
|
58 | 58 | RepoGroupModel().delete(id_) |
|
59 | 59 | |
|
60 | 60 | def test_create_group(self): |
|
61 | 61 | g = fixture.create_repo_group(u'newGroup') |
|
62 | 62 | Session().commit() |
|
63 | 63 | self.assertEqual(g.full_path, 'newGroup') |
|
64 | 64 | |
|
65 | 65 | self.assertTrue(self.__check_path('newGroup')) |
|
66 | 66 | |
|
67 | 67 | def test_create_same_name_group(self): |
|
68 | 68 | self.assertRaises(IntegrityError, lambda: fixture.create_repo_group(u'newGroup')) |
|
69 | 69 | Session().rollback() |
|
70 | 70 | |
|
71 | 71 | def test_same_subgroup(self): |
|
72 | 72 | sg1 = fixture.create_repo_group(u'sub1', group_parent_id=self.g1.group_id) |
|
73 | 73 | self.assertEqual(sg1.parent_group, self.g1) |
|
74 | 74 | self.assertEqual(sg1.full_path, 'test1/sub1') |
|
75 | 75 | self.assertTrue(self.__check_path('test1', 'sub1')) |
|
76 | 76 | |
|
77 | 77 | ssg1 = fixture.create_repo_group(u'subsub1', group_parent_id=sg1.group_id) |
|
78 | 78 | self.assertEqual(ssg1.parent_group, sg1) |
|
79 | 79 | self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1') |
|
80 | 80 | self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1')) |
|
81 | 81 | |
|
82 | 82 | def test_remove_group(self): |
|
83 | 83 | sg1 = fixture.create_repo_group(u'deleteme') |
|
84 | 84 | self.__delete_group(sg1.group_id) |
|
85 | 85 | |
|
86 | 86 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
87 | 87 | self.assertFalse(self.__check_path('deteteme')) |
|
88 | 88 | |
|
89 | 89 | sg1 = fixture.create_repo_group(u'deleteme', group_parent_id=self.g1.group_id) |
|
90 | 90 | self.__delete_group(sg1.group_id) |
|
91 | 91 | |
|
92 | 92 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
93 | 93 | self.assertFalse(self.__check_path('test1', 'deteteme')) |
|
94 | 94 | |
|
95 | 95 | def test_rename_single_group(self): |
|
96 | 96 | sg1 = fixture.create_repo_group(u'initial') |
|
97 | 97 | |
|
98 | 98 | new_sg1 = _update_group(sg1.group_id, u'after') |
|
99 | 99 | self.assertTrue(self.__check_path('after')) |
|
100 | 100 | self.assertEqual(RepoGroup.get_by_group_name(u'initial'), None) |
|
101 | 101 | |
|
102 | 102 | def test_update_group_parent(self): |
|
103 | 103 | |
|
104 | 104 | sg1 = fixture.create_repo_group(u'initial', group_parent_id=self.g1.group_id) |
|
105 | 105 | |
|
106 | 106 | new_sg1 = _update_group(sg1.group_id, u'after', parent_id=self.g1.group_id) |
|
107 | 107 | self.assertTrue(self.__check_path('test1', 'after')) |
|
108 | 108 | self.assertEqual(RepoGroup.get_by_group_name(u'test1/initial'), None) |
|
109 | 109 | |
|
110 | 110 | new_sg1 = _update_group(sg1.group_id, u'after', parent_id=self.g3.group_id) |
|
111 | 111 | self.assertTrue(self.__check_path('test3', 'after')) |
|
112 | 112 | self.assertEqual(RepoGroup.get_by_group_name(u'test3/initial'), None) |
|
113 | 113 | |
|
114 | 114 | new_sg1 = _update_group(sg1.group_id, u'hello') |
|
115 | 115 | self.assertTrue(self.__check_path('hello')) |
|
116 | 116 | |
|
117 | 117 | self.assertEqual(RepoGroup.get_by_group_name(u'hello'), new_sg1) |
|
118 | 118 | |
|
119 | 119 | def test_subgrouping_with_repo(self): |
|
120 | 120 | |
|
121 | 121 | g1 = fixture.create_repo_group(u'g1') |
|
122 | 122 | g2 = fixture.create_repo_group(u'g2') |
|
123 | 123 | # create new repo |
|
124 | 124 | r = fixture.create_repo(u'john') |
|
125 | 125 | |
|
126 | 126 | self.assertEqual(r.repo_name, 'john') |
|
127 | 127 | # put repo into group |
|
128 | 128 | r = _update_repo(u'john', repo_group=g1.group_id) |
|
129 | 129 | Session().commit() |
|
130 | 130 | self.assertEqual(r.repo_name, 'g1/john') |
|
131 | 131 | |
|
132 | 132 | _update_group(g1.group_id, u'g1', parent_id=g2.group_id) |
|
133 | 133 | self.assertTrue(self.__check_path('g2', 'g1')) |
|
134 | 134 | |
|
135 | 135 | # test repo |
|
136 | 136 | self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', |
|
137 | 137 | r.just_name])) |
|
138 | 138 | |
|
139 | 139 | def test_move_to_root(self): |
|
140 | 140 | g1 = fixture.create_repo_group(u't11') |
|
141 | 141 | g2 = fixture.create_repo_group(u't22', group_parent_id=g1.group_id) |
|
142 | 142 | |
|
143 | 143 | self.assertEqual(g2.full_path, 't11/t22') |
|
144 | 144 | self.assertTrue(self.__check_path('t11', 't22')) |
|
145 | 145 | |
|
146 | 146 | g2 = _update_group(g2.group_id, u'g22', parent_id=None) |
|
147 | 147 | Session().commit() |
|
148 | 148 | |
|
149 | 149 | self.assertEqual(g2.group_name, 'g22') |
|
150 | 150 | # we moved out group from t1 to '' so it's full path should be 'g2' |
|
151 | 151 | self.assertEqual(g2.full_path, 'g22') |
|
152 | 152 | self.assertFalse(self.__check_path('t11', 't22')) |
|
153 | 153 | self.assertTrue(self.__check_path('g22')) |
|
154 | 154 | |
|
155 | 155 | def test_rename_top_level_group_in_nested_setup(self): |
|
156 | 156 | g1 = fixture.create_repo_group(u'L1') |
|
157 | 157 | g2 = fixture.create_repo_group(u'L2', group_parent_id=g1.group_id) |
|
158 | 158 | g3 = fixture.create_repo_group(u'L3', group_parent_id=g2.group_id) |
|
159 | 159 | |
|
160 | 160 | r = fixture.create_repo(u'L1/L2/L3/L3_REPO', repo_group=g3.group_id) |
|
161 | 161 | |
|
162 | 162 | ##rename L1 all groups should be now changed |
|
163 | 163 | _update_group(g1.group_id, u'L1_NEW') |
|
164 | 164 | Session().commit() |
|
165 | 165 | self.assertEqual(g1.full_path, 'L1_NEW') |
|
166 | 166 | self.assertEqual(g2.full_path, 'L1_NEW/L2') |
|
167 | 167 | self.assertEqual(g3.full_path, 'L1_NEW/L2/L3') |
|
168 | 168 | self.assertEqual(r.repo_name, 'L1_NEW/L2/L3/L3_REPO') |
|
169 | 169 | |
|
170 | 170 | def test_change_parent_of_top_level_group_in_nested_setup(self): |
|
171 | 171 | g1 = fixture.create_repo_group(u'R1') |
|
172 | 172 | g2 = fixture.create_repo_group(u'R2', group_parent_id=g1.group_id) |
|
173 | 173 | g3 = fixture.create_repo_group(u'R3', group_parent_id=g2.group_id) |
|
174 | 174 | g4 = fixture.create_repo_group(u'R1_NEW') |
|
175 | 175 | |
|
176 | 176 | r = fixture.create_repo(u'R1/R2/R3/R3_REPO', repo_group=g3.group_id) |
|
177 | 177 | ##rename L1 all groups should be now changed |
|
178 | 178 | _update_group(g1.group_id, u'R1', parent_id=g4.group_id) |
|
179 | 179 | Session().commit() |
|
180 | 180 | self.assertEqual(g1.full_path, 'R1_NEW/R1') |
|
181 | 181 | self.assertEqual(g2.full_path, 'R1_NEW/R1/R2') |
|
182 | 182 | self.assertEqual(g3.full_path, 'R1_NEW/R1/R2/R3') |
|
183 | 183 | self.assertEqual(r.repo_name, 'R1_NEW/R1/R2/R3/R3_REPO') |
|
184 | 184 | |
|
185 | 185 | def test_change_parent_of_top_level_group_in_nested_setup_with_rename(self): |
|
186 | 186 | g1 = fixture.create_repo_group(u'X1') |
|
187 | 187 | g2 = fixture.create_repo_group(u'X2', group_parent_id=g1.group_id) |
|
188 | 188 | g3 = fixture.create_repo_group(u'X3', group_parent_id=g2.group_id) |
|
189 | 189 | g4 = fixture.create_repo_group(u'X1_NEW') |
|
190 | 190 | |
|
191 | 191 | r = fixture.create_repo(u'X1/X2/X3/X3_REPO', repo_group=g3.group_id) |
|
192 | 192 | |
|
193 | 193 | ##rename L1 all groups should be now changed |
|
194 | 194 | _update_group(g1.group_id, u'X1_PRIM', parent_id=g4.group_id) |
|
195 | 195 | Session().commit() |
|
196 | 196 | self.assertEqual(g1.full_path, 'X1_NEW/X1_PRIM') |
|
197 | 197 | self.assertEqual(g2.full_path, 'X1_NEW/X1_PRIM/X2') |
|
198 | 198 | self.assertEqual(g3.full_path, 'X1_NEW/X1_PRIM/X2/X3') |
|
199 | 199 | 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