-
- Downloads
Sanitize and modernize pytests
Some of these tests were written before some of our convenient
tooling existed. Additionally, some of the tests were not
cooperating with PEP-8 guidelines or isorted.
This commit does the following:
- Replaces all calls to make_(user|session) with
aurweb.db.create(Model, ...).
- Replace calls to session.add(...) + session.commit() with
aurweb.db.create.
- Removes the majority of calls to (session|aurweb.db).delete(...).
- Replaces session.query calls with aurweb.db.query.
- Initializes all mutable globals in pytest fixture setup().
- Makes mutable global declarations more concise:
`var1, var2 = None, None` -> `var1 = var2 = None`
- Defines a warning exclusion for test/test_ssh_pub_key.py.
- Removes the aurweb.testing.models module.
- Removes some useless pytest.fixture yielding.
As of this commit, developers should use the following guidelines
when writing tests:
- Always use aurweb.db.(create|delete|query) for database
operations, where possible.
- Always define mutable globals in the style: `var1 = var2 = None`.
- `yield` the most dependent model in pytest setup fixture **iff**
you must delete records after test runs to maintain database
integrity. Example: test/test_account_type.py.
This all makes the test code look and behave much cleaner.
Previously, aurweb.testing.setup_test_db was buggy and leaving
objects around in SQLAlchemy's IdentityMap.
Signed-off-by:
Kevin Morris <kevr@0cost.org>
Showing
- aurweb/testing/models.py 0 additions, 25 deletionsaurweb/testing/models.py
- setup.cfg 18 additions, 10 deletionssetup.cfg
- test/test_accepted_term.py 2 additions, 9 deletionstest/test_accepted_term.py
- test/test_account_type.py 9 additions, 19 deletionstest/test_account_type.py
- test/test_accounts_routes.py 6 additions, 7 deletionstest/test_accounts_routes.py
- test/test_auth.py 11 additions, 18 deletionstest/test_auth.py
- test/test_auth_routes.py 9 additions, 8 deletionstest/test_auth_routes.py
- test/test_ban.py 6 additions, 10 deletionstest/test_ban.py
- test/test_exceptions.py 29 additions, 32 deletionstest/test_exceptions.py
- test/test_group.py 7 additions, 3 deletionstest/test_group.py
- test/test_initdb.py 3 additions, 2 deletionstest/test_initdb.py
- test/test_package.py 0 additions, 2 deletionstest/test_package.py
- test/test_package_base.py 4 additions, 5 deletionstest/test_package_base.py
- test/test_package_keyword.py 5 additions, 7 deletionstest/test_package_keyword.py
- test/test_routes.py 9 additions, 8 deletionstest/test_routes.py
- test/test_session.py 15 additions, 16 deletionstest/test_session.py
- test/test_ssh_pub_key.py 10 additions, 19 deletionstest/test_ssh_pub_key.py
- test/test_term.py 3 additions, 3 deletionstest/test_term.py
- test/test_user.py 14 additions, 36 deletionstest/test_user.py
aurweb/testing/models.py
deleted
100644 → 0
Please register or sign in to comment