Mercurial > kallithea
annotate kallithea/tests/fixture.py @ 7187:522cfb2be9e1
tests: add custom hook tests
Git testing is omitted for now - errors are not reported as they are for Hg.
author | domruf <dominikruf@gmail.com> |
---|---|
date | Sun, 26 Nov 2017 13:12:46 +0100 |
parents | 438876d818d3 |
children | ebc239a474a3 |
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 |
6655
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
25 import mock |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
26 from tg import request |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
27 from tg.util.webtest import test_context |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
28 |
6652
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
29 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
|
30 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
|
31 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
|
32 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
|
33 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
|
34 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
|
35 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
|
36 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
|
37 from kallithea.model.comment import ChangesetCommentsModel |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
38 from kallithea.model.changeset_status import ChangesetStatusModel |
6655
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
39 from kallithea.model.pull_request import CreatePullRequestAction#, CreatePullRequestIterationAction, PullRequestModel |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
40 from kallithea.lib import helpers |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
41 from kallithea.lib.auth import AuthUser |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
42 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
|
43 from kallithea.lib.vcs.backends.base import EmptyChangeset |
6655
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
44 from kallithea.tests.base import invalidate_all_caches, GIT_REPO, HG_REPO, \ |
7086
438876d818d3
tests: git changeset authors need to have the format 'username <user@example.com>'
domruf <dominikruf@gmail.com>
parents:
6864
diff
changeset
|
45 TESTS_TMP_PATH, TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN, TEST_USER_ADMIN_EMAIL |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
46 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
47 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
48 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
|
49 |
5998
037efd94e955
cleanup: get rid of dn as shortcut for os.path.dirname
domruf <dominikruf@gmail.com>
parents:
5768
diff
changeset
|
50 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
|
51 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
52 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
53 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
|
54 raise Exception('Total Crash !') |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
55 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
56 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
57 class Fixture(object): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
58 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
59 def __init__(self): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
60 pass |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
61 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
62 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
|
63 """ |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
64 Context manager for controlling anonymous access. |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
65 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
|
66 |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
67 Usage: |
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
68 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
69 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
|
70 with fixture.anon_access(False): |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
71 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
|
72 """ |
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 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
|
75 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
|
76 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
77 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
|
78 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
|
79 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
|
80 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
|
81 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
82 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
|
83 anon = User.get_default_user() |
4880
5d8fbada35fc
tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents:
4849
diff
changeset
|
84 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
|
85 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
|
86 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
87 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
|
88 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
89 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
|
90 """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
|
91 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
92 repo_name=None, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
93 repo_type='hg', |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
94 clone_uri='', |
5281
82faecc21324
repogroups: use group IDs as integers instead of unicoding them
Mads Kiilerich <madski@unity3d.com>
parents:
4880
diff
changeset
|
95 repo_group=u'-1', |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
96 repo_description=u'DESC', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
97 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
|
98 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
|
99 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
|
100 repo_state=Repository.STATE_CREATED, |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
101 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
102 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
103 if 'repo_name_full' not in custom: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
104 defs.update({'repo_name_full': defs['repo_name']}) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
105 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
106 # 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
|
107 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
|
108 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
|
109 |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
110 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
111 |
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
|
112 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
|
113 """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
|
114 defs = dict( |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
115 group_name=None, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
116 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
|
117 parent_group_id=u'-1', |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
118 perms_updates=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
119 perms_new=[], |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
120 enable_locking=False, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
121 recursive=False |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
122 ) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
123 defs.update(custom) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
124 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
125 return defs |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
126 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
127 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
|
128 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
|
129 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
|
130 password='qweqwe', |
4183
da3c57422ee6
Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4116
diff
changeset
|
131 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
|
132 firstname=u'TestUser', |
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
133 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
|
134 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
|
135 admin=False, |
4209
de26de99ac5b
Rename auth_rhodecode to auth_internal
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
4187
diff
changeset
|
136 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
|
137 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
|
138 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
139 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
|
140 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
141 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
|
142 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
143 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
|
144 defs = dict( |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
145 users_group_name=name, |
5631
bd4840ad72d3
tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents:
5378
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 ) |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
150 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
|
151 |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
152 return defs |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
153 |
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
|
154 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
|
155 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
156 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
157 r = Repository.get_by_repo_name(name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
158 if r: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
159 return r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
160 |
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
|
161 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
|
162 repo_group = repo_group.group_id |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
163 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
164 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
|
165 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
|
166 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
|
167 RepoModel().create(form_data, cur_user) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
168 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
|
169 ScmModel().mark_for_invalidation(name) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
170 return Repository.get_by_repo_name(name) |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
171 |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
172 def create_fork(self, repo_to_fork, fork_name, **kwargs): |
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
173 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
|
174 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
175 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
|
176 fork_parent_id=repo_to_fork, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
177 repo_type=repo_to_fork.repo_type, |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
178 **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
|
179 # 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
|
180 form_data['description'] = form_data['repo_description'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
181 form_data['private'] = form_data['repo_private'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
182 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
|
183 |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
184 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
|
185 RepoModel().create_fork(form_data, cur_user=owner) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
186 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
|
187 ScmModel().mark_for_invalidation(fork_name) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
188 r = Repository.get_by_repo_name(fork_name) |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
189 assert r |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
190 return r |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
191 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
192 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
|
193 RepoModel().delete(repo_name, **kwargs) |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
194 Session().commit() |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
195 |
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
|
196 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
|
197 if 'skip_if_exists' in kwargs: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
198 del kwargs['skip_if_exists'] |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
199 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
|
200 if gr: |
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
201 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
|
202 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
|
203 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
|
204 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
|
205 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
|
206 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
|
207 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
|
208 ) |
3642
749dfd6b6e95
added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff
changeset
|
209 Session().commit() |
3647
8a86836fad64
more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents:
3642
diff
changeset
|
210 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
|
211 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
|
212 |
4116
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
213 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
|
214 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
|
215 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
|
216 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
217 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
|
218 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
|
219 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
|
220 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
|
221 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
|
222 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
|
223 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
|
224 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
|
225 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
|
226 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
|
227 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
|
228 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
229 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
|
230 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
|
231 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
|
232 |
3714
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
233 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
|
234 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
|
235 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
|
236 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
|
237 if gr: |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
238 return gr |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
239 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
|
240 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
|
241 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
|
242 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
|
243 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
|
244 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
|
245 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
|
246 Session().commit() |
7e3d89d9d3a2
- Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents:
3647
diff
changeset
|
247 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
|
248 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
|
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 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
|
251 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
|
252 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
|
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 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
|
255 form_data = { |
4731
c154dc461bd5
tests: fix some test sqlalchemy unicode warnings
Mads Kiilerich <madski@unity3d.com>
parents:
4209
diff
changeset
|
256 '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
|
257 'owner': TEST_USER_ADMIN_LOGIN, |
6118
3d1fcf67f299
model: drop BaseModel.cls
Søren Løvborg <sorenl@unity3d.com>
parents:
6117
diff
changeset
|
258 '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
|
259 'lifetime': -1, |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6799
diff
changeset
|
260 'gist_mapping': {'filename1.txt': {'content': 'hello world'}} |
4116
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 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
|
263 gist = GistModel().create( |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6799
diff
changeset
|
264 description=form_data['description'], owner=form_data['owner'], |
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 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
|
266 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
|
267 ) |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
268 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
|
269 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
270 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
|
271 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
272 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
|
273 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
|
274 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
|
275 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
|
276 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
|
277 else: |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
278 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
|
279 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
|
280 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
281 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
|
282 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
|
283 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
|
284 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
|
285 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
|
286 |
ffd45b185016
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents:
3714
diff
changeset
|
287 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
|
288 |
6471
8b4c09e740a7
tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents:
6468
diff
changeset
|
289 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
|
290 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
|
291 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
|
292 _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
|
293 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
|
294 _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
|
295 if author is None: |
7086
438876d818d3
tests: git changeset authors need to have the format 'username <user@example.com>'
domruf <dominikruf@gmail.com>
parents:
6864
diff
changeset
|
296 author = '%s <%s>' % (TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_EMAIL) |
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
|
297 |
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 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
|
299 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 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
|
301 '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
|
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 } |
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().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
|
305 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
|
306 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
|
307 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
|
308 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
|
309 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
|
310 ) |
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 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
|
312 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
|
313 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
|
314 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
|
315 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
|
316 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
|
317 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
|
318 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
|
319 ) |
fd8c0117ca22
tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents:
4731
diff
changeset
|
320 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
|
321 |
6652
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
322 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
|
323 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
|
324 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
|
325 Session().commit() |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
326 return csm |
b60fb9461b18
Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents:
6623
diff
changeset
|
327 |
6676
95e149edc46c
sqlalchemy: fix warnings from running the test suite
Mads Kiilerich <mads@kiilerich.com>
parents:
6655
diff
changeset
|
328 def create_pullrequest(self, testcontroller, repo_name, pr_src_rev, pr_dst_rev, title=u'title'): |
6655
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
329 org_ref = 'branch:stable:%s' % pr_src_rev |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
330 other_ref = 'branch:default:%s' % pr_dst_rev |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
331 with test_context(testcontroller.app): # needed to be able to mock request user |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
332 org_repo = other_repo = Repository.get_by_repo_name(repo_name) |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
333 owner_user = User.get_by_username(TEST_USER_ADMIN_LOGIN) |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
334 reviewers = [User.get_by_username(TEST_USER_REGULAR_LOGIN)] |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
335 request.authuser = request.user = AuthUser(dbuser=owner_user) |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
336 # creating a PR sends a message with an absolute URL - without routing that requires mocking |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
337 with mock.patch.object(helpers, 'url', (lambda arg, qualified=False, **kwargs: ('https://localhost' if qualified else '') + '/fake/' + arg)): |
6676
95e149edc46c
sqlalchemy: fix warnings from running the test suite
Mads Kiilerich <mads@kiilerich.com>
parents:
6655
diff
changeset
|
338 cmd = CreatePullRequestAction(org_repo, other_repo, org_ref, other_ref, title, u'No description', owner_user, reviewers) |
6655
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
339 pull_request = cmd.execute() |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
340 Session().commit() |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
341 return pull_request.pull_request_id |
6452215a54ee
api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents:
6652
diff
changeset
|
342 |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
343 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
344 #============================================================================== |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
345 # 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
|
346 #============================================================================== |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
347 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
348 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
|
349 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
350 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
|
351 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
|
352 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
353 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
354 # 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
|
355 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
|
356 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
|
357 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
358 # 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
|
359 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
|
360 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
|
361 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
|
362 |
6623
5b3568c99cc3
sqlalchemy: remove echo setting from .ini files and create_engine
domruf <dominikruf@gmail.com>
parents:
6621
diff
changeset
|
363 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
|
364 tests=True) |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
365 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
|
366 # 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
|
367 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
|
368 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
|
369 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
|
370 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
|
371 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
|
372 Session().commit() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
373 # 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
|
374 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
|
375 |
6621
6cc40e545e9a
test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents:
6617
diff
changeset
|
376 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
|
377 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
|
378 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6799
diff
changeset
|
379 # clean index and data |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
380 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
|
381 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
|
382 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
|
383 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
384 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
|
385 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
|
386 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
|
387 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6799
diff
changeset
|
388 # CREATE DEFAULT TEST REPOS |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
389 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
|
390 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
|
391 tar.close() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
392 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
393 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
|
394 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
|
395 tar.close() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
396 |
6864
7691290837d2
codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents:
6799
diff
changeset
|
397 # LOAD VCS test stuff |
6468
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
398 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
|
399 setup_package() |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
400 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
401 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
402 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
|
403 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
404 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
|
405 """ |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
406 |
b35f74c2d661
tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents:
6317
diff
changeset
|
407 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
|
408 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
|
409 |
6621
6cc40e545e9a
test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents:
6617
diff
changeset
|
410 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
|
411 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
|
412 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
|
413 |
6799
5aa9fa97306f
lib: make the DaemonLock lock location parameter mandatory - the default was never used
Mads Kiilerich <mads@kiilerich.com>
parents:
6798
diff
changeset
|
414 l = DaemonLock(os.path.join(index_location, 'make_index.lock')) |
6786
0866bb29f217
tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents:
6676
diff
changeset
|
415 WhooshIndexingDaemon(index_location=index_location, |
0866bb29f217
tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents:
6676
diff
changeset
|
416 repo_location=repo_location) \ |
0866bb29f217
tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents:
6676
diff
changeset
|
417 .run(full_index=full_index) |
0866bb29f217
tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents:
6676
diff
changeset
|
418 l.release() |
7187
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
419 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
420 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
421 def failing_test_hook(ui, repo, **kwargs): |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
422 ui.write("failing_test_hook failed\n") |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
423 return 1 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
424 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
425 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
426 def exception_test_hook(ui, repo, **kwargs): |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
427 raise Exception("exception_test_hook threw an exception") |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
428 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
429 |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
430 def passing_test_hook(ui, repo, **kwargs): |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
431 ui.write("passing_test_hook succeeded\n") |
522cfb2be9e1
tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents:
7086
diff
changeset
|
432 return 0 |