annotate kallithea/tests/__init__.py @ 5909:ab36d9a31a2d

pytest migration: add args/kwargs to assertRaises replacement Even though we'll soon get rid of the assertRaises replacement, the tests in kallithea/tests/other/test_validators.py expect to pass it args and kwargs so we need to adapt it first.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Fri, 06 May 2016 21:20:56 +0200
parents 91b89797a775
children 151459ea3bd1
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: 3960
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: 3960
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: 3960
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: 3960
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: 3960
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: 3960
diff changeset
6 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
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: 3960
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: 3960
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: 3960
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: 3960
diff changeset
11 #
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
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: 3960
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: 3960
diff changeset
14
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
15 """
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
16 Pylons application test package
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17
5701
2d2decce586f pytest migration: update documentation
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5631
diff changeset
18 This package assumes the Pylons environment is already loaded.
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20 This module initializes the application via ``websetup`` (`paster
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 setup-app`) and provides the base testing objects.
3637
58c2b54540d2 tests docs
Marcin Kuzminski <marcin@python-works.com>
parents: 3550
diff changeset
22
5701
2d2decce586f pytest migration: update documentation
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5631
diff changeset
23 Refer to docs/contributing.rst for details on running the test suite.
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 """
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
25 import os
5409
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
26 import re
1707
54fda6ce9e98 fixes timezone issues with tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
27 import time
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
28 import logging
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
29 import datetime
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
30 import hashlib
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
31 import tempfile
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
32 from os.path import join as jn
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
33
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1718
diff changeset
34 from tempfile import _RandomNameSequence
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
36 import pylons
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
37 import pylons.test
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 from pylons import config, url
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
39 from pylons.i18n.translation import _get_translator
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
40 from pylons.util import ContextObj
3797
d7488551578e synced vcs with upstream
Marcin Kuzminski <marcin@python-works.com>
parents: 3674
diff changeset
41
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
42 from routes.util import URLGenerator
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43 from webtest import TestApp
5702
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
44 import pytest
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
45
4186
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
46 from kallithea.lib.compat import unittest
7e5f8c12a3fc First step in two-part process to rename directories to kallithea.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4116
diff changeset
47 from kallithea import is_windows
5214
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
48 from kallithea.model.db import Notification, User, UserNotification
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
49 from kallithea.model.meta import Session
5019
cf8c3cf122a0 tests: Make `parameterized` stuff work with both pytest and nose
Marc Abramowitz <marc@marc-abramowitz.com>
parents: 4993
diff changeset
50 from kallithea.tests.parameterized import parameterized
4422
d51a6f5e57d1 cleanup: remove unused Python imports, found with pyflakes
Mads Kiilerich <madski@unity3d.com>
parents: 4206
diff changeset
51 from kallithea.lib.utils2 import safe_str
1707
54fda6ce9e98 fixes timezone issues with tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
52
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
53
1707
54fda6ce9e98 fixes timezone issues with tests
Marcin Kuzminski <marcin@python-works.com>
parents: 1628
diff changeset
54 os.environ['TZ'] = 'UTC'
2254
8b1a79ad7a42 fix windows test issue with tzset()
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
55 if not is_windows:
8b1a79ad7a42 fix windows test issue with tzset()
Marcin Kuzminski <marcin@python-works.com>
parents: 1818
diff changeset
56 time.tzset()
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 483
diff changeset
57
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
58 log = logging.getLogger(__name__)
473
6b934c9607e7 Improved testing scenarios. Made test env creator
Marcin Kuzminski <marcin@python-works.com>
parents: 469
diff changeset
59
5702
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
60 skipif = pytest.mark.skipif
5712
6b67bbc1652e pytest migration: make pytest's parametrize functionality available
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5709
diff changeset
61 parametrize = pytest.mark.parametrize
5702
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
62
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
63 __all__ = [
5712
6b67bbc1652e pytest migration: make pytest's parametrize functionality available
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5709
diff changeset
64 'skipif', 'parametrize', 'parameterized', 'environ', 'url', 'TestController', 'TestControllerPytest',
5702
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
65 'ldap_lib_installed', 'pam_lib_installed', 'BaseTestCase', 'init_stack',
2466
7010dc12f10c Added rewritten validators module + tests
Marcin Kuzminski <marcin@python-works.com>
parents: 2459
diff changeset
66 'TESTS_TMP_PATH', 'HG_REPO', 'GIT_REPO', 'NEW_HG_REPO', 'NEW_GIT_REPO',
2728
6341084b7a2f rewrote test_scm_operations, now run by nosetests
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
67 'HG_FORK', 'GIT_FORK', 'TEST_USER_ADMIN_LOGIN', 'TEST_USER_ADMIN_PASS',
5206
414142964b62 tests: remove hardcoded test e-mail addresses
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5019
diff changeset
68 'TEST_USER_ADMIN_EMAIL', 'TEST_USER_REGULAR_LOGIN', 'TEST_USER_REGULAR_PASS',
2728
6341084b7a2f rewrote test_scm_operations, now run by nosetests
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
69 'TEST_USER_REGULAR_EMAIL', 'TEST_USER_REGULAR2_LOGIN',
6341084b7a2f rewrote test_scm_operations, now run by nosetests
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
70 'TEST_USER_REGULAR2_PASS', 'TEST_USER_REGULAR2_EMAIL', 'TEST_HG_REPO',
6341084b7a2f rewrote test_scm_operations, now run by nosetests
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
71 'TEST_HG_REPO_CLONE', 'TEST_HG_REPO_PULL', 'TEST_GIT_REPO',
6341084b7a2f rewrote test_scm_operations, now run by nosetests
Marcin Kuzminski <marcin@python-works.com>
parents: 2629
diff changeset
72 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
5707
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
73 'GIT_REMOTE_REPO', 'SCM_TESTS', 'remove_all_notifications',
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
74 ]
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
75
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
76 # Invoke websetup with the current config file
1628
de71a4bde097 Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
77 # SetupCommand('setup-app').run([config_file])
491
fefffd6fd5f4 Added some more tests, rewrite testing schema, to autogenerate fresh db, new index.
Marcin Kuzminski <marcin@python-works.com>
parents: 483
diff changeset
78
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
79 environ = {}
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
80
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
81 #SOME GLOBALS FOR TESTS
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1718
diff changeset
82
5753
1a7611b9730e replace absolute /tmp paths to tempfile.gettempdir()
domruf <dominikruf@gmail.com>
parents: 5751
diff changeset
83 TESTS_TMP_PATH = jn(tempfile.gettempdir(), 'rc_test_%s' % _RandomNameSequence().next())
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
84 TEST_USER_ADMIN_LOGIN = 'test_admin'
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
85 TEST_USER_ADMIN_PASS = 'test12'
5497
12b47803189f cleanup: use example.com for tests and examples
Søren Løvborg <sorenl@unity3d.com>
parents: 5465
diff changeset
86 TEST_USER_ADMIN_EMAIL = 'test_admin@example.com'
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
87
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
88 TEST_USER_REGULAR_LOGIN = 'test_regular'
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
89 TEST_USER_REGULAR_PASS = 'test12'
5497
12b47803189f cleanup: use example.com for tests and examples
Søren Løvborg <sorenl@unity3d.com>
parents: 5465
diff changeset
90 TEST_USER_REGULAR_EMAIL = 'test_regular@example.com'
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
91
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
92 TEST_USER_REGULAR2_LOGIN = 'test_regular2'
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
93 TEST_USER_REGULAR2_PASS = 'test12'
5497
12b47803189f cleanup: use example.com for tests and examples
Søren Løvborg <sorenl@unity3d.com>
parents: 5465
diff changeset
94 TEST_USER_REGULAR2_EMAIL = 'test_regular2@example.com'
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
95
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
96 HG_REPO = u'vcs_test_hg'
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
97 GIT_REPO = u'vcs_test_git'
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
98
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
99 NEW_HG_REPO = u'vcs_test_hg_new'
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
100 NEW_GIT_REPO = u'vcs_test_git_new'
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
101
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
102 HG_FORK = u'vcs_test_hg_fork'
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
103 GIT_FORK = u'vcs_test_git_fork'
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
104
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
105 ## VCS
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
106 SCM_TESTS = ['hg', 'git']
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
107 uniq_suffix = str(int(time.mktime(datetime.datetime.now().timetuple())))
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
108
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
109 GIT_REMOTE_REPO = 'git://github.com/codeinn/vcs.git'
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
110
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
111 TEST_GIT_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
112 TEST_GIT_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcsgitclone%s' % uniq_suffix)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
113 TEST_GIT_REPO_PULL = jn(TESTS_TMP_PATH, 'vcsgitpull%s' % uniq_suffix)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
114
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
115
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
116 HG_REMOTE_REPO = 'http://bitbucket.org/marcinkuzminski/vcs'
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
117
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
118 TEST_HG_REPO = jn(TESTS_TMP_PATH, HG_REPO)
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
119 TEST_HG_REPO_CLONE = jn(TESTS_TMP_PATH, 'vcshgclone%s' % uniq_suffix)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
120 TEST_HG_REPO_PULL = jn(TESTS_TMP_PATH, 'vcshgpull%s' % uniq_suffix)
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
121
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
122 TEST_DIR = tempfile.gettempdir()
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
123 TEST_REPO_PREFIX = 'vcs-test'
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
124
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
125 # cached repos if any !
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
126 # comment out to get some other repos from bb or github
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
127 GIT_REMOTE_REPO = jn(TESTS_TMP_PATH, GIT_REPO)
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
128 HG_REMOTE_REPO = jn(TESTS_TMP_PATH, HG_REPO)
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
129
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
130 #skip ldap tests if LDAP lib is not installed
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
131 ldap_lib_installed = False
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
132 try:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
133 import ldap
4422
d51a6f5e57d1 cleanup: remove unused Python imports, found with pyflakes
Mads Kiilerich <madski@unity3d.com>
parents: 4206
diff changeset
134 ldap.API_VERSION
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
135 ldap_lib_installed = True
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
136 except ImportError:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
137 # means that python-ldap is not installed
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
138 pass
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
139
5334
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
140 try:
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
141 import pam
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
142 pam.PAM_TEXT_INFO
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
143 pam_lib_installed = True
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
144 except ImportError:
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
145 pam_lib_installed = False
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
146
4732
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
147 class NullHandler(logging.Handler):
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
148 def emit(self, record):
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
149 pass
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
150
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
151 def init_stack(config=None):
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
152 if not config:
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
153 config = pylons.test.pylonsapp.config
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
154 url._push_object(URLGenerator(config['routes.map'], environ))
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
155 pylons.app_globals._push_object(config['pylons.app_globals'])
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
156 pylons.config._push_object(config)
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
157 pylons.tmpl_context._push_object(ContextObj())
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
158 # Initialize a translator for tests that utilize i18n
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
159 translator = _get_translator(pylons.config.get('lang'))
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
160 pylons.translator._push_object(translator)
4732
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
161 h = NullHandler()
0f96804480c3 tests: create default logging handler to mute 'No handlers could be found for logger' warnings
Mads Kiilerich <madski@unity3d.com>
parents: 4697
diff changeset
162 logging.getLogger("kallithea").addHandler(h)
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
163
5707
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
164 def remove_all_notifications():
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
165 Notification.query().delete()
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
166
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
167 # Because query().delete() does not (by default) trigger cascades.
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
168 # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
169 UserNotification.query().delete()
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
170
37d713674f63 tests: move remove_all_notifications outside of BaseTestCase
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5706
diff changeset
171 Session().commit()
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
172
3872
2b9da8749065 Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
173 class BaseTestCase(unittest.TestCase):
5709
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
174 """Unittest-style base test case. Deprecated in favor of pytest style."""
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
175
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
176 def __init__(self, *args, **kwargs):
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
177 self.wsgiapp = pylons.test.pylonsapp
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
178 init_stack(self.wsgiapp.config)
3872
2b9da8749065 Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
179 unittest.TestCase.__init__(self, *args, **kwargs)
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
180
5709
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
181 class BaseTestController(object):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
182 """Base test controller used by pytest and unittest tests controllers."""
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
183
5709
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
184 # Note: pytest base classes cannot have an __init__ method
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
185
5709
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
186 def init(self):
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
187 self.app = TestApp(self.wsgiapp)
4116
ffd45b185016 Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 3960
diff changeset
188 self.maxDiff = None
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
189 self.index_location = config['app_conf']['index_dir']
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
190
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
191 def log_user(self, username=TEST_USER_ADMIN_LOGIN,
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
192 password=TEST_USER_ADMIN_PASS):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
193 self._logged_username = username
464
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
194 response = self.app.post(url(controller='login', action='index'),
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
195 {'username': username,
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
196 'password': password})
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
197
5346
b75f1d0753d6 privacy: don't tell users what is the reason for a failed login
Andrew Shadura <andrew@shadura.me>
parents: 5334
diff changeset
198 if 'Invalid username or password' in response.body:
5751
1883a4e4c390 tests: self.fail is better written as pytest.fail now
domruf <dominikruf@gmail.com>
parents: 5712
diff changeset
199 pytest.fail('could not login using %s %s' % (username, password))
688
8acbfa837180 Tests rewrite for 1.2 added some globals configs to make tests easier.
Marcin Kuzminski <marcin@python-works.com>
parents: 548
diff changeset
200
1366
9c0f5d558789 fixes #200, rewrote the whole caching mechanism to get rid of such problems. Now cached instances are attached
Marcin Kuzminski <marcin@python-works.com>
parents: 1047
diff changeset
201 self.assertEqual(response.status, '302 Found')
5323
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
202 self.assert_authenticated_user(response, username)
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
203
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1718
diff changeset
204 response = response.follow()
4197
d208416c84c6 Rename rhodecode_user to authuser - it is an AuthUser instance
Bradley M. Kuhn <bkuhn@sfconservancy.org>
parents: 4187
diff changeset
205 return response.session['authuser']
1382
c310e1e1e757 Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
206
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
207 def _get_logged_user(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
208 return User.get_by_username(self._logged_username)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
209
5323
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
210 def assert_authenticated_user(self, response, expected_username):
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
211 cookie = response.session.get('authuser')
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
212 user = cookie and cookie.get('user_id')
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
213 user = user and User.get(user)
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
214 user = user and user.username
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
215 self.assertEqual(user, expected_username)
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
216
4993
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
217 def authentication_token(self):
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
218 return self.app.get(url('authentication_token')).body
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
219
5409
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
220 def checkSessionFlash(self, response, msg=None, skip=0, _matcher=lambda msg, m: msg in m):
4881
afddaa53ab8a tests: fix handling of failing flash assertion ... again
Mads Kiilerich <madski@unity3d.com>
parents: 4775
diff changeset
221 if 'flash' not in response.session:
5751
1883a4e4c390 tests: self.fail is better written as pytest.fail now
domruf <dominikruf@gmail.com>
parents: 5712
diff changeset
222 pytest.fail(safe_str(u'msg `%s` not found - session has no flash:\n%s' % (msg, response)))
4775
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
223 try:
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
224 level, m = response.session['flash'][-1 - skip]
5409
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
225 if _matcher(msg, m):
4775
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
226 return
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
227 except IndexError:
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
228 pass
5751
1883a4e4c390 tests: self.fail is better written as pytest.fail now
domruf <dominikruf@gmail.com>
parents: 5712
diff changeset
229 pytest.fail(safe_str(u'msg `%s` not found in session flash (skipping %s): %s' %
4775
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
230 (msg, skip,
787f30a1a996 tests: make checkSessionFlash check the last flash message only but show all on failure
Mads Kiilerich <madski@unity3d.com>
parents: 4732
diff changeset
231 ', '.join('`%s`' % m for level, m in response.session['flash']))))
5409
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
232
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
233 def checkSessionFlashRegex(self, response, regex, skip=0):
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
234 self.checkSessionFlash(response, regex, skip=skip, _matcher=re.search)
5709
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
235
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
236 class TestController(BaseTestCase, BaseTestController):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
237 """Deprecated unittest-style test controller"""
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
238
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
239 def __init__(self, *args, **kwargs):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
240 super(TestController, self).__init__(*args, **kwargs)
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
241 self.init()
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
242
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
243 class TestControllerPytest(BaseTestController):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
244 """Pytest-style test controller"""
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
245
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
246 # Note: pytest base classes cannot have an __init__ method
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
247
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
248 @pytest.fixture(autouse=True)
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
249 def app_fixture(self):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
250 self.wsgiapp = pylons.test.pylonsapp
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
251 init_stack(self.wsgiapp.config)
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
252 self.init()
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
253 return self.app
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
254
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
255 # transitional implementations of unittest.TestCase asserts
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
256 # Users of these should be converted to pytest's single 'assert' call
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
257 def assertEqual(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
258 assert first == second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
259 def assertNotEqual(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
260 assert first != second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
261 def assertTrue(self, expr, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
262 assert bool(expr) is True
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
263 def assertFalse(self, expr, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
264 assert bool(expr) is False
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
265 def assertIn(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
266 assert first in second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
267 def assertNotIn(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
268 assert first not in second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
269 def assertSetEqual(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
270 assert first == second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
271 def assertListEqual(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
272 assert first == second
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
273 def assertDictEqual(self, first, second, msg=None):
877bcf22bf71 pytest migration: introduce TestControllerPytest
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5707
diff changeset
274 assert first == second
5909
ab36d9a31a2d pytest migration: add args/kwargs to assertRaises replacement
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 5804
diff changeset
275 def assertRaises(self, exception, method, *args, **kwargs):
5804
91b89797a775 pytest migration: add temporary assertRaises wrapper
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5753
diff changeset
276 with pytest.raises(exception):
5909
ab36d9a31a2d pytest migration: add args/kwargs to assertRaises replacement
Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
parents: 5804
diff changeset
277 method(*args, **kwargs)