|
|
Thomas De Schampheleire
|
56de50d57ff0
|
6 years ago
|
|
pytest: fix register_assert_rewrite call
Since a while, the test suite shows following warning:
kallithea/tests/__init__.py:29 /home/tdescham/repo/contrib/kallithea/kallithea-review/kallithea/tests/__init__.py:29: PytestAssertRewriteWarning: Module already imported so cannot be rewritten: kallithea.tests pytest.register_assert_rewrite('kallithea.tests')
The problem can be fixed by moving the register_assert_rewrite call from kallithea/tests/__init__.py to the root-level conftest.py, outside of the 'kallithea' module.
|
|
|
Mads Kiilerich
|
0a277465fddf
|
6 years ago
|
|
|
|
|
Thomas De Schampheleire
|
0996e43e89c7
|
7 years ago
|
|
tests: fix assert rewriting in non-test modules like api_base.py pytest rewrites assert statements in tests so it can print details about the values involved when the assert fails. Since pytest 3.0.0, this was no longer the case for files/modules that are not discovered as test modules, i.e. starting with 'test_'. Examples are: api/api_base.py models/common.py base.py fixture.py Commit 790aeeddcab598d2aacbbecf86830b608ca8b32b attempted to fix that problem, but seems incorrect. A trailing dot should not be there.
|
|
|
Thomas De Schampheleire
|
790aeeddcab5
|
9 years ago
|
|
tests: fix assertion rewriting in some tests with pytest-3.0.0+ Since pytest 3.0.0, asserts present in modules that are not directly seen by pytest as 'test modules', are no longer rewritten to have improved reporting, unless they are explicitly marked as up-for-rewriting. Rationale from pytest upstream: However since we do not want to test different bytecode then you will run in production this hook only re-writes test modules themselves as well as any modules which are part of plugins. Any other imported module will not be re-written and normal assertion behaviour will happen. This is e.g. the case for asserts in files like kallithea/tests/api/api_base.py and kallithea/tests/models/common.py. See http://doc.pytest.org/en/latest/changelog.html#id13http://doc.pytest.org/en/latest/writing_plugins.html#assertion-rewritingThis commit registers all modules below kallithea.tests for assert rewriting, but note that asserts in kallithea/tests/__init__.py itself are not rewritten as kallithea.tests is already imported when the register statement is encountered. Moving the register statement to kallithea/__init__.py would fix that, but even then asserts in kallithea/tests/__init__.py seem not to be rewritten (let alone the issue that we do not want a pytest dependency enforced in kallithea/__init__.py which is also used in production). Moving the code from kallithea/tests/__init__.py to a proper module, as suggested by Mads Kiilerich, solves that problem.
|
|
|
Thomas De Schampheleire
|
8d98924c58b1
|
9 years ago
|
|
tests: add as little code as possible in __init__.py
kallithea/tests/__init__.py contained quite a lot of code, including the test base class TestController. This in itself may be considered bad practice.
Specifically, this poses a problem when using pytest 3.0+, in which asserts in some files are not automatically rewritten to give improved assert output. That problem can be fixed by explicitly registering such files for assertion rewriting, but that register call should be executed _before_ said files are imported. I.e. if the register call is in kallithea/tests/__init__.py, assert calls in __init__.py itself can not be rewritten.
Since the TestController base class does effectively contain asserts, and we do not want to execute the register call from somewhere outside the kallithea/tests directory, we need to move the TestController class to another file (kallithea/tests/base.py) so we can have a register call in __init__.py before loading base.py.
While not strictly necessary to fix the mentioned pytest problem, we take the opportunity to fully clean __init__.py and move everything to the new kallithea/tests/base.py. While doing so, unnecessary imports are removed, and imports are ordered alphabetically. Explicit imports of symbols from modules that were already imported as a whole, are removed in favor of fully qualifying the references (e.g. tempfile._RandomNameSequence).
|
|
|
Thomas De Schampheleire
|
5eec79420ce3
|
9 years ago
|
|
Turbogears2 migration: remove some references to Pylons in comments
In order to minimize the diff of the actual Turbogears2 migration, this commit already removes certain unnecessary references to Pylons from the Kallithea source base. Places where the reference to Pylons is important are still kept for now, as well as references in kallithea/config where many changes are made for Turbogears2 anyway.
|
|
|
Thomas De Schampheleire
|
ee88c8c07111
|
9 years ago
|
|
tests: remove sleep hack to expire sql_cache_short
A number of tests sleep for 1.5 or 2 seconds to let the beaker cache 'sql_cache_short' expire. This cache is for example used for IP permissions; tests changing such permissions need to make sure they take effect before proceeding, especially when exiting from the test.
A much faster method is to effectively invalidating the caches. Because it is difficult and fragile to only invalidate the relevant cache -- difficult to know exactly which cache needs to be invalidated, fragile because the string indicating the cache line is not very nice and might change in the future (in the case of IP permissions for the default user, the cache is referred to with something like "get_user_ips_default_Mapper|UserIpMap|users". This string changes when the permissions are for a different user.
Clearing all caches shouldn't be a problem in a test context.
|
|
|
domruf
|
b313d735d9c8
|
9 years ago
|
|
|
|
|
domruf
|
77bd10c410ed
|
9 years ago
|
|
tests: fix 'a foreign key constraint fails' when running tests on mysql
UserNotification needs to be deleted before Notification because there are foreign key references in UserNotification to Notification.
|
|
|
Mads Kiilerich
|
7d0052c68a6f
|
9 years ago
|
|
|
|
|
Mads Kiilerich
|
96779dba8b01
|
10 years ago
|
|
tests: remove reference to removed kallithea/tests/parameterized.py The file was removed in 66c40720e7b2. I guess tests still passed because it still found the .pyc file.
|
|
|
Thomas De Schampheleire
|
7f2aa3ec2931
|
10 years ago
|
|
pytest migration: rename TestControllerPytest back to TestController
The name TestControllerPytest was introduced to allow a temporary situation where nose/unittest and pytest-based tests could coexist. This situation is now over, so the base test class can be renamed again.
|
|
|
Thomas De Schampheleire
|
cbeed250b599
|
10 years ago
|
|
pytest migration: move init_stack under TestControllerPytest
Avoid top-level methods if they could be placed under classes. The init_stack method is only used from TestControllerPytest so it makes sense to scope it under that class.
|
|
|
Thomas De Schampheleire
|
fed129fb8533
|
10 years ago
|
|
pytest migration: backout declassification of remove_all_notifications In order to accomodate both nose/unittest and pytest at the same time, method remove_all_notifications has been extracted from BaseTestCase in commit 37d713674f63. Now that nose/unittest is no longer used, we can backout this change again.
|
|
|
Thomas De Schampheleire
|
acfd700770cc
|
10 years ago
|
|
pytest migration: merge TestControllerPytest with BaseTestController
There is no need anymore for a separate BaseTestController class. Simplify the code by removing it.
|
|
|
Thomas De Schampheleire
|
66c40720e7b2
|
10 years ago
|
|
pytest migration: remove custom 'parameterized' implementation
Since all tests have been converted to pure pytest style, we can get rid of the custom 'parameterized' helper, and use pytest's parametrize instead.
|
|
|
Thomas De Schampheleire
|
68ac6055d4b2
|
10 years ago
|
|
pytest migration: remove original TestController and BaseTestCase
Since all tests have been migrated to TestControllerPytest, we can remove these classes.
|
|
|
Thomas De Schampheleire
|
062b4418ca9d
|
10 years ago
|
|
|
|
|
Thomas De Schampheleire
|
151459ea3bd1
|
10 years ago
|
|
pytest migration: __init__: switch to standard assert statements
Use unittest2pytest to replace unittest-style assert statements (e.g. assertEqual) with standard Python assert statements to benefit from pytest's improved reporting on assert failures.
The conversion by unittest2pytest was correct.
|
|
|
Thomas De Schampheleire
|
ab36d9a31a2d
|
10 years ago
|
|
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.
|
|
|
Thomas De Schampheleire
|
91b89797a775
|
10 years ago
|
|
pytest migration: add temporary assertRaises wrapper
Similar to the other temporary unittest-assert wrappers, add the missing assertRaises and forward to pytest.raises.
|
|
|
domruf
|
1a7611b9730e
|
10 years ago
|
|
|
|
|
domruf
|
1883a4e4c390
|
10 years ago
|
|
|
|
|
Thomas De Schampheleire
|
6b67bbc1652e
|
10 years ago
|
|
pytest migration: make pytest's parametrize functionality available
To provide parameterized tests, a custom implementation is currently provided at kallithea/tests/parameterized.py because nose does not provide that out-of-the-box. pytest, on the other hand, does have a built-in 'parametrize' (note: different spelling) functionality. Therefore, once all tests have been converted to pytest, we can get rid of the custom 'parameterized' implementation. Also, the existing 'parameterized' implementation does not seem to work under pytest-style tests.
This commit makes pytest's 'parametrize' decorator available alongside the custom 'parameterized' decorator. The names are confusing but it is the intention to kill the original 'parameterized' soon.
|
|
|
Thomas De Schampheleire
|
877bcf22bf71
|
10 years ago
|
|
pytest migration: introduce TestControllerPytest
In order to allow tests to benefit from pytest specific functionality, like fixtures, they can no longer derive from unittest.TestCase. What's more, while they can derive from any user-defined class, none of the classes involved (the test class itself nor any of the base classes) can have an __init__ method.
Converting all tests from unittest-style to pytest-style in one commit is not realistic. Hence, a more gradual approach is needed.
Most existing test classes derive from TestController, which in turn derives from BaseTestCase, which derives from unittest.TestCase. Some test classes derive directly from BaseTestCase. Supporting both unittest-style and pytest-style from TestController directly is not possible: pytest-style _cannot_ and unittest-style _must_ derive from unittest.TestCase. Thus, in any case, an extra level in the class hierarchy is needed (TestController deriving from Foo and from unittest.TestCase; pytest-style test classes would then directly derive from Foo).
The requirement that pytest-style test classes cannot have an __init__ method anywhere in the class hierarchy imposes another restriction that makes it difficult to support both unittest-style and pytest-style test classes with one class. Any init code needs to be placed in another method than __init__ and be called explicitly when the test class is initialized. For unittest-style test classes this would naturally be done with a setupClass method, but several test classes already use that. Thus, there would need to be explicit 'super' calls from the test classes. This is technically possible but not very nice.
A more transparent approach (from the existing test classes point of view), implemented by this patch, works as follows: - the implementation of the existing TestController class is now put under a new class BaseTestController. To accomodate pytest, the __init__ method is renamed init. - contrary to the original TestController, BaseTestController does not derive from BaseTestCase (and neither from unittest.TestCase). Instead, the 'new' TestController derives both from BaseTestCase, which is untouched, and from BaseTestController. - TestController has an __init__ method that calls the base classes' __init__ methods and the renamed 'init' method of BaseTestController. - a new class TestControllerPytest is introduced that derives from BaseTestController but not from BaseTestCase. It uses a pytest fixture to automatically call the setup functionality previously provided by BaseTestCase and also calls 'init' on BaseTestController. This means a little code duplication but is hard to avoid.
The app setup fixture is scoped on the test method, which means that the app is recreated for every test (unlike for the unittest-style tests where the app is created per test class). This has the advantage of detecting current inter-test dependencies and thus improve the health of our test suite. This in turn is one step closer to allowing parallel test execution.
The unittest-style assert methods (assertEqual, assertIn, ...) do not exist for pytest-style tests. To avoid having to change all existing test cases upfront, provide transitional implementations of these methods. The conversion of the unittest asserts to the pytest/python asserts can happen gradually over time.
|
|
|
Thomas De Schampheleire
|
37d713674f63
|
10 years ago
|
|
tests: move remove_all_notifications outside of BaseTestCase
In preparation of allowing real pytest-style test cases (instead of unittest-style ones), some reorganization is needed in the base test classes, for one because we want a transition period where pytest and unittest style test cases can live alongside each other, and secondly because the pytest style test classes cannot have an __init__ method.
The BaseTestCase class will not be reused for the pytest test cases, but the remove_all_notifications method will. To avoid having to duplicate it, and since it does not use any resources from the class (self), move the method out of the BaseTestCase class to top-level, and export it in kallithea.tests.
|
|
|
Thomas De Schampheleire
|
ff1bd1b60736
|
10 years ago
|
|
|
|
|
Thomas De Schampheleire
|
b755464eff8d
|
10 years ago
|
|
pytest migration: use pytest test skipping instead of nose's While the nose test skipping still worked, we want to remove all remnants of nose, so switch to the pytest equivalent. Note: due to a bug in pytest-sugar (reported at [1]) the skipped tests are not shown explicitly when using the 'skipif' approach, while they were with the nose approach. Since pytest-sugar is not enabled yet in setup.py, this is not deemed a problem. [1] https://github.com/Frozenball/pytest-sugar/issues/75
|
|
|
Thomas De Schampheleire
|
2d2decce586f
|
10 years ago
|
|
pytest migration: update documentation
Update documentation and comments to refer to pytest instead of nose.
|
|
|
Mads Kiilerich
|
bd4840ad72d3
|
10 years ago
|
|
tests: more consistently use unicode where unicode is expected
Nothing but extra u annotation to turn str constants into unicode.
This has been verified by hacking sqlalchemy to fail if wrong string types are passed.
|
|
|
Søren Løvborg
|
23a86f1c33a1
|
10 years ago
|
|
auth: note that we never emit authuser "cookies" for the default user
The only place where we set "authuser" in the session is in log_in_user, which is called only by the internal auth system and by auth plugins. The internal auth system cannot log a user in as the default user, because the default user doesn't have a password (and cannot have a password assigned). Auth plugins cannot log a user in as the default user, because the user doesn't have the right extern_type. As such, it's a bug if log_in_user is ever called with the default user (which this commit documents with an assert).
This realization makes the is_authenticated field of the authuser cookie redundant, as it's always True. It also emphasizes that is_default_user and is_authenticated are mutually exclusive.
|
|
|
Søren Løvborg
|
12b47803189f
|
10 years ago
|
|
cleanup: use example.com for tests and examples
example.com is explicitly reserved for this purpose. Using that means we won't accidentally hammer a real server or real email address if an example value escapes into the wild, e.g. in an automated test.
The domain "kallithea.example.com" has been used throughout to refer to the example Kallithea server.
|
|
|
branko
|
6db421a8cd9a
|
10 years ago
|
|
tests: fix generation of a unique temporary directory path for VCS testing
The old code was complicated and failed if directories were created quickly in succession.
Re-implement vcs get_new_dir without get_normalized_path and VCSTestError.
The top level get_new_dir was unused.
|
|
|
Søren Løvborg
|
5bfeada59776
|
10 years ago
|
|
tests: add regex version of checkSessionFlash
This is needed to match more complex messages.
|
|
|
Andrew Shadura
|
b75f1d0753d6
|
11 years ago
|
|
privacy: don't tell users what is the reason for a failed login
Makes it harder for strangers to probe the instance for presence of certain users. This can make it harder to break in, as it is now harder to tell is a username or a password are wrong, so bruteforcing should probably take a bit longer if you don't know what exactly are you doing.
|
|
|
Mads Kiilerich
|
d8918bb94b80
|
10 years ago
|
|
|
|
|
Mads Kiilerich
|
f5a83106cd30
|
10 years ago
|
|
|
|
|
Søren Løvborg
|
81d8affd08f4
|
10 years ago
|
|
auth: remove username from AuthUser session cookie
There's no reason to store the username when we store the user ID. We have load the user from database anyway under all circumstances, to verify e.g. that the user is (still) active.
This does not impact application code, but does impact a number of test cases which explicitly checks the username stored in the session.
|
|
|
Søren Løvborg
|
9b2c5e8b37ea
|
10 years ago
|
|
notification tests: delete notifications before (not after) tests
Don't clean notifications (and changeset comments) *after* the test, but *before* the test. Other unit tests don't care if they leave notifications in the database, and neither should these. Rather, they should ensure their *own* preconditions before testing.
Admittedly, currently only one test leaves a notification in the database, but more could come along at any time (and why worry?): TestPullrequestsController.test_create_with_existing_reviewer
|
|
|
Thomas De Schampheleire
|
414142964b62
|
10 years ago
|
|
|
|
|
Marc Abramowitz
|
cf8c3cf122a0
|
11 years ago
|
|
tests: Make `parameterized` stuff work with both pytest and nose
- Use `nose.tools.nottest` if `nose` is available - Use `pytest.mark.skipIf` if `pytest` is available - Rename from `nose_parametrized` to `parameterized` since it's no longer nose-specific
|
|
|
Mads Kiilerich
|
0efca3ad8467
|
11 years ago
|
|
tests: provide _authentication_token when POSTing
So far not used, just preparing for the the time when the actual checking is introduced ...
This change is very verbose. self.app.post should perhaps just at this value automagically ...
|
|
|
Mads Kiilerich
|
afddaa53ab8a
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
787f30a1a996
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
0f96804480c3
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
5225ed43bbb3
|
11 years ago
|
|
|
|
|
Mads Kiilerich
|
d51a6f5e57d1
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
703d3208424c
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
d208416c84c6
|
11 years ago
|
|
|
|
|
Bradley M. Kuhn
|
d1addaf7a91e
|
11 years ago
|
|
Second step in two-part process to rename directories. This is the actual directory rename.
|