Mercurial > kallithea
annotate kallithea/tests/fixture.py @ 5768:5cb780fd494d
tests: invalidate cache for new repositories - make tests more stable if garbage has been left behind in the db
It could be argued that this should be done elsewhere in the app ...
author | Mads Kiilerich <madski@unity3d.com> |
---|---|
date | Mon, 14 Mar 2016 16:17:46 +0100 |
parents | 83dbf427f1dc |
children | 037efd94e955 |
rev | line source |
---|---|
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
1 # -*- coding: utf-8 -*- |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
2 # This program is free software: you can redistribute it and/or modify |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
3 # it under the terms of the GNU General Public License as published by |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
4 # the Free Software Foundation, either version 3 of the License, or |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
5 # (at your option) any later version. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
6 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
7 # This program is distributed in the hope that it will be useful, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
10 # GNU General Public License for more details. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
11 # |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
12 # You should have received a copy of the GNU General Public License |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
13 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
14 |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
15 """ |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
16 Helpers for fixture generation |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
17 """ |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
18 import os |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
19 import time |
4186
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
20 from kallithea.tests import * |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
21 from kallithea.model.db import Repository, User, RepoGroup, UserGroup |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
22 from kallithea.model.meta import Session |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
23 from kallithea.model.repo import RepoModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
24 from kallithea.model.user import UserModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
25 from kallithea.model.repo_group import RepoGroupModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
26 from kallithea.model.user_group import UserGroupModel |
7e5f8c12a3fc
First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4183
diff
changeset
|
27 from kallithea.model.gist import GistModel |
4842
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
28 from kallithea.model.scm import ScmModel |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
29 from kallithea.lib.vcs.backends.base import EmptyChangeset |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
30 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
31 dn = os.path.dirname |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
32 FIXTURES = os.path.join(dn(dn(os.path.abspath(__file__))), 'tests', 'fixtures') |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
33 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
34 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
35 def error_function(*args, **kwargs): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
36 raise Exception('Total Crash !') |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
37 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
38 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
39 class Fixture(object): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
40 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
41 def __init__(self): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
42 pass |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
43 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
44 def anon_access(self, status): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
45 """ |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
46 Context manager for controlling anonymous access. |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
47 Anon access will be set and committed, but restored again when exiting the block. |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
48 |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
49 Usage: |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
50 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
51 fixture = Fixture() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
52 with fixture.anon_access(False): |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
53 stuff |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
54 """ |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
55 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
56 class context(object): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
57 def __enter__(self): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
58 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
59 self._before = anon.active |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
60 anon.active = status |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
61 Session().add(anon) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
62 Session().commit() |
4849
5e94c0f9720c
tests: decrease sql_cache_short beaker config to 1 s to match hack in fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4842
diff
changeset
|
63 time.sleep(1.5) # hack: wait for beaker sql_cache_short to expire |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
64 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
65 def __exit__(self, exc_type, exc_val, exc_tb): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
66 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
67 anon.active = self._before |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
68 Session().add(anon) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
69 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
70 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
71 return context() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
72 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
73 def _get_repo_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
74 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
75 repo_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
76 repo_type='hg', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
77 clone_uri='', |
5281
82faecc21324
repogroups: use group IDs as integers instead of unicoding them
Mads Kiilerich <madski@unity3d.com>
parents:
4880
diff
changeset
|
78 repo_group=u'-1', |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
79 repo_description=u'DESC', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
80 repo_private=False, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
81 repo_landing_rev='rev:tip', |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
82 repo_copy_permissions=False, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
83 repo_state=Repository.STATE_CREATED, |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
84 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
85 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
86 if 'repo_name_full' not in custom: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
87 defs.update({'repo_name_full': defs['repo_name']}) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
88 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
89 # fix the repo name if passed as repo_name_full |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
90 if defs['repo_name']: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
91 defs['repo_name'] = defs['repo_name'].split('/')[-1] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
92 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
93 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
94 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
95 def _get_group_create_params(self, **custom): |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
96 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
97 group_name=None, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
98 group_description=u'DESC', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
99 group_parent_id=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
100 perms_updates=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
101 perms_new=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
102 enable_locking=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
103 recursive=False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
104 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
105 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
106 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
107 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
108 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
109 def _get_user_create_params(self, name, **custom): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
110 defs = dict( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
111 username=name, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
112 password='qweqwe', |
4183
da3c57422ee6
Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
113 email='%s+test@example.com' % name, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
114 firstname=u'TestUser', |
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
115 lastname=u'Test', |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
116 active=True, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
117 admin=False, |
4209
de26de99ac5b
Rename auth_rhodecode to auth_internal
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
118 extern_type='internal', |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
119 extern_name=None |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
120 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
121 defs.update(custom) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
122 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
123 return defs |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
124 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
125 def _get_user_group_create_params(self, name, **custom): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
126 defs = dict( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
127 users_group_name=name, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
128 user_group_description=u'DESC', |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
129 users_group_active=True, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
130 user_group_data={}, |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
131 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
132 defs.update(custom) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
133 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
134 return defs |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
135 |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
136 def create_repo(self, name, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
137 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
138 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
139 r = Repository.get_by_repo_name(name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
140 if r: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
141 return r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
142 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
143 if isinstance(kwargs.get('repo_group'), RepoGroup): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
144 kwargs['repo_group'] = kwargs['repo_group'].group_id |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
145 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
146 form_data = self._get_repo_create_params(repo_name=name, **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
147 cur_user = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
148 RepoModel().create(form_data, cur_user) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
149 Session().commit() |
5768
5cb780fd494d
tests: invalidate cache for new repositories - make tests more stable if garbage has been left behind in the db
Mads Kiilerich <madski@unity3d.com>
parents:
5745
diff
changeset
|
150 ScmModel().mark_for_invalidation(name) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
151 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
152 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
153 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
154 repo_to_fork = Repository.get_by_repo_name(repo_to_fork) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
155 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
156 form_data = self._get_repo_create_params(repo_name=fork_name, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
157 fork_parent_id=repo_to_fork, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
158 repo_type=repo_to_fork.repo_type, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
159 **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
160 form_data['update_after_clone'] = False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
161 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
162 #TODO: fix it !! |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
163 form_data['description'] = form_data['repo_description'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
164 form_data['private'] = form_data['repo_private'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
165 form_data['landing_rev'] = form_data['repo_landing_rev'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
166 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
167 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
168 RepoModel().create_fork(form_data, cur_user=owner) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
169 Session().commit() |
5768
5cb780fd494d
tests: invalidate cache for new repositories - make tests more stable if garbage has been left behind in the db
Mads Kiilerich <madski@unity3d.com>
parents:
5745
diff
changeset
|
170 ScmModel().mark_for_invalidation(fork_name) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
171 r = Repository.get_by_repo_name(fork_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
172 assert r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
173 return r |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
174 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
175 def destroy_repo(self, repo_name, **kwargs): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
176 RepoModel().delete(repo_name, **kwargs) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
177 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
178 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
179 def create_repo_group(self, name, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
180 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
181 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
182 gr = RepoGroup.get_by_group_name(group_name=name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
183 if gr: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
184 return gr |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
185 form_data = self._get_group_create_params(group_name=name, **kwargs) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
186 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
187 gr = RepoGroupModel().create( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
188 group_name=form_data['group_name'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
189 group_description=form_data['group_name'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
190 owner=owner, parent=form_data['group_parent_id']) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 Session().commit() |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
192 gr = RepoGroup.get_by_group_name(gr.group_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
193 return gr |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
194 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
195 def destroy_repo_group(self, repogroupid): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
196 RepoGroupModel().delete(repogroupid) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
197 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
198 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
199 def create_user(self, name, **kwargs): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
200 if 'skip_if_exists' in kwargs: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
201 del kwargs['skip_if_exists'] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
202 user = User.get_by_username(name) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
203 if user: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
204 return user |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
205 form_data = self._get_user_create_params(name, **kwargs) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
206 user = UserModel().create(form_data) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
207 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
208 user = User.get_by_username(user.username) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
209 return user |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
210 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
211 def destroy_user(self, userid): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
212 UserModel().delete(userid) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
213 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
214 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
215 def create_user_group(self, name, **kwargs): |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
216 if 'skip_if_exists' in kwargs: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
217 del kwargs['skip_if_exists'] |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
218 gr = UserGroup.get_by_group_name(group_name=name) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
219 if gr: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
220 return gr |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
221 form_data = self._get_user_group_create_params(name, **kwargs) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
222 owner = kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
223 user_group = UserGroupModel().create( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
224 name=form_data['users_group_name'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
225 description=form_data['user_group_description'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
226 owner=owner, active=form_data['users_group_active'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
227 group_data=form_data['user_group_data']) |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
228 Session().commit() |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
229 user_group = UserGroup.get_by_group_name(user_group.users_group_name) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
230 return user_group |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
231 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
232 def destroy_user_group(self, usergroupid): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
233 UserGroupModel().delete(user_group=usergroupid, force=True) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
234 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
235 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
236 def create_gist(self, **kwargs): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
237 form_data = { |
4731
c154dc461bd5
tests: fix some test sqlalchemy unicode warnings
Mads Kiilerich <madski@unity3d.com>
parents:
4209
diff
changeset
|
238 'description': u'new-gist', |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
239 'owner': TEST_USER_ADMIN_LOGIN, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
240 'gist_type': GistModel.cls.GIST_PUBLIC, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
241 'lifetime': -1, |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
242 'gist_mapping': {'filename1.txt':{'content':'hello world'},} |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
243 } |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
244 form_data.update(kwargs) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
245 gist = GistModel().create( |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
246 description=form_data['description'],owner=form_data['owner'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
247 gist_mapping=form_data['gist_mapping'], gist_type=form_data['gist_type'], |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
248 lifetime=form_data['lifetime'] |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
249 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
250 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
251 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
252 return gist |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
253 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
254 def destroy_gists(self, gistid=None): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
255 for g in GistModel.cls.get_all(): |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
256 if gistid: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
257 if gistid == g.gist_access_id: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
258 GistModel().delete(g) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
259 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
260 GistModel().delete(g) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
261 Session().commit() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
262 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
263 def load_resource(self, resource_name, strip=True): |
5745
83dbf427f1dc
tests: load fixture in binary mode - otherwise \r would be filtered on Windows
domruf <dominikruf@gmail.com>
parents:
5631
diff
changeset
|
264 with open(os.path.join(FIXTURES, resource_name), 'rb') as f: |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
265 source = f.read() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
266 if strip: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
267 source = source.strip() |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
268 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
269 return source |
4842
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
270 |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
271 def commit_change(self, repo, filename, content, message, vcs_type, parent=None, newfile=False): |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
272 repo = Repository.get_by_repo_name(repo) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
273 _cs = parent |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
274 if not parent: |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
275 _cs = EmptyChangeset(alias=vcs_type) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
276 |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
277 if newfile: |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
278 nodes = { |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
279 filename: { |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
280 'content': content |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
281 } |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
282 } |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
283 cs = ScmModel().create_nodes( |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
284 user=TEST_USER_ADMIN_LOGIN, repo=repo, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
285 message=message, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
286 nodes=nodes, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
287 parent_cs=_cs, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
288 author=TEST_USER_ADMIN_LOGIN, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
289 ) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
290 else: |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
291 cs = ScmModel().commit_change( |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
292 repo=repo.scm_instance, repo_name=repo.repo_name, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
293 cs=parent, user=TEST_USER_ADMIN_LOGIN, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
294 author=TEST_USER_ADMIN_LOGIN, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
295 message=message, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
296 content=content, |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
297 f_path=filename |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
298 ) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
299 return cs |