annotate kallithea/tests/fixture.py @ 8802:76394eb36b27

tests: fix create_fork to actually pass a repo id as fork_parent_id Passing a whole repo wouldn't work if actually using celery and thus serializing the parameters. The test scenario was thus different from actual runtime.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 09 Nov 2020 14:15:38 +0100
parents f3fab7b124f2
children f1138ec0ba7f
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)
8728
f3fab7b124f2 imports: try to use global imports unless it is a layering violation
Mads Kiilerich <mads@kiilerich.com>
parents: 8718
diff changeset
46 from kallithea.tests.vcs import setup_package
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
47
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
48
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
49 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
50
5998
037efd94e955 cleanup: get rid of dn as shortcut for os.path.dirname
domruf <dominikruf@gmail.com>
parents: 5768
diff changeset
51 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
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
8585
1de3e5d104bf tests: consistent use of more helpful raise_exception "fixture"
Mads Kiilerich <mads@kiilerich.com>
parents: 8288
diff changeset
54 def raise_exception(*args, **kwargs):
1de3e5d104bf tests: consistent use of more helpful raise_exception "fixture"
Mads Kiilerich <mads@kiilerich.com>
parents: 8288
diff changeset
55 raise Exception('raise_exception raised exception')
3642
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
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
58 class Fixture(object):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
59
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
60 def __init__(self):
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
61 pass
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
62
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
63 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
64 """
4880
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
65 Context manager for controlling anonymous access.
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
66 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
67
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
68 Usage:
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
69
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
70 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
71 with fixture.anon_access(False):
4880
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
72 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
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
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
75 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
76 def __enter__(self):
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
77 anon = db.User.get_default_user()
4880
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
78 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
79 anon.active = status
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
80 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
81 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
82
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
83 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
84 anon = db.User.get_default_user()
4880
5d8fbada35fc tests: cleanup of fixture.anon_access
Mads Kiilerich <madski@unity3d.com>
parents: 4849
diff changeset
85 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
86 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
87
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
88 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
89
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
90 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
91 """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
92 defs = dict(
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
93 repo_name=None,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
94 repo_type='hg',
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
95 clone_uri='',
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
96 repo_group='-1',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
97 repo_description='DESC',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
98 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
99 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
100 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
101 repo_state=db.Repository.STATE_CREATED,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
102 )
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
103 defs.update(custom)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
104 if 'repo_name_full' not in custom:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
105 defs.update({'repo_name_full': defs['repo_name']})
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
106
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
107 # 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
108 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
109 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
110
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
111 return defs
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
112
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
113 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
114 """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
115 defs = dict(
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
116 group_name=None,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
117 group_description='DESC',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
118 parent_group_id='-1',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
119 perms_updates=[],
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
120 perms_new=[],
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,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
132 firstname='TestUser',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
133 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
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,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
146 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
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']
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
157 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
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
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
161 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
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)
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
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):
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
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
186 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
187 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
188 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
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
194 meta.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):
7316
7d5e8894db6c tests: clarify that fixture.create_repo_group takes a name, not a path
Mads Kiilerich <mads@kiilerich.com>
parents: 5378
diff changeset
197 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
198 if 'skip_if_exists' in kwargs:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
199 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
200 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
201 if gr:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
202 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
203 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
204 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
205 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
206 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
207 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
208 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
209 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
210 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
211 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
212 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
213
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
214 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
215 RepoGroupModel().delete(repogroupid)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
216 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
217
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
218 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
219 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
220 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
221 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
222 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
223 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
224 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
225 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
226 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
227 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
228 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
229
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
230 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
231 UserModel().delete(userid)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
232 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
233
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
234 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
235 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
236 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
237 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
238 if gr:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
239 return gr
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
240 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
241 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
242 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
243 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
244 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
245 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
246 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
247 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
248 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
249 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
250
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
251 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
252 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
253 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
254
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
255 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
256 form_data = {
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
257 '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
258 '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
259 '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
260 'lifetime': -1,
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
261 '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
262 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
263 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
264 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
265 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
266 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
267 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
268 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
269 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
270
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
271 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
272
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
273 def 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
274 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
275 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
276 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
277 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
278 else:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
279 GistModel().delete(g)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
280 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
281
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
282 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
283 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
284 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
285 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
286 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
287
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
288 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
289
6471
8b4c09e740a7 tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 6468
diff changeset
290 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
291 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
292 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
293 _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
294 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
295 _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
296 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
297 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
298
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
299 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
300 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
301 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
302 '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
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 }
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 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
306 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
307 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
308 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
309 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
310 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
311 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
312 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
313 )
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 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
315 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
316 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
317 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
318 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
319 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
320 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
321 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
322 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
323 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
324 )
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
325 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
326
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
327 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
328 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
329 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
330 meta.Session().commit()
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
331 return csm
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
332
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
333 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
334 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
335 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
336 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
337 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
338 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
339 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
340 request.authuser = AuthUser(dbuser=owner_user)
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
341 # 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
342 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
343 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
344 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
345 meta.Session().commit()
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
346 return pull_request.pull_request_id
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
347
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
348
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 # 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
351 #==============================================================================
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
352
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
353 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
354 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
355 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
356 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
357 """
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 # 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
360 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
361 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
362
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
363 # 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
364 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
365 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
366 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
367
6623
5b3568c99cc3 sqlalchemy: remove echo setting from .ini files and create_engine
domruf <dominikruf@gmail.com>
parents: 6621
diff changeset
368 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
369 cli_args={
8675
3afc6bff84bb db_manage: drop special DbManage mode for tests
Mads Kiilerich <mads@kiilerich.com>
parents: 8674
diff changeset
370 '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
371 '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
372 '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
373 '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
374 })
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
375 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
376 # 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
377 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
378 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
379 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
380 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
381 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
382 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
383 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
384 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
385 # 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
386 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
387
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
388 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
389 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
390
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
391 # 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
392 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
393 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
394 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
395
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
396 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
397 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
398 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
399
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
400 # 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
401 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
402 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
403 tar.close()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
404
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_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
406 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
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
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
409 # 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
410 setup_package()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
411
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 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
414 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
415 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
416 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
417
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
418 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
419 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
420 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
421
6799
5aa9fa97306f lib: make the DaemonLock lock location parameter mandatory - the default was never used
Mads Kiilerich <mads@kiilerich.com>
parents: 6798
diff changeset
422 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
423 WhooshIndexingDaemon(index_location=index_location,
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
424 repo_location=repo_location) \
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
425 .run(full_index=full_index)
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
426 l.release()
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
427
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 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
430 ui.write(b"failing_test_hook failed\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
431 return 1
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
432
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 def exception_test_hook(ui, repo, **kwargs):
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
435 raise Exception("exception_test_hook threw an exception")
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
436
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 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
439 ui.write(b"passing_test_hook succeeded\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
440 return 0