Mercurial > kallithea
comparison rhodecode/tests/functional/test_forks.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3ยง14 and other relevant sections of GPLv3.
author | Bradley M. Kuhn <bkuhn@sfconservancy.org> |
---|---|
date | Wed, 02 Jul 2014 19:03:13 -0400 |
parents | 63e49418a4cc |
children | da3c57422ee6 |
comparison
equal
deleted
inserted
replaced
4115:8b7294a804a0 | 4116:ffd45b185016 |
---|---|
1 # -*- coding: utf-8 -*- | |
1 from rhodecode.tests import * | 2 from rhodecode.tests import * |
3 from rhodecode.tests.fixture import Fixture | |
2 | 4 |
3 from rhodecode.model.db import Repository | 5 from rhodecode.model.db import Repository |
4 from rhodecode.model.repo import RepoModel | 6 from rhodecode.model.repo import RepoModel |
5 from rhodecode.model.user import UserModel | 7 from rhodecode.model.user import UserModel |
6 from rhodecode.model.meta import Session | 8 from rhodecode.model.meta import Session |
7 | 9 |
8 | 10 fixture = Fixture() |
9 class TestForksController(TestController): | 11 |
12 from rhodecode.tests import * | |
13 | |
14 | |
15 class _BaseTest(TestController): | |
16 """ | |
17 Write all tests here | |
18 """ | |
19 REPO = None | |
20 REPO_TYPE = None | |
21 NEW_REPO = None | |
22 REPO_FORK = None | |
23 | |
24 @classmethod | |
25 def setup_class(cls): | |
26 pass | |
27 | |
28 @classmethod | |
29 def teardown_class(cls): | |
30 pass | |
10 | 31 |
11 def setUp(self): | 32 def setUp(self): |
12 self.username = u'forkuser' | 33 self.username = u'forkuser' |
13 self.password = u'qweqwe' | 34 self.password = u'qweqwe' |
14 self.u1 = UserModel().create_or_update( | 35 self.u1 = fixture.create_user(self.username, password=self.password, |
15 username=self.username, password=self.password, | 36 email=u'fork_king@rhodecode.org') |
16 email=u'fork_king@rhodecode.org', firstname=u'u1', lastname=u'u1' | |
17 ) | |
18 Session().commit() | 37 Session().commit() |
19 | 38 |
20 def tearDown(self): | 39 def tearDown(self): |
21 Session().delete(self.u1) | 40 Session().delete(self.u1) |
22 Session().commit() | 41 Session().commit() |
23 | 42 |
24 def test_index(self): | 43 def test_index(self): |
25 self.log_user() | 44 self.log_user() |
26 repo_name = HG_REPO | 45 repo_name = self.REPO |
27 response = self.app.get(url(controller='forks', action='forks', | 46 response = self.app.get(url(controller='forks', action='forks', |
28 repo_name=repo_name)) | 47 repo_name=repo_name)) |
29 | 48 |
30 response.mustcontain("""There are no forks yet""") | 49 response.mustcontain("""There are no forks yet""") |
31 | 50 |
37 user_model.grant_perm(usr, 'hg.fork.none') | 56 user_model.grant_perm(usr, 'hg.fork.none') |
38 u = UserModel().get(usr) | 57 u = UserModel().get(usr) |
39 u.inherit_default_permissions = False | 58 u.inherit_default_permissions = False |
40 Session().commit() | 59 Session().commit() |
41 # try create a fork | 60 # try create a fork |
42 repo_name = HG_REPO | 61 repo_name = self.REPO |
43 self.app.post(url(controller='forks', action='fork_create', | 62 self.app.post(url(controller='forks', action='fork_create', |
44 repo_name=repo_name), {}, status=403) | 63 repo_name=repo_name), {}, status=403) |
45 | 64 |
46 def test_index_with_fork_hg(self): | 65 def test_index_with_fork(self): |
47 self.log_user() | 66 self.log_user() |
48 | 67 |
49 # create a fork | 68 # create a fork |
50 fork_name = HG_FORK | 69 fork_name = self.REPO_FORK |
51 description = 'fork of vcs test' | 70 description = 'fork of vcs test' |
52 repo_name = HG_REPO | 71 repo_name = self.REPO |
53 org_repo = Repository.get_by_repo_name(repo_name) | 72 org_repo = Repository.get_by_repo_name(repo_name) |
54 response = self.app.post(url(controller='forks', | 73 creation_args = { |
55 action='fork_create', | 74 'repo_name': fork_name, |
56 repo_name=repo_name), | 75 'repo_group': '', |
57 {'repo_name': fork_name, | 76 'fork_parent_id': org_repo.repo_id, |
58 'repo_group': '', | 77 'repo_type': self.REPO_TYPE, |
59 'fork_parent_id': org_repo.repo_id, | 78 'description': description, |
60 'repo_type': 'hg', | 79 'private': 'False', |
61 'description': description, | 80 'landing_rev': 'rev:tip'} |
62 'private': 'False', | 81 |
63 'landing_rev': 'tip'}) | 82 self.app.post(url(controller='forks', action='fork_create', |
83 repo_name=repo_name), creation_args) | |
64 | 84 |
65 response = self.app.get(url(controller='forks', action='forks', | 85 response = self.app.get(url(controller='forks', action='forks', |
66 repo_name=repo_name)) | 86 repo_name=repo_name)) |
67 | 87 |
68 response.mustcontain( | 88 response.mustcontain( |
69 """<a href="/%s">%s</a>""" % (fork_name, fork_name) | 89 """<a href="/%s">%s</a>""" % (fork_name, fork_name) |
70 ) | 90 ) |
71 | 91 |
72 #remove this fork | 92 # remove this fork |
73 response = self.app.delete(url('repo', repo_name=fork_name)) | 93 response = self.app.delete(url('repo', repo_name=fork_name)) |
74 | 94 |
75 def test_index_with_fork_git(self): | 95 def test_fork_create_into_group(self): |
76 self.log_user() | 96 self.log_user() |
77 | 97 group = fixture.create_repo_group('vc') |
78 # create a fork | 98 group_id = group.group_id |
79 fork_name = GIT_FORK | 99 fork_name = self.REPO_FORK |
100 fork_name_full = 'vc/%s' % fork_name | |
80 description = 'fork of vcs test' | 101 description = 'fork of vcs test' |
81 repo_name = GIT_REPO | 102 repo_name = self.REPO |
82 org_repo = Repository.get_by_repo_name(repo_name) | 103 org_repo = Repository.get_by_repo_name(repo_name) |
83 response = self.app.post(url(controller='forks', | 104 creation_args = { |
84 action='fork_create', | 105 'repo_name': fork_name, |
85 repo_name=repo_name), | 106 'repo_group': group_id, |
86 {'repo_name': fork_name, | 107 'fork_parent_id': org_repo.repo_id, |
87 'repo_group': '', | 108 'repo_type': self.REPO_TYPE, |
88 'fork_parent_id': org_repo.repo_id, | 109 'description': description, |
89 'repo_type': 'git', | 110 'private': 'False', |
90 'description': description, | 111 'landing_rev': 'rev:tip'} |
91 'private': 'False', | 112 self.app.post(url(controller='forks', action='fork_create', |
92 'landing_rev': 'tip'}) | 113 repo_name=repo_name), creation_args) |
93 | 114 repo = Repository.get_by_repo_name(fork_name_full) |
94 response = self.app.get(url(controller='forks', action='forks', | 115 assert repo.fork.repo_name == self.REPO |
95 repo_name=repo_name)) | 116 |
96 | 117 ## run the check page that triggers the flash message |
97 response.mustcontain( | 118 response = self.app.get(url('repo_check_home', repo_name=fork_name_full)) |
98 """<a href="/%s">%s</a>""" % (fork_name, fork_name) | 119 #test if we have a message that fork is ok |
99 ) | 120 self.checkSessionFlash(response, |
100 | 121 'Forked repository %s as <a href="/%s">%s</a>' |
101 #remove this fork | 122 % (repo_name, fork_name_full, fork_name_full)) |
102 response = self.app.delete(url('repo', repo_name=fork_name)) | 123 |
124 #test if the fork was created in the database | |
125 fork_repo = Session().query(Repository)\ | |
126 .filter(Repository.repo_name == fork_name_full).one() | |
127 | |
128 self.assertEqual(fork_repo.repo_name, fork_name_full) | |
129 self.assertEqual(fork_repo.fork.repo_name, repo_name) | |
130 | |
131 # test if the repository is visible in the list ? | |
132 response = self.app.get(url('summary_home', repo_name=fork_name_full)) | |
133 response.mustcontain(fork_name_full) | |
134 response.mustcontain(self.REPO_TYPE) | |
135 response.mustcontain('Fork of "<a href="/%s">%s</a>"' % (repo_name, repo_name)) | |
136 | |
137 fixture.destroy_repo(fork_name_full) | |
138 fixture.destroy_repo_group(group_id) | |
103 | 139 |
104 def test_z_fork_create(self): | 140 def test_z_fork_create(self): |
105 self.log_user() | 141 self.log_user() |
106 fork_name = HG_FORK | 142 fork_name = self.REPO_FORK |
107 description = 'fork of vcs test' | 143 description = 'fork of vcs test' |
108 repo_name = HG_REPO | 144 repo_name = self.REPO |
109 org_repo = Repository.get_by_repo_name(repo_name) | 145 org_repo = Repository.get_by_repo_name(repo_name) |
110 response = self.app.post(url(controller='forks', action='fork_create', | 146 creation_args = { |
111 repo_name=repo_name), | 147 'repo_name': fork_name, |
112 {'repo_name': fork_name, | 148 'repo_group': '', |
113 'repo_group':'', | 149 'fork_parent_id': org_repo.repo_id, |
114 'fork_parent_id':org_repo.repo_id, | 150 'repo_type': self.REPO_TYPE, |
115 'repo_type':'hg', | 151 'description': description, |
116 'description':description, | 152 'private': 'False', |
117 'private':'False', | 153 'landing_rev': 'rev:tip'} |
118 'landing_rev': 'tip'}) | 154 self.app.post(url(controller='forks', action='fork_create', |
119 | 155 repo_name=repo_name), creation_args) |
156 repo = Repository.get_by_repo_name(self.REPO_FORK) | |
157 assert repo.fork.repo_name == self.REPO | |
158 | |
159 ## run the check page that triggers the flash message | |
160 response = self.app.get(url('repo_check_home', repo_name=fork_name)) | |
120 #test if we have a message that fork is ok | 161 #test if we have a message that fork is ok |
121 self.checkSessionFlash(response, | 162 self.checkSessionFlash(response, |
122 'Forked repository %s as <a href="/%s">%s</a>' | 163 'Forked repository %s as <a href="/%s">%s</a>' |
123 % (repo_name, fork_name, fork_name)) | 164 % (repo_name, fork_name, fork_name)) |
124 | 165 |
127 .filter(Repository.repo_name == fork_name).one() | 168 .filter(Repository.repo_name == fork_name).one() |
128 | 169 |
129 self.assertEqual(fork_repo.repo_name, fork_name) | 170 self.assertEqual(fork_repo.repo_name, fork_name) |
130 self.assertEqual(fork_repo.fork.repo_name, repo_name) | 171 self.assertEqual(fork_repo.fork.repo_name, repo_name) |
131 | 172 |
132 #test if fork is visible in the list ? | 173 # test if the repository is visible in the list ? |
133 response = response.follow() | 174 response = self.app.get(url('summary_home', repo_name=fork_name)) |
134 | 175 response.mustcontain(fork_name) |
135 response = self.app.get(url(controller='summary', action='index', | 176 response.mustcontain(self.REPO_TYPE) |
136 repo_name=fork_name)) | 177 response.mustcontain('Fork of "<a href="/%s">%s</a>"' % (repo_name, repo_name)) |
137 | |
138 response.mustcontain('Fork of %s' % repo_name) | |
139 | 178 |
140 def test_zz_fork_permission_page(self): | 179 def test_zz_fork_permission_page(self): |
141 usr = self.log_user(self.username, self.password)['user_id'] | 180 usr = self.log_user(self.username, self.password)['user_id'] |
142 repo_name = HG_REPO | 181 repo_name = self.REPO |
143 | 182 |
144 forks = Session().query(Repository)\ | 183 forks = Repository.query()\ |
145 .filter(Repository.fork_id != None)\ | 184 .filter(Repository.repo_type == self.REPO_TYPE)\ |
146 .all() | 185 .filter(Repository.fork_id != None).all() |
147 self.assertEqual(1, len(forks)) | 186 self.assertEqual(1, len(forks)) |
148 | 187 |
149 # set read permissions for this | 188 # set read permissions for this |
150 RepoModel().grant_user_permission(repo=forks[0], | 189 RepoModel().grant_user_permission(repo=forks[0], |
151 user=usr, | 190 user=usr, |
157 | 196 |
158 response.mustcontain('<div style="padding:5px 3px 3px 42px;">fork of vcs test</div>') | 197 response.mustcontain('<div style="padding:5px 3px 3px 42px;">fork of vcs test</div>') |
159 | 198 |
160 def test_zzz_fork_permission_page(self): | 199 def test_zzz_fork_permission_page(self): |
161 usr = self.log_user(self.username, self.password)['user_id'] | 200 usr = self.log_user(self.username, self.password)['user_id'] |
162 repo_name = HG_REPO | 201 repo_name = self.REPO |
163 | 202 |
164 forks = Session().query(Repository)\ | 203 forks = Repository.query()\ |
165 .filter(Repository.fork_id != None)\ | 204 .filter(Repository.repo_type == self.REPO_TYPE)\ |
166 .all() | 205 .filter(Repository.fork_id != None).all() |
167 self.assertEqual(1, len(forks)) | 206 self.assertEqual(1, len(forks)) |
168 | 207 |
169 # set none | 208 # set none |
170 RepoModel().grant_user_permission(repo=forks[0], | 209 RepoModel().grant_user_permission(repo=forks[0], |
171 user=usr, perm='repository.none') | 210 user=usr, perm='repository.none') |
172 Session().commit() | 211 Session().commit() |
173 # fork shouldn't be there | 212 # fork shouldn't be there |
174 response = self.app.get(url(controller='forks', action='forks', | 213 response = self.app.get(url(controller='forks', action='forks', |
175 repo_name=repo_name)) | 214 repo_name=repo_name)) |
176 response.mustcontain('There are no forks yet') | 215 response.mustcontain('There are no forks yet') |
216 | |
217 | |
218 class TestGIT(_BaseTest): | |
219 REPO = GIT_REPO | |
220 NEW_REPO = NEW_GIT_REPO | |
221 REPO_TYPE = 'git' | |
222 REPO_FORK = GIT_FORK | |
223 | |
224 | |
225 class TestHG(_BaseTest): | |
226 REPO = HG_REPO | |
227 NEW_REPO = NEW_HG_REPO | |
228 REPO_TYPE = 'hg' | |
229 REPO_FORK = HG_FORK |