annotate kallithea/tests/fixture.py @ 8997:66fcd3993563 draft i18n

i18n: updated translation for Chinese (Simplified) Currently translated at 45.0% (487 of 1082 strings)
author Poesty Li <poesty7450@gmail.com>
date Tue, 05 Mar 2024 11:40:54 +0100
parents a136383459ef
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 from tg import request
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
26 from tg.util.webtest import test_context
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
27
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
28 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
29 from kallithea.lib.db_manage import DbManage
8728
f3fab7b124f2 imports: try to use global imports unless it is a layering violation
Mads Kiilerich <mads@kiilerich.com>
parents: 8718
diff changeset
30 from kallithea.lib.indexers.daemon import WhooshIndexingDaemon
f3fab7b124f2 imports: try to use global imports unless it is a layering violation
Mads Kiilerich <mads@kiilerich.com>
parents: 8718
diff changeset
31 from kallithea.lib.pidlock import DaemonLock
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.lib.vcs.backends.base import EmptyChangeset
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
33 from kallithea.model import db, meta
7811
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
34 from kallithea.model.changeset_status import ChangesetStatusModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
35 from kallithea.model.comment import ChangesetCommentsModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
36 from kallithea.model.gist import GistModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
37 from kallithea.model.pull_request import CreatePullRequestAction # , CreatePullRequestIterationAction, PullRequestModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
38 from kallithea.model.repo import RepoModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
39 from kallithea.model.repo_group import RepoGroupModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
40 from kallithea.model.scm import ScmModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
41 from kallithea.model.user import UserModel
0a277465fddf scripts: initial run of import cleanup using isort
Mads Kiilerich <mads@kiilerich.com>
parents: 7730
diff changeset
42 from kallithea.model.user_group import UserGroupModel
8674
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
43 from kallithea.tests.base import (GIT_REPO, HG_REPO, IP_ADDR, TEST_USER_ADMIN_EMAIL, TEST_USER_ADMIN_LOGIN, TEST_USER_ADMIN_PASS, TEST_USER_REGULAR2_EMAIL,
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
44 TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR_EMAIL, TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS,
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
45 TESTS_TMP_PATH, 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
46
6468
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
8585
1de3e5d104bf tests: consistent use of more helpful raise_exception "fixture"
Mads Kiilerich <mads@kiilerich.com>
parents: 8288
diff changeset
53 def raise_exception(*args, **kwargs):
1de3e5d104bf tests: consistent use of more helpful raise_exception "fixture"
Mads Kiilerich <mads@kiilerich.com>
parents: 8288
diff changeset
54 raise Exception('raise_exception raised exception')
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):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
76 anon = db.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
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
79 meta.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):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
83 anon = db.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
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
85 meta.Session().commit()
4116
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='',
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
95 repo_group='-1',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
96 repo_description='DESC',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
97 repo_private=False,
8942
f2dc57c123cf repo: introduce enable_downloads and enable_statistics when creating repos
Mads Kiilerich <mads@kiilerich.com>
parents: 8806
diff changeset
98 repo_enable_statistics=False,
f2dc57c123cf repo: introduce enable_downloads and enable_statistics when creating repos
Mads Kiilerich <mads@kiilerich.com>
parents: 8806
diff changeset
99 repo_enable_downloads=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
100 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
101 repo_copy_permissions=False,
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
102 repo_state=db.Repository.STATE_CREATED,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
103 )
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
104 defs.update(custom)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
105 if 'repo_name_full' not in custom:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
106 defs.update({'repo_name_full': defs['repo_name']})
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
107
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
108 # 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
109 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
110 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
111
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
112 return defs
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
113
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
114 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
115 """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
116 defs = dict(
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
117 group_name=None,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
118 group_description='DESC',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
119 parent_group_id='-1',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
120 perms_updates=[],
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
121 perms_new=[],
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
122 recursive=False
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
123 )
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
124 defs.update(custom)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
125
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
126 return defs
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
127
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
128 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
129 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
130 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
131 password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
132 email='%s+test@example.com' % name,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
133 firstname='TestUser',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
134 lastname='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
135 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
136 admin=False,
4209
de26de99ac5b Rename auth_rhodecode to auth_internal
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
137 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
138 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
139 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
140 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
141
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
142 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
143
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
144 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
145 defs = dict(
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
146 users_group_name=name,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
147 user_group_description='DESC',
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
148 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
149 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
150 )
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
151 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
152
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
153 return defs
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
154
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
155 def create_repo(self, name, repo_group=None, cur_user=TEST_USER_ADMIN_LOGIN, **kwargs):
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
156 if 'skip_if_exists' in kwargs:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
157 del kwargs['skip_if_exists']
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
158 r = db.Repository.get_by_repo_name(name)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
159 if r:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
160 return r
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
161
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
162 if isinstance(repo_group, db.RepoGroup):
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
163 repo_group = repo_group.group_id
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
164
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
165 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
166 form_data['repo_group'] = repo_group # patch form dict so it can be used directly by model
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
167 RepoModel().create(form_data, cur_user=cur_user)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
168 meta.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)
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
170 return db.Repository.get_by_repo_name(name)
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
171
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
172 def create_fork(self, repo_to_fork, fork_name, cur_user=TEST_USER_ADMIN_LOGIN, **kwargs):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
173 repo_to_fork = db.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,
8802
76394eb36b27 tests: fix create_fork to actually pass a repo id as fork_parent_id
Mads Kiilerich <mads@kiilerich.com>
parents: 8728
diff changeset
176 fork_parent_id=repo_to_fork.repo_id,
3647
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
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
184 RepoModel().create_fork(form_data, cur_user=cur_user)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
185 meta.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
186 ScmModel().mark_for_invalidation(fork_name)
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
187 r = db.Repository.get_by_repo_name(fork_name)
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
188 assert r
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
189 return r
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
190
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
191 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
192 RepoModel().delete(repo_name, **kwargs)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
193 meta.Session().commit()
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
194
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
195 def create_repo_group(self, name, parent_group_id=None, cur_user=TEST_USER_ADMIN_LOGIN, **kwargs):
7316
7d5e8894db6c tests: clarify that fixture.create_repo_group takes a name, not a path
Mads Kiilerich <mads@kiilerich.com>
parents: 5378
diff changeset
196 assert '/' not in name, (name, kwargs) # use group_parent_id to make nested groups
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']
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
199 gr = db.RepoGroup.get_by_group_name(group_name=name)
3647
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,
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
207 owner=cur_user,
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
208 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
209 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
210 gr = db.RepoGroup.get_by_group_name(gr.group_name)
3647
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
215 meta.Session().commit()
4116
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']
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
220 user = db.User.get_by_username(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
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
225 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
226 user = db.User.get_by_username(user.username)
4116
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
231 meta.Session().commit()
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
232
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
233 def create_user_group(self, name, cur_user=TEST_USER_ADMIN_LOGIN, **kwargs):
3714
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']
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
236 gr = db.UserGroup.get_by_group_name(group_name=name)
3714
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)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
240 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
241 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
242 description=form_data['user_group_description'],
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
243 owner=cur_user,
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
244 active=form_data['users_group_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
245 group_data=form_data['user_group_data'])
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
246 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
247 user_group = db.UserGroup.get_by_group_name(user_group.users_group_name)
3714
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
252 meta.Session().commit()
4116
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 = {
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
256 'description': '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,
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
258 'gist_type': db.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(
7726
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
264 description=form_data['description'], owner=form_data['owner'], ip_addr=IP_ADDR,
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 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
268 meta.Session().commit()
4116
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):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
273 for g in db.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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
279 meta.Session().commit()
4116
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):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
291 repo = db.Repository.get_by_repo_name(repo)
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
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(
7726
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
305 user=TEST_USER_ADMIN_LOGIN,
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
306 ip_addr=IP_ADDR,
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
307 repo=repo,
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 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
310 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
311 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
312 )
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 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
314 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
315 repo=repo.scm_instance, repo_name=repo.repo_name,
7726
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
316 cs=parent,
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
317 user=TEST_USER_ADMIN_LOGIN,
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
318 ip_addr=IP_ADDR,
6471
8b4c09e740a7 tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 6468
diff changeset
319 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
320 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
321 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
322 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
323 )
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
324 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
325
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
326 def review_changeset(self, repo, revision, status, author=TEST_USER_ADMIN_LOGIN):
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
327 comment = ChangesetCommentsModel().create("review comment", repo, author, revision=revision, send_email=False)
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
328 csm = ChangesetStatusModel().set_status(repo, db.ChangesetStatus.STATUS_APPROVED, author, comment, revision=revision)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
329 meta.Session().commit()
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
330 return csm
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
331
8982
a136383459ef api: add possibility to optionally return comments from get_changeset()
Manuel Jacob <me@manueljacob.de>
parents: 8942
diff changeset
332 def add_changeset_comment(self, repo, revision, text, author=TEST_USER_ADMIN_LOGIN, f_path=None, line_no=None):
a136383459ef api: add possibility to optionally return comments from get_changeset()
Manuel Jacob <me@manueljacob.de>
parents: 8942
diff changeset
333 comment = ChangesetCommentsModel().create(text, repo, author, revision=revision, f_path=f_path, line_no=line_no, send_email=False)
a136383459ef api: add possibility to optionally return comments from get_changeset()
Manuel Jacob <me@manueljacob.de>
parents: 8942
diff changeset
334 meta.Session().commit()
a136383459ef api: add possibility to optionally return comments from get_changeset()
Manuel Jacob <me@manueljacob.de>
parents: 8942
diff changeset
335 return comment
a136383459ef api: add possibility to optionally return comments from get_changeset()
Manuel Jacob <me@manueljacob.de>
parents: 8942
diff changeset
336
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
337 def create_pullrequest(self, testcontroller, repo_name, pr_src_rev, pr_dst_rev, title='title'):
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
338 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
339 other_ref = 'branch:default:%s' % pr_dst_rev
8718
f8b092f9e6a3 lib: consistently use webutils.url instead of h.url
Mads Kiilerich <mads@kiilerich.com>
parents: 8687
diff changeset
340 with test_context(testcontroller.app): # needed to be able to mock request user and routes.url
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
341 org_repo = other_repo = db.Repository.get_by_repo_name(repo_name)
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
342 owner_user = db.User.get_by_username(TEST_USER_ADMIN_LOGIN)
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
343 reviewers = [db.User.get_by_username(TEST_USER_REGULAR_LOGIN)]
7485
c6ce891312ef auth: consistently use request.authuser - drop request.user
Mads Kiilerich <mads@kiilerich.com>
parents: 7320
diff changeset
344 request.authuser = AuthUser(dbuser=owner_user)
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
345 # creating a PR sends a message with an absolute URL - without routing that requires mocking
8718
f8b092f9e6a3 lib: consistently use webutils.url instead of h.url
Mads Kiilerich <mads@kiilerich.com>
parents: 8687
diff changeset
346 request.environ['routes.url'] = lambda arg, qualified=False, **kwargs: ('https://localhost' if qualified else '') + '/fake/' + arg
f8b092f9e6a3 lib: consistently use webutils.url instead of h.url
Mads Kiilerich <mads@kiilerich.com>
parents: 8687
diff changeset
347 cmd = CreatePullRequestAction(org_repo, other_repo, org_ref, other_ref, title, 'No description', owner_user, reviewers)
f8b092f9e6a3 lib: consistently use webutils.url instead of h.url
Mads Kiilerich <mads@kiilerich.com>
parents: 8687
diff changeset
348 pull_request = cmd.execute()
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
349 meta.Session().commit()
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
350 return pull_request.pull_request_id
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
351
6468
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 # 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
355 #==============================================================================
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
356
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
357 def create_test_env(repos_test_path, config, reuse_database):
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
358 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
359 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
360 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
361 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
362
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
363 # 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
364 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
365 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
366
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
367 # 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
368 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
369 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
370 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
371
6623
5b3568c99cc3 sqlalchemy: remove echo setting from .ini files and create_engine
domruf <dominikruf@gmail.com>
parents: 6621
diff changeset
372 dbmanage = DbManage(dbconf=dbconf, root=config['here'],
8674
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
373 cli_args={
8675
3afc6bff84bb db_manage: drop special DbManage mode for tests
Mads Kiilerich <mads@kiilerich.com>
parents: 8674
diff changeset
374 'force_ask': True,
8674
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
375 'username': TEST_USER_ADMIN_LOGIN,
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
376 'password': TEST_USER_ADMIN_PASS,
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
377 'email': TEST_USER_ADMIN_EMAIL,
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
378 })
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
379 dbmanage.create_tables(reuse_database=reuse_database)
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
380 # for tests dynamically set new root paths based on generated content
7730
bb5650d4a914 config: clarify naming of repo_root_path
Mads Kiilerich <mads@kiilerich.com>
parents: 7726
diff changeset
381 dbmanage.create_settings(dbmanage.prompt_repo_root_path(repos_test_path))
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
382 dbmanage.create_default_user()
8674
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
383 dbmanage.create_admin_user()
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
384 dbmanage.create_user(TEST_USER_REGULAR_LOGIN, TEST_USER_REGULAR_PASS, TEST_USER_REGULAR_EMAIL, False)
30aac95e7fd5 db_manage: clarify that the purpose of admin_prompt is to create the admin user
Mads Kiilerich <mads@kiilerich.com>
parents: 8593
diff changeset
385 dbmanage.create_user(TEST_USER_REGULAR2_LOGIN, TEST_USER_REGULAR2_PASS, TEST_USER_REGULAR2_EMAIL, False)
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
386 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
387 dbmanage.populate_default_permissions()
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
388 meta.Session().commit()
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
389 # 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
390 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
391
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
392 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
393 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
394
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
395 # 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
396 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
397 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
398 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
399
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
400 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
401 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
402 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
403
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
404 # 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
405 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
406 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
407 tar.close()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
408
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
409 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
410 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
411 tar.close()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
412
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
413
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
414 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
415 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
416 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
417 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
418
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
419 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
420 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
421 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
422
6799
5aa9fa97306f lib: make the DaemonLock lock location parameter mandatory - the default was never used
Mads Kiilerich <mads@kiilerich.com>
parents: 6798
diff changeset
423 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
424 WhooshIndexingDaemon(index_location=index_location,
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
425 repo_location=repo_location) \
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
426 .run(full_index=full_index)
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
427 l.release()
7187
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 failing_test_hook(ui, repo, **kwargs):
8078
45bfab30d433 py3: add b'' annotations in some places where they will be needed later
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
431 ui.write(b"failing_test_hook failed\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
432 return 1
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
433
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
434
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
435 def exception_test_hook(ui, repo, **kwargs):
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
436 raise Exception("exception_test_hook threw an exception")
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
437
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
438
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
439 def passing_test_hook(ui, repo, **kwargs):
8078
45bfab30d433 py3: add b'' annotations in some places where they will be needed later
Mads Kiilerich <mads@kiilerich.com>
parents: 7812
diff changeset
440 ui.write(b"passing_test_hook succeeded\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
441 return 0