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