annotate kallithea/tests/__init__.py @ 5706:ff1bd1b60736

tests: remove duplicate import of 'logging'
author Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
date Tue, 09 Feb 2016 17:54:22 +0100
parents b755464eff8d
children 37d713674f63
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
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
61
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
62 __all__ = [
5702
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
63 'skipif', 'parameterized', 'environ', 'url', 'TestController',
b755464eff8d pytest migration: use pytest test skipping instead of nose's
Thomas De Schampheleire <thomas.de.schampheleire@gmail.com>
parents: 5701
diff changeset
64 '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
65 '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
66 '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
67 '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
68 '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
69 '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
70 '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
71 'TEST_GIT_REPO_CLONE', 'TEST_GIT_REPO_PULL', 'HG_REMOTE_REPO',
3647
8a86836fad64 more usage of fixture tools
Marcin Kuzminski <marcin@python-works.com>
parents: 3646
diff changeset
72 'GIT_REMOTE_REPO', 'SCM_TESTS',
1758
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
73 ]
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
74
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
75 # Invoke websetup with the current config file
1628
de71a4bde097 Some code cleanups and fixes
Marcin Kuzminski <marcin@python-works.com>
parents: 1594
diff changeset
76 # 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
77
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
78 environ = {}
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
79
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
80 #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
81
1397
dc960653f8d2 Added new random directory for each test to be better sandboxed
Marcin Kuzminski <marcin@python-works.com>
parents: 1389
diff changeset
82 TESTS_TMP_PATH = jn('/', 'tmp', 'rc_test_%s' % _RandomNameSequence().next())
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
83 TEST_USER_ADMIN_LOGIN = 'test_admin'
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
84 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
85 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
86
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
87 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
88 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
89 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
90
a87aa385f21c fixed repo_create permission by adding missing commit statements
Marcin Kuzminski <marcin@python-works.com>
parents: 1723
diff changeset
91 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
92 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
93 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
94
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
95 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
96 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
97
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
98 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
99 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
100
5631
bd4840ad72d3 tests: more consistently use unicode where unicode is expected
Mads Kiilerich <madski@unity3d.com>
parents: 5548
diff changeset
101 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
102 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
103
2451
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
104 ## VCS
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
105 SCM_TESTS = ['hg', 'git']
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
106 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
107
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
108 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
109
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
110 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
111 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
112 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
113
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 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
116
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
117 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
118 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
119 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
120
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
121 TEST_DIR = tempfile.gettempdir()
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
122 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
123
2459
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
124 # cached repos if any !
9492ab68331f Initial version of landing revisions ref #483
Marcin Kuzminski <marcin@python-works.com>
parents: 2451
diff changeset
125 # 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
126 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
127 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
128
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
129 #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
130 ldap_lib_installed = False
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
131 try:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
132 import ldap
4422
d51a6f5e57d1 cleanup: remove unused Python imports, found with pyflakes
Mads Kiilerich <madski@unity3d.com>
parents: 4206
diff changeset
133 ldap.API_VERSION
3674
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
134 ldap_lib_installed = True
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
135 except ImportError:
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
136 # 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
137 pass
ff2ea58debb5 fixed ldap tests when ldap lib is installed
Marcin Kuzminski <marcin@python-works.com>
parents: 3647
diff changeset
138
5334
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
139 try:
d8918bb94b80 tests: introduce pam_lib_installed for testing of the optional PAM auth module
Mads Kiilerich <madski@unity3d.com>
parents: 5333
diff changeset
140 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
141 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
142 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
143 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
144 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
145
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
146 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
147 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
148 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
149
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
150 def init_stack(config=None):
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
151 if not config:
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
152 config = pylons.test.pylonsapp.config
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
153 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
154 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
155 pylons.config._push_object(config)
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
156 pylons.tmpl_context._push_object(ContextObj())
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
157 # 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
158 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
159 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
160 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
161 logging.getLogger("kallithea").addHandler(h)
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
162
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
163
3872
2b9da8749065 Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
164 class BaseTestCase(unittest.TestCase):
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
165 def __init__(self, *args, **kwargs):
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
166 self.wsgiapp = pylons.test.pylonsapp
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
167 init_stack(self.wsgiapp.config)
3872
2b9da8749065 Use unittest2 for testing
Marcin Kuzminski <marcin@python-works.com>
parents: 3829
diff changeset
168 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
169
5214
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
170 def remove_all_notifications(self):
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
171 Notification.query().delete()
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
172
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
173 # Because query().delete() does not (by default) trigger cascades.
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
174 # http://docs.sqlalchemy.org/en/rel_0_7/orm/collections.html#passive-deletes
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
175 UserNotification.query().delete()
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
176
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
177 Session().commit()
9b2c5e8b37ea notification tests: delete notifications before (not after) tests
Søren Løvborg <kwi@kwi.dk>
parents: 5206
diff changeset
178
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
179
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
180 class TestController(BaseTestCase):
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
181
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
182 def __init__(self, *args, **kwargs):
3829
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
183 BaseTestCase.__init__(self, *args, **kwargs)
5067d6e826a5 created basic TestClass for tests that does
Marcin Kuzminski <marcin@python-works.com>
parents: 3797
diff changeset
184 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
185 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
186 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
187
1416
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
188 def log_user(self, username=TEST_USER_ADMIN_LOGIN,
df04752daa64 test env update
Marcin Kuzminski <marcin@python-works.com>
parents: 1397
diff changeset
189 password=TEST_USER_ADMIN_PASS):
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
190 self._logged_username = username
464
cbe777be5b8c some more basic tests
Marcin Kuzminski <marcin@python-works.com>
parents: 463
diff changeset
191 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
192 {'username': username,
402a96fcfa22 Added vcs testsuite for better integration tests + added fetching
Marcin Kuzminski <marcin@python-works.com>
parents: 2254
diff changeset
193 'password': password})
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
194
5346
b75f1d0753d6 privacy: don't tell users what is the reason for a failed login
Andrew Shadura <andrew@shadura.me>
parents: 5334
diff changeset
195 if 'Invalid username or password' in response.body:
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
196 self.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
197
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
198 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
199 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
200
1723
64e91067b996 - refactoring to overcome poor usage of global pylons config
Marcin Kuzminski <marcin@python-works.com>
parents: 1718
diff changeset
201 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
202 return response.session['authuser']
1382
c310e1e1e757 Added CheckSessionFlash into init.
Marcin Kuzminski <marcin@python-works.com>
parents: 1366
diff changeset
203
1712
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
204 def _get_logged_user(self):
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
205 return User.get_by_username(self._logged_username)
cac5109ac3b6 Notification system improvements
Marcin Kuzminski <marcin@python-works.com>
parents: 1707
diff changeset
206
5323
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
207 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
208 cookie = response.session.get('authuser')
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
209 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
210 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
211 user = user and user.username
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
212 self.assertEqual(user, expected_username)
81d8affd08f4 auth: remove username from AuthUser session cookie
Søren Løvborg <kwi@kwi.dk>
parents: 5214
diff changeset
213
4993
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
214 def authentication_token(self):
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
215 return self.app.get(url('authentication_token')).body
0efca3ad8467 tests: provide _authentication_token when POSTing
Mads Kiilerich <madski@unity3d.com>
parents: 4881
diff changeset
216
5409
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
217 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
218 if 'flash' not in response.session:
5333
f5a83106cd30 tests: when checkSessionFlash fails, help debugging the problem by showing the full response
Mads Kiilerich <madski@unity3d.com>
parents: 5323
diff changeset
219 self.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
220 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
221 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
222 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
223 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
224 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
225 pass
4881
afddaa53ab8a tests: fix handling of failing flash assertion ... again
Mads Kiilerich <madski@unity3d.com>
parents: 4775
diff changeset
226 self.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
227 (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
228 ', '.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
229
5bfeada59776 tests: add regex version of checkSessionFlash
Søren Løvborg <sorenl@unity3d.com>
parents: 5346
diff changeset
230 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
231 self.checkSessionFlash(response, regex, skip=skip, _matcher=re.search)