mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
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>
This commit is contained in:
parent
f2121fb833
commit
38dc2bb99d
19 changed files with 160 additions and 239 deletions
|
@ -1,102 +1,99 @@
|
|||
from aurweb.exceptions import (AlreadyVotedException, AurwebException, BannedException, BrokenUpdateHookException,
|
||||
InvalidArgumentsException, InvalidCommentException, InvalidPackageBaseException,
|
||||
InvalidReasonException, InvalidRepositoryNameException, InvalidUserException,
|
||||
MaintenanceException, NotVotedException, PackageBaseExistsException, PermissionDeniedException)
|
||||
from aurweb import exceptions
|
||||
|
||||
|
||||
def test_aurweb_exception():
|
||||
try:
|
||||
raise AurwebException("test")
|
||||
except AurwebException as exc:
|
||||
raise exceptions.AurwebException("test")
|
||||
except exceptions.AurwebException as exc:
|
||||
assert str(exc) == "test"
|
||||
|
||||
|
||||
def test_maintenance_exception():
|
||||
try:
|
||||
raise MaintenanceException("test")
|
||||
except MaintenanceException as exc:
|
||||
raise exceptions.MaintenanceException("test")
|
||||
except exceptions.MaintenanceException as exc:
|
||||
assert str(exc) == "test"
|
||||
|
||||
|
||||
def test_banned_exception():
|
||||
try:
|
||||
raise BannedException("test")
|
||||
except BannedException as exc:
|
||||
raise exceptions.BannedException("test")
|
||||
except exceptions.BannedException as exc:
|
||||
assert str(exc) == "test"
|
||||
|
||||
|
||||
def test_already_voted_exception():
|
||||
try:
|
||||
raise AlreadyVotedException("test")
|
||||
except AlreadyVotedException as exc:
|
||||
raise exceptions.AlreadyVotedException("test")
|
||||
except exceptions.AlreadyVotedException as exc:
|
||||
assert str(exc) == "already voted for package base: test"
|
||||
|
||||
|
||||
def test_broken_update_hook_exception():
|
||||
try:
|
||||
raise BrokenUpdateHookException("test")
|
||||
except BrokenUpdateHookException as exc:
|
||||
raise exceptions.BrokenUpdateHookException("test")
|
||||
except exceptions.BrokenUpdateHookException as exc:
|
||||
assert str(exc) == "broken update hook: test"
|
||||
|
||||
|
||||
def test_invalid_arguments_exception():
|
||||
try:
|
||||
raise InvalidArgumentsException("test")
|
||||
except InvalidArgumentsException as exc:
|
||||
raise exceptions.InvalidArgumentsException("test")
|
||||
except exceptions.InvalidArgumentsException as exc:
|
||||
assert str(exc) == "test"
|
||||
|
||||
|
||||
def test_invalid_packagebase_exception():
|
||||
try:
|
||||
raise InvalidPackageBaseException("test")
|
||||
except InvalidPackageBaseException as exc:
|
||||
raise exceptions.InvalidPackageBaseException("test")
|
||||
except exceptions.InvalidPackageBaseException as exc:
|
||||
assert str(exc) == "package base not found: test"
|
||||
|
||||
|
||||
def test_invalid_comment_exception():
|
||||
try:
|
||||
raise InvalidCommentException("test")
|
||||
except InvalidCommentException as exc:
|
||||
raise exceptions.InvalidCommentException("test")
|
||||
except exceptions.InvalidCommentException as exc:
|
||||
assert str(exc) == "comment is too short: test"
|
||||
|
||||
|
||||
def test_invalid_reason_exception():
|
||||
try:
|
||||
raise InvalidReasonException("test")
|
||||
except InvalidReasonException as exc:
|
||||
raise exceptions.InvalidReasonException("test")
|
||||
except exceptions.InvalidReasonException as exc:
|
||||
assert str(exc) == "invalid reason: test"
|
||||
|
||||
|
||||
def test_invalid_user_exception():
|
||||
try:
|
||||
raise InvalidUserException("test")
|
||||
except InvalidUserException as exc:
|
||||
raise exceptions.InvalidUserException("test")
|
||||
except exceptions.InvalidUserException as exc:
|
||||
assert str(exc) == "unknown user: test"
|
||||
|
||||
|
||||
def test_not_voted_exception():
|
||||
try:
|
||||
raise NotVotedException("test")
|
||||
except NotVotedException as exc:
|
||||
raise exceptions.NotVotedException("test")
|
||||
except exceptions.NotVotedException as exc:
|
||||
assert str(exc) == "missing vote for package base: test"
|
||||
|
||||
|
||||
def test_packagebase_exists_exception():
|
||||
try:
|
||||
raise PackageBaseExistsException("test")
|
||||
except PackageBaseExistsException as exc:
|
||||
raise exceptions.PackageBaseExistsException("test")
|
||||
except exceptions.PackageBaseExistsException as exc:
|
||||
assert str(exc) == "package base already exists: test"
|
||||
|
||||
|
||||
def test_permission_denied_exception():
|
||||
try:
|
||||
raise PermissionDeniedException("test")
|
||||
except PermissionDeniedException as exc:
|
||||
raise exceptions.PermissionDeniedException("test")
|
||||
except exceptions.PermissionDeniedException as exc:
|
||||
assert str(exc) == "permission denied: test"
|
||||
|
||||
|
||||
def test_repository_name_exception():
|
||||
try:
|
||||
raise InvalidRepositoryNameException("test")
|
||||
except InvalidRepositoryNameException as exc:
|
||||
raise exceptions.InvalidRepositoryNameException("test")
|
||||
except exceptions.InvalidRepositoryNameException as exc:
|
||||
assert str(exc) == "invalid repository name: test"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue