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