Mercurial > kallithea
annotate kallithea/tests/fixture.py @ 6652:b60fb9461b18
Add JSON-RPC API for reading changeset status
Allows reading a changeset status as json. This is useful for e.g. reporting,
extracting review status for all changesets between two releases.
author | Eivind Tagseth <eivindt@gmail.com> |
---|---|
date | Mon, 13 Mar 2017 15:34:53 +0100 |
parents | 5b3568c99cc3 |
children | 6452215a54ee |
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 """ |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
18 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
19 import logging |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
20 import os |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
21 import shutil |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
22 import tarfile |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
23 from os.path import dirname |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
24 |
6652
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
25 from kallithea.model.db import Repository, User, RepoGroup, UserGroup, Gist, ChangesetStatus |
4186
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.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
|
27 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
|
28 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
|
29 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
|
30 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
|
31 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
|
32 from kallithea.model.scm import ScmModel |
6652
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
33 from kallithea.model.comment import ChangesetCommentsModel |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
34 from kallithea.model.changeset_status import ChangesetStatusModel |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
35 from kallithea.lib.db_manage import DbManage |
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
|
36 from kallithea.lib.vcs.backends.base import EmptyChangeset |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
37 from kallithea.tests.base import invalidate_all_caches, GIT_REPO, HG_REPO, TESTS_TMP_PATH, TEST_USER_ADMIN_LOGIN |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
38 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
39 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
40 log = logging.getLogger(__name__) |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
41 |
5998
037efd94e955
cleanup: get rid of dn as shortcut for os.path.dirname
domruf <dominikruf@gmail.com>
parents:
5768
diff
changeset
|
42 FIXTURES = os.path.join(dirname(dirname(os.path.abspath(__file__))), 'tests', 'fixtures') |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
43 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
44 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
45 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
|
46 raise Exception('Total Crash !') |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
47 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
48 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
49 class Fixture(object): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
50 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
51 def __init__(self): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
52 pass |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
53 |
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 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
|
55 """ |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
56 Context manager for controlling anonymous access. |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
57 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
|
58 |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
59 Usage: |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
60 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
61 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
|
62 with fixture.anon_access(False): |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
63 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
|
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 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
66 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
|
67 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
|
68 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
69 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
|
70 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
|
71 Session().commit() |
6140
ee88c8c07111
tests: remove sleep hack to expire sql_cache_short
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents:
6118
diff
changeset
|
72 invalidate_all_caches() |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
73 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
74 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
|
75 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
76 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
|
77 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
|
78 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
79 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
|
80 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
81 def _get_repo_create_params(self, **custom): |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
82 """Return form values to be validated through RepoForm""" |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
83 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
84 repo_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
85 repo_type='hg', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
86 clone_uri='', |
5281
82faecc21324
repogroups: use group IDs as integers instead of unicoding them
Mads Kiilerich <madski@unity3d.com>
parents:
4880
diff
changeset
|
87 repo_group=u'-1', |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
88 repo_description=u'DESC', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
89 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
|
90 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
|
91 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
|
92 repo_state=Repository.STATE_CREATED, |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
93 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
94 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
95 if 'repo_name_full' not in custom: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
96 defs.update({'repo_name_full': defs['repo_name']}) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
97 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
98 # 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
|
99 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
|
100 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
|
101 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
102 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
103 |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
104 def _get_repo_group_create_params(self, **custom): |
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
105 """Return form values to be validated through RepoGroupForm""" |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
106 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
107 group_name=None, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
108 group_description=u'DESC', |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
109 parent_group_id=u'-1', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
110 perms_updates=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
111 perms_new=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
112 enable_locking=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
113 recursive=False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
114 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
115 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
116 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
117 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
118 |
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 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
|
120 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
|
121 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
|
122 password='qweqwe', |
4183
da3c57422ee6
Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
123 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
|
124 firstname=u'TestUser', |
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
125 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
|
126 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
|
127 admin=False, |
4209
de26de99ac5b
Rename auth_rhodecode to auth_internal
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
128 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
|
129 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
|
130 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
131 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
|
132 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
133 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
|
134 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
135 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
|
136 defs = dict( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
137 users_group_name=name, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
138 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
|
139 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
|
140 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
|
141 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
142 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
|
143 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
144 return defs |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
145 |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
146 def create_repo(self, name, repo_group=None, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
147 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
148 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
149 r = Repository.get_by_repo_name(name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
150 if r: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
151 return r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
152 |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
153 if isinstance(repo_group, RepoGroup): |
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
154 repo_group = repo_group.group_id |
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=name, **kwargs) |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
157 form_data['repo_group'] = repo_group # patch form dict so it can be used directly by model |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
158 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
|
159 RepoModel().create(form_data, cur_user) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
160 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
|
161 ScmModel().mark_for_invalidation(name) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
162 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
163 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
164 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
165 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
|
166 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
167 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
|
168 fork_parent_id=repo_to_fork, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
169 repo_type=repo_to_fork.repo_type, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
170 **kwargs) |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
171 # patch form dict so it can be used directly by model |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
172 form_data['description'] = form_data['repo_description'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
173 form_data['private'] = form_data['repo_private'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
174 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
|
175 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
176 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
|
177 RepoModel().create_fork(form_data, cur_user=owner) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
178 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
|
179 ScmModel().mark_for_invalidation(fork_name) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
180 r = Repository.get_by_repo_name(fork_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
181 assert r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
182 return r |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
183 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
184 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
|
185 RepoModel().delete(repo_name, **kwargs) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
186 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
187 |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
188 def create_repo_group(self, name, parent_group_id=None, **kwargs): |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
189 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
190 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
191 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
|
192 if gr: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
193 return gr |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
194 form_data = self._get_repo_group_create_params(group_name=name, **kwargs) |
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 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
|
196 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
|
197 group_description=form_data['group_name'], |
6617
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
198 parent=parent_group_id, |
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
199 owner=kwargs.get('cur_user', TEST_USER_ADMIN_LOGIN), |
0bae66824ac5
tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents:
6471
diff
changeset
|
200 ) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
201 Session().commit() |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
202 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
|
203 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
|
204 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
205 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
|
206 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
|
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 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
209 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
|
210 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
|
211 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
|
212 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
|
213 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
|
214 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
|
215 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
|
216 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
|
217 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
|
218 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
|
219 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
|
220 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
221 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
|
222 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
|
223 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
|
224 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
225 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
|
226 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
|
227 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
|
228 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
|
229 if gr: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
230 return gr |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
231 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
|
232 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
|
233 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
|
234 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
|
235 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
|
236 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
|
237 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
|
238 Session().commit() |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
239 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
|
240 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
|
241 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
246 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
|
247 form_data = { |
4731
c154dc461bd5
tests: fix some test sqlalchemy unicode warnings
Mads Kiilerich <madski@unity3d.com>
parents:
4209
diff
changeset
|
248 '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
|
249 'owner': TEST_USER_ADMIN_LOGIN, |
6118
3d1fcf67f299
model: drop BaseModel.cls
Søren Løvborg <sorenl@unity3d.com>
parents:
6117
diff
changeset
|
250 'gist_type': Gist.GIST_PUBLIC, |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
251 '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
|
252 '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
|
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 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
|
255 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
|
256 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
|
257 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
|
258 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
|
259 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
260 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
|
261 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
262 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
|
263 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
264 def destroy_gists(self, gistid=None): |
6220
7bffccee3a49
db: inline calls to get_all
Søren Løvborg <sorenl@unity3d.com>
parents:
6217
diff
changeset
|
265 for g in Gist.query(): |
4116
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 gistid: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
267 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
|
268 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
|
269 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
270 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
|
271 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
|
272 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
273 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
|
274 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
|
275 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
|
276 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
|
277 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
|
278 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
279 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
|
280 |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
281 def commit_change(self, repo, filename, content, message, vcs_type, |
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
282 parent=None, newfile=False, author=None): |
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
|
283 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
|
284 _cs = parent |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
285 if parent is None: |
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
|
286 _cs = EmptyChangeset(alias=vcs_type) |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
287 if author is None: |
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
288 author = TEST_USER_ADMIN_LOGIN |
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
|
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 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
|
291 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
|
292 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
|
293 '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
|
294 } |
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 } |
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 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
|
297 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
|
298 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
|
299 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
|
300 parent_cs=_cs, |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
301 author=author, |
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
|
302 ) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
303 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
|
304 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
|
305 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
|
306 cs=parent, user=TEST_USER_ADMIN_LOGIN, |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
307 author=author, |
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
|
308 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
|
309 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
|
310 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
|
311 ) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
312 return cs |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
313 |
6652
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
314 def review_changeset(self, repo, revision, status, author=TEST_USER_ADMIN_LOGIN): |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
315 comment = ChangesetCommentsModel().create(u"review comment", repo, author, revision=revision, send_email=False) |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
316 csm = ChangesetStatusModel().set_status(repo, ChangesetStatus.STATUS_APPROVED, author, comment, revision=revision) |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
317 Session().commit() |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
318 return csm |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
319 |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
320 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
321 #============================================================================== |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
322 # Global test environment setup |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
323 #============================================================================== |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
324 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
325 def create_test_env(repos_test_path, config): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
326 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
327 Makes a fresh database and |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
328 install test repository into tmp dir |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
329 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
330 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
331 # PART ONE create db |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
332 dbconf = config['sqlalchemy.url'] |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
333 log.debug('making test db %s', dbconf) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
334 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
335 # create test dir if it doesn't exist |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
336 if not os.path.isdir(repos_test_path): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
337 log.debug('Creating testdir %s', repos_test_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
338 os.makedirs(repos_test_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
339 |
6623
5b3568c99cc3
sqlalchemy: remove echo setting from .ini files and create_engine
domruf <dominikruf@gmail.com>
parents:
6621
diff
changeset
|
340 dbmanage = DbManage(dbconf=dbconf, root=config['here'], |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
341 tests=True) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
342 dbmanage.create_tables(override=True) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
343 # for tests dynamically set new root paths based on generated content |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
344 dbmanage.create_settings(dbmanage.config_prompt(repos_test_path)) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
345 dbmanage.create_default_user() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
346 dbmanage.admin_prompt() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
347 dbmanage.create_permissions() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
348 dbmanage.populate_default_permissions() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
349 Session().commit() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
350 # PART TWO make test repo |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
351 log.debug('making test vcs repositories') |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
352 |
6621
6cc40e545e9a
test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents:
6617
diff
changeset
|
353 idx_path = config['index_dir'] |
6cc40e545e9a
test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents:
6617
diff
changeset
|
354 data_path = config['cache_dir'] |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
355 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
356 #clean index and data |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
357 if idx_path and os.path.exists(idx_path): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
358 log.debug('remove %s', idx_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
359 shutil.rmtree(idx_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
360 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
361 if data_path and os.path.exists(data_path): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
362 log.debug('remove %s', data_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
363 shutil.rmtree(data_path) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
364 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
365 #CREATE DEFAULT TEST REPOS |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
366 tar = tarfile.open(os.path.join(FIXTURES, 'vcs_test_hg.tar.gz')) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
367 tar.extractall(os.path.join(TESTS_TMP_PATH, HG_REPO)) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
368 tar.close() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
369 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
370 tar = tarfile.open(os.path.join(FIXTURES, 'vcs_test_git.tar.gz')) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
371 tar.extractall(os.path.join(TESTS_TMP_PATH, GIT_REPO)) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
372 tar.close() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
373 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
374 #LOAD VCS test stuff |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
375 from kallithea.tests.vcs import setup_package |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
376 setup_package() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
377 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
378 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
379 def create_test_index(repo_location, config, full_index): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
380 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
381 Makes default test index |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
382 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
383 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
384 from kallithea.lib.indexers.daemon import WhooshIndexingDaemon |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
385 from kallithea.lib.pidlock import DaemonLock, LockHeld |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
386 |
6621
6cc40e545e9a
test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents:
6617
diff
changeset
|
387 index_location = os.path.join(config['index_dir']) |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
388 if not os.path.exists(index_location): |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
389 os.makedirs(index_location) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
390 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
391 try: |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
392 l = DaemonLock(file_=os.path.join(dirname(index_location), 'make_index.lock')) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
393 WhooshIndexingDaemon(index_location=index_location, |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
394 repo_location=repo_location) \ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
395 .run(full_index=full_index) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
396 l.release() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
397 except LockHeld: |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
398 pass |