annotate kallithea/tests/fixture.py @ 8806:3672a8e4584a

tests: drop vcs setup_package Repos are always created before running vcs tests, and the SCMFetcher code was thus effectively dead.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 14 Dec 2020 17:56:31 +0100
parents f1138ec0ba7f
children f2dc57c123cf
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,
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
98 repo_landing_rev='rev:tip',
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
99 repo_copy_permissions=False,
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
100 repo_state=db.Repository.STATE_CREATED,
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
101 )
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
102 defs.update(custom)
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
103 if 'repo_name_full' not in custom:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
104 defs.update({'repo_name_full': defs['repo_name']})
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
105
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
106 # fix the repo name if passed as repo_name_full
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
107 if defs['repo_name']:
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
108 defs['repo_name'] = defs['repo_name'].split('/')[-1]
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
109
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
110 return defs
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
111
6617
0bae66824ac5 tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents: 6471
diff changeset
112 def _get_repo_group_create_params(self, **custom):
0bae66824ac5 tests: clarify that default parameters are for form - direct model access requires different types
Mads Kiilerich <mads@kiilerich.com>
parents: 6471
diff changeset
113 """Return form values to be validated through RepoGroupForm"""
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
114 defs = dict(
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
115 group_name=None,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
116 group_description='DESC',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
117 parent_group_id='-1',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
118 perms_updates=[],
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
119 perms_new=[],
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
120 recursive=False
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
121 )
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
122 defs.update(custom)
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 return defs
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
125
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
126 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
127 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
128 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
129 password='qweqwe',
4183
da3c57422ee6 Change domain used for email addresses in tests
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
130 email='%s+test@example.com' % name,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
131 firstname='TestUser',
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
132 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
133 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
134 admin=False,
4209
de26de99ac5b Rename auth_rhodecode to auth_internal
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
135 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
136 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
137 )
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
138 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
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 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
141
3714
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
142 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
143 defs = dict(
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
144 users_group_name=name,
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
145 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
146 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
147 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
148 )
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
149 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
150
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
151 return defs
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
152
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
153 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
154 if 'skip_if_exists' in kwargs:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
155 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
156 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
157 if r:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
158 return r
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
159
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
160 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
161 repo_group = repo_group.group_id
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
162
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
163 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
164 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
165 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
166 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
167 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
168 return db.Repository.get_by_repo_name(name)
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
169
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
170 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
171 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
172
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
173 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
174 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
175 repo_type=repo_to_fork.repo_type,
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
176 **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
177 # 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
178 form_data['description'] = form_data['repo_description']
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
179 form_data['private'] = form_data['repo_private']
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
180 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
181
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
182 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
183 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
184 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
185 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
186 assert r
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
187 return r
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
188
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
189 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
190 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
191 meta.Session().commit()
3642
749dfd6b6e95 added new fixture classes
Marcin Kuzminski <marcin@python-works.com>
parents:
diff changeset
192
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
193 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
194 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
195 if 'skip_if_exists' in kwargs:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
196 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
197 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
198 if gr:
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3642
diff changeset
199 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
200 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
201 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
202 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
203 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
204 parent=parent_group_id,
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
205 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
206 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
207 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
208 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
209 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
210
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
211 def destroy_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
212 RepoGroupModel().delete(repogroupid)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
213 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
214
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
215 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
216 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
217 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
218 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
219 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
220 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
221 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
222 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
223 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
224 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
225 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
226
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
227 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
228 UserModel().delete(userid)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
229 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
230
8804
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
231 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
232 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
233 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
234 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
235 if gr:
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
236 return gr
7e3d89d9d3a2 - Manage User’s Groups: create, delete, rename, add/remove users inside.
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
237 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
238 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
239 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
240 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
241 owner=cur_user,
f1138ec0ba7f tests: simplify cur_user handling in fixture create methods
Mads Kiilerich <mads@kiilerich.com>
parents: 8802
diff changeset
242 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
243 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
244 meta.Session().commit()
8687
5e46f73f0d1c model: always import the whole db module - drop "from" imports
Mads Kiilerich <mads@kiilerich.com>
parents: 8686
diff changeset
245 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
246 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
247
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
248 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
249 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
250 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
251
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
252 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
253 form_data = {
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
254 '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
255 '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
256 '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
257 'lifetime': -1,
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
258 '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
259 }
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
260 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
261 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
262 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
263 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
264 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
265 )
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
266 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
267
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
268 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
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 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
271 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
272 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
273 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
274 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
275 else:
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)
8686
b095e2fbba44 model: always import whole meta module - also when referencing Session
Mads Kiilerich <mads@kiilerich.com>
parents: 8675
diff changeset
277 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
278
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
279 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
280 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
281 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
282 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
283 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
284
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3714
diff changeset
285 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
286
6471
8b4c09e740a7 tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 6468
diff changeset
287 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
288 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
289 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
290 _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
291 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
292 _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
293 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
294 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
295
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
296 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
297 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
298 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
299 '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
300 }
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 }
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 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
303 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
304 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
305 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
306 message=message,
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
307 nodes=nodes,
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
308 parent_cs=_cs,
6471
8b4c09e740a7 tests: add commit_change() author to specify author name explicitly
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 6468
diff changeset
309 author=author,
4842
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
310 )
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
311 else:
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
312 cs = ScmModel().commit_change(
fd8c0117ca22 tests: move helper commit_change from compare test to fixture
Thomas De Schampheleire <thomas.de_schampheleire@alcatel-lucent.com>
parents: 4731
diff changeset
313 repo=repo.scm_instance, repo_name=repo.repo_name,
7726
16df4993b442 scm: don't try to get IP address from web request in model
Mads Kiilerich <mads@kiilerich.com>
parents: 7672
diff changeset
314 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
315 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
316 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
317 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
318 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
319 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
320 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
321 )
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 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
323
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
324 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
325 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
326 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
327 meta.Session().commit()
6652
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
328 return csm
b60fb9461b18 Add JSON-RPC API for reading changeset status
Eivind Tagseth <eivindt@gmail.com>
parents: 6623
diff changeset
329
8224
e63bcce18fef py3: automatic migration with 2to3 -f unicode
Mads Kiilerich <mads@kiilerich.com>
parents: 8078
diff changeset
330 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
331 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
332 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
333 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
334 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
335 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
336 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
337 request.authuser = AuthUser(dbuser=owner_user)
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
338 # 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
339 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
340 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
341 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
342 meta.Session().commit()
6655
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
343 return pull_request.pull_request_id
6452215a54ee api: add get_pullrequest and comment_pullrequest methods
domruf <dominikruf@gmail.com>
parents: 6652
diff changeset
344
6468
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
345
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
346 #==============================================================================
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
347 # 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
348 #==============================================================================
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
349
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
350 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
351 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
352 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
353 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
354 """
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 # 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
357 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
358 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
359
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
360 # 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
361 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
362 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
363 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
364
6623
5b3568c99cc3 sqlalchemy: remove echo setting from .ini files and create_engine
domruf <dominikruf@gmail.com>
parents: 6621
diff changeset
365 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
366 cli_args={
8675
3afc6bff84bb db_manage: drop special DbManage mode for tests
Mads Kiilerich <mads@kiilerich.com>
parents: 8674
diff changeset
367 '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
368 '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
369 '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
370 '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
371 })
8593
922808a61274 tests: introduce REUSE_TEST_DB as an alternative to TEST_DB
Mads Kiilerich <mads@kiilerich.com>
parents: 8590
diff changeset
372 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
373 # 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
374 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
375 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
376 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
377 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
378 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
379 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
380 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
381 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
382 # 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
383 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
384
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
385 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
386 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
387
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
388 # 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
389 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
390 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
391 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
392
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
393 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
394 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
395 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
396
6864
7691290837d2 codingstyle: trivial whitespace fixes
Lars Kruse <devel@sumpfralle.de>
parents: 6799
diff changeset
397 # 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
398 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
399 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
400 tar.close()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
401
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
402 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
403 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
404 tar.close()
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
405
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
406
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
407 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
408 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
409 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
410 """
b35f74c2d661 tests: move test environment setup code out of utils.py
Søren Løvborg <sorenl@unity3d.com>
parents: 6317
diff changeset
411
6621
6cc40e545e9a test: move test environment initialization from the main code to tests
Anton Schur <tonich.sh@gmail.com>
parents: 6617
diff changeset
412 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
413 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
414 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
415
6799
5aa9fa97306f lib: make the DaemonLock lock location parameter mandatory - the default was never used
Mads Kiilerich <mads@kiilerich.com>
parents: 6798
diff changeset
416 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
417 WhooshIndexingDaemon(index_location=index_location,
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
418 repo_location=repo_location) \
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
419 .run(full_index=full_index)
0866bb29f217 tests: don't silence errors while creating test index
domruf <dominikruf@gmail.com>
parents: 6676
diff changeset
420 l.release()
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
421
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
422
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
423 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
424 ui.write(b"failing_test_hook failed\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
425 return 1
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
426
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 def exception_test_hook(ui, repo, **kwargs):
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
429 raise Exception("exception_test_hook threw an exception")
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
430
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
431
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
432 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
433 ui.write(b"passing_test_hook succeeded\n")
7187
522cfb2be9e1 tests: add custom hook tests
domruf <dominikruf@gmail.com>
parents: 7086
diff changeset
434 return 0