Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kristian Klausen
aurweb
Commits
fdc5c7ca
Commit
fdc5c7ca
authored
Mar 29, 2021
by
Kevin Morris
Browse files
add aurweb.testing, a module with testing utilities
Signed-off-by:
Kevin Morris
<
kevr@0cost.org
>
parent
8e7f1a03
Changes
1
Hide whitespace changes
Inline
Side-by-side
aurweb/testing.py
0 → 100644
View file @
fdc5c7ca
from
aurweb.db
import
get_engine
def
setup_test_db
(
*
args
):
""" This function is to be used to setup a test database before
using it. It takes a variable number of table strings, and for
each table in that set of table strings, it deletes all records.
The primary goal of this method is to configure empty tables
that tests can use from scratch. This means that tests using
this function should make sure they do not depend on external
records and keep their logic self-contained.
Generally used inside of pytest fixtures, this function
can be used anywhere, but keep in mind its functionality when
doing so.
Examples:
setup_test_db("Users", "Sessions")
test_tables = ["Users", "Sessions"];
setup_test_db(*test_tables)
"""
engine
=
get_engine
()
conn
=
engine
.
connect
()
tables
=
list
(
args
)
for
table
in
tables
:
conn
.
execute
(
f
"DELETE FROM
{
table
}
"
)
conn
.
close
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment