Show More
@@ -1,170 +1,172 b'' | |||||
1 | import os |
|
1 | import os | |
2 | import unittest |
|
2 | import unittest | |
3 | from rhodecode.tests import * |
|
3 | from rhodecode.tests import * | |
4 |
|
4 | |||
5 | from rhodecode.model.repos_group import ReposGroupModel |
|
5 | from rhodecode.model.repos_group import ReposGroupModel | |
6 | from rhodecode.model.repo import RepoModel |
|
6 | from rhodecode.model.repo import RepoModel | |
7 | from rhodecode.model.db import RepoGroup, User |
|
7 | from rhodecode.model.db import RepoGroup, User | |
8 | from rhodecode.model.meta import Session |
|
8 | from rhodecode.model.meta import Session | |
9 | from sqlalchemy.exc import IntegrityError |
|
9 | from sqlalchemy.exc import IntegrityError | |
10 |
|
10 | |||
11 |
|
11 | |||
12 | def _make_group(path, desc='desc', parent_id=None, |
|
12 | def _make_group(path, desc='desc', parent_id=None, | |
13 | skip_if_exists=False): |
|
13 | skip_if_exists=False): | |
14 |
|
14 | |||
15 | gr = RepoGroup.get_by_group_name(path) |
|
15 | gr = RepoGroup.get_by_group_name(path) | |
16 | if gr and skip_if_exists: |
|
16 | if gr and skip_if_exists: | |
17 | return gr |
|
17 | return gr | |
18 |
|
18 | |||
19 | gr = ReposGroupModel().create(path, desc, parent_id) |
|
19 | gr = ReposGroupModel().create(path, desc, parent_id) | |
20 | return gr |
|
20 | return gr | |
21 |
|
21 | |||
22 |
|
22 | |||
23 | class TestReposGroups(unittest.TestCase): |
|
23 | class TestReposGroups(unittest.TestCase): | |
24 |
|
24 | |||
25 | def setUp(self): |
|
25 | def setUp(self): | |
26 | self.g1 = _make_group('test1', skip_if_exists=True) |
|
26 | self.g1 = _make_group('test1', skip_if_exists=True) | |
27 | Session().commit() |
|
27 | Session().commit() | |
28 | self.g2 = _make_group('test2', skip_if_exists=True) |
|
28 | self.g2 = _make_group('test2', skip_if_exists=True) | |
29 | Session().commit() |
|
29 | Session().commit() | |
30 | self.g3 = _make_group('test3', skip_if_exists=True) |
|
30 | self.g3 = _make_group('test3', skip_if_exists=True) | |
31 | Session().commit() |
|
31 | Session().commit() | |
32 |
|
32 | |||
33 | def tearDown(self): |
|
33 | def tearDown(self): | |
34 | print 'out' |
|
34 | print 'out' | |
35 |
|
35 | |||
36 | def __check_path(self, *path): |
|
36 | def __check_path(self, *path): | |
37 | """ |
|
37 | """ | |
38 | Checks the path for existance ! |
|
38 | Checks the path for existance ! | |
39 | """ |
|
39 | """ | |
40 | path = [TESTS_TMP_PATH] + list(path) |
|
40 | path = [TESTS_TMP_PATH] + list(path) | |
41 | path = os.path.join(*path) |
|
41 | path = os.path.join(*path) | |
42 | return os.path.isdir(path) |
|
42 | return os.path.isdir(path) | |
43 |
|
43 | |||
44 | def _check_folders(self): |
|
44 | def _check_folders(self): | |
45 | print os.listdir(TESTS_TMP_PATH) |
|
45 | print os.listdir(TESTS_TMP_PATH) | |
46 |
|
46 | |||
47 | def __delete_group(self, id_): |
|
47 | def __delete_group(self, id_): | |
48 | ReposGroupModel().delete(id_) |
|
48 | ReposGroupModel().delete(id_) | |
49 |
|
49 | |||
50 | def __update_group(self, id_, path, desc='desc', parent_id=None): |
|
50 | def __update_group(self, id_, path, desc='desc', parent_id=None): | |
51 | form_data = dict( |
|
51 | form_data = dict( | |
52 | group_name=path, |
|
52 | group_name=path, | |
53 | group_description=desc, |
|
53 | group_description=desc, | |
54 | group_parent_id=parent_id, |
|
54 | group_parent_id=parent_id, | |
55 | perms_updates=[], |
|
55 | perms_updates=[], | |
56 | perms_new=[] |
|
56 | perms_new=[], | |
|
57 | enable_locking=False | |||
57 | ) |
|
58 | ) | |
58 | gr = ReposGroupModel().update(id_, form_data) |
|
59 | gr = ReposGroupModel().update(id_, form_data) | |
59 | return gr |
|
60 | return gr | |
60 |
|
61 | |||
61 | def test_create_group(self): |
|
62 | def test_create_group(self): | |
62 | g = _make_group('newGroup') |
|
63 | g = _make_group('newGroup') | |
63 | self.assertEqual(g.full_path, 'newGroup') |
|
64 | self.assertEqual(g.full_path, 'newGroup') | |
64 |
|
65 | |||
65 | self.assertTrue(self.__check_path('newGroup')) |
|
66 | self.assertTrue(self.__check_path('newGroup')) | |
66 |
|
67 | |||
67 | def test_create_same_name_group(self): |
|
68 | def test_create_same_name_group(self): | |
68 | self.assertRaises(IntegrityError, lambda: _make_group('newGroup')) |
|
69 | self.assertRaises(IntegrityError, lambda: _make_group('newGroup')) | |
69 | Session().rollback() |
|
70 | Session().rollback() | |
70 |
|
71 | |||
71 | def test_same_subgroup(self): |
|
72 | def test_same_subgroup(self): | |
72 | sg1 = _make_group('sub1', parent_id=self.g1.group_id) |
|
73 | sg1 = _make_group('sub1', parent_id=self.g1.group_id) | |
73 | self.assertEqual(sg1.parent_group, self.g1) |
|
74 | self.assertEqual(sg1.parent_group, self.g1) | |
74 | self.assertEqual(sg1.full_path, 'test1/sub1') |
|
75 | self.assertEqual(sg1.full_path, 'test1/sub1') | |
75 | self.assertTrue(self.__check_path('test1', 'sub1')) |
|
76 | self.assertTrue(self.__check_path('test1', 'sub1')) | |
76 |
|
77 | |||
77 | ssg1 = _make_group('subsub1', parent_id=sg1.group_id) |
|
78 | ssg1 = _make_group('subsub1', parent_id=sg1.group_id) | |
78 | self.assertEqual(ssg1.parent_group, sg1) |
|
79 | self.assertEqual(ssg1.parent_group, sg1) | |
79 | self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1') |
|
80 | self.assertEqual(ssg1.full_path, 'test1/sub1/subsub1') | |
80 | self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1')) |
|
81 | self.assertTrue(self.__check_path('test1', 'sub1', 'subsub1')) | |
81 |
|
82 | |||
82 | def test_remove_group(self): |
|
83 | def test_remove_group(self): | |
83 | sg1 = _make_group('deleteme') |
|
84 | sg1 = _make_group('deleteme') | |
84 | self.__delete_group(sg1.group_id) |
|
85 | self.__delete_group(sg1.group_id) | |
85 |
|
86 | |||
86 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
87 | self.assertEqual(RepoGroup.get(sg1.group_id), None) | |
87 | self.assertFalse(self.__check_path('deteteme')) |
|
88 | self.assertFalse(self.__check_path('deteteme')) | |
88 |
|
89 | |||
89 | sg1 = _make_group('deleteme', parent_id=self.g1.group_id) |
|
90 | sg1 = _make_group('deleteme', parent_id=self.g1.group_id) | |
90 | self.__delete_group(sg1.group_id) |
|
91 | self.__delete_group(sg1.group_id) | |
91 |
|
92 | |||
92 | self.assertEqual(RepoGroup.get(sg1.group_id), None) |
|
93 | self.assertEqual(RepoGroup.get(sg1.group_id), None) | |
93 | self.assertFalse(self.__check_path('test1', 'deteteme')) |
|
94 | self.assertFalse(self.__check_path('test1', 'deteteme')) | |
94 |
|
95 | |||
95 | def test_rename_single_group(self): |
|
96 | def test_rename_single_group(self): | |
96 | sg1 = _make_group('initial') |
|
97 | sg1 = _make_group('initial') | |
97 |
|
98 | |||
98 | new_sg1 = self.__update_group(sg1.group_id, 'after') |
|
99 | new_sg1 = self.__update_group(sg1.group_id, 'after') | |
99 | self.assertTrue(self.__check_path('after')) |
|
100 | self.assertTrue(self.__check_path('after')) | |
100 | self.assertEqual(RepoGroup.get_by_group_name('initial'), None) |
|
101 | self.assertEqual(RepoGroup.get_by_group_name('initial'), None) | |
101 |
|
102 | |||
102 | def test_update_group_parent(self): |
|
103 | def test_update_group_parent(self): | |
103 |
|
104 | |||
104 | sg1 = _make_group('initial', parent_id=self.g1.group_id) |
|
105 | sg1 = _make_group('initial', parent_id=self.g1.group_id) | |
105 |
|
106 | |||
106 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id) |
|
107 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g1.group_id) | |
107 | self.assertTrue(self.__check_path('test1', 'after')) |
|
108 | self.assertTrue(self.__check_path('test1', 'after')) | |
108 | self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None) |
|
109 | self.assertEqual(RepoGroup.get_by_group_name('test1/initial'), None) | |
109 |
|
110 | |||
110 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id) |
|
111 | new_sg1 = self.__update_group(sg1.group_id, 'after', parent_id=self.g3.group_id) | |
111 | self.assertTrue(self.__check_path('test3', 'after')) |
|
112 | self.assertTrue(self.__check_path('test3', 'after')) | |
112 | self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None) |
|
113 | self.assertEqual(RepoGroup.get_by_group_name('test3/initial'), None) | |
113 |
|
114 | |||
114 | new_sg1 = self.__update_group(sg1.group_id, 'hello') |
|
115 | new_sg1 = self.__update_group(sg1.group_id, 'hello') | |
115 | self.assertTrue(self.__check_path('hello')) |
|
116 | self.assertTrue(self.__check_path('hello')) | |
116 |
|
117 | |||
117 | self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1) |
|
118 | self.assertEqual(RepoGroup.get_by_group_name('hello'), new_sg1) | |
118 |
|
119 | |||
119 | def test_subgrouping_with_repo(self): |
|
120 | def test_subgrouping_with_repo(self): | |
120 |
|
121 | |||
121 | g1 = _make_group('g1') |
|
122 | g1 = _make_group('g1') | |
122 | g2 = _make_group('g2') |
|
123 | g2 = _make_group('g2') | |
123 |
|
124 | |||
124 | # create new repo |
|
125 | # create new repo | |
125 | form_data = dict(repo_name='john', |
|
126 | form_data = dict(repo_name='john', | |
126 | repo_name_full='john', |
|
127 | repo_name_full='john', | |
127 | fork_name=None, |
|
128 | fork_name=None, | |
128 | description=None, |
|
129 | description=None, | |
129 | repo_group=None, |
|
130 | repo_group=None, | |
130 | private=False, |
|
131 | private=False, | |
131 | repo_type='hg', |
|
132 | repo_type='hg', | |
132 | clone_uri=None, |
|
133 | clone_uri=None, | |
133 |
landing_rev='tip' |
|
134 | landing_rev='tip', | |
|
135 | enable_locking=False) | |||
134 | cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) |
|
136 | cur_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) | |
135 | r = RepoModel().create(form_data, cur_user) |
|
137 | r = RepoModel().create(form_data, cur_user) | |
136 |
|
138 | |||
137 | self.assertEqual(r.repo_name, 'john') |
|
139 | self.assertEqual(r.repo_name, 'john') | |
138 |
|
140 | |||
139 | # put repo into group |
|
141 | # put repo into group | |
140 | form_data = form_data |
|
142 | form_data = form_data | |
141 | form_data['repo_group'] = g1.group_id |
|
143 | form_data['repo_group'] = g1.group_id | |
142 | form_data['perms_new'] = [] |
|
144 | form_data['perms_new'] = [] | |
143 | form_data['perms_updates'] = [] |
|
145 | form_data['perms_updates'] = [] | |
144 | RepoModel().update(r.repo_name, form_data) |
|
146 | RepoModel().update(r.repo_name, form_data) | |
145 | self.assertEqual(r.repo_name, 'g1/john') |
|
147 | self.assertEqual(r.repo_name, 'g1/john') | |
146 |
|
148 | |||
147 | self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id) |
|
149 | self.__update_group(g1.group_id, 'g1', parent_id=g2.group_id) | |
148 | self.assertTrue(self.__check_path('g2', 'g1')) |
|
150 | self.assertTrue(self.__check_path('g2', 'g1')) | |
149 |
|
151 | |||
150 | # test repo |
|
152 | # test repo | |
151 | self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', |
|
153 | self.assertEqual(r.repo_name, RepoGroup.url_sep().join(['g2', 'g1', | |
152 | r.just_name])) |
|
154 | r.just_name])) | |
153 |
|
155 | |||
154 | def test_move_to_root(self): |
|
156 | def test_move_to_root(self): | |
155 | g1 = _make_group('t11') |
|
157 | g1 = _make_group('t11') | |
156 | Session().commit() |
|
158 | Session().commit() | |
157 | g2 = _make_group('t22', parent_id=g1.group_id) |
|
159 | g2 = _make_group('t22', parent_id=g1.group_id) | |
158 | Session().commit() |
|
160 | Session().commit() | |
159 |
|
161 | |||
160 | self.assertEqual(g2.full_path, 't11/t22') |
|
162 | self.assertEqual(g2.full_path, 't11/t22') | |
161 | self.assertTrue(self.__check_path('t11', 't22')) |
|
163 | self.assertTrue(self.__check_path('t11', 't22')) | |
162 |
|
164 | |||
163 | g2 = self.__update_group(g2.group_id, 'g22', parent_id=None) |
|
165 | g2 = self.__update_group(g2.group_id, 'g22', parent_id=None) | |
164 | Session().commit() |
|
166 | Session().commit() | |
165 |
|
167 | |||
166 | self.assertEqual(g2.group_name, 'g22') |
|
168 | self.assertEqual(g2.group_name, 'g22') | |
167 | # we moved out group from t1 to '' so it's full path should be 'g2' |
|
169 | # we moved out group from t1 to '' so it's full path should be 'g2' | |
168 | self.assertEqual(g2.full_path, 'g22') |
|
170 | self.assertEqual(g2.full_path, 'g22') | |
169 | self.assertFalse(self.__check_path('t11', 't22')) |
|
171 | self.assertFalse(self.__check_path('t11', 't22')) | |
170 | self.assertTrue(self.__check_path('g22')) |
|
172 | self.assertTrue(self.__check_path('g22')) |
General Comments 0
You need to be logged in to leave comments.
Login now