Separate db tests from unit tests
This commit is contained in:
parent
04e4bc1f55
commit
f9ac8b1e29
8
dev.py
8
dev.py
|
|
@ -32,12 +32,20 @@ def unit_tests(args):
|
|||
import_run().unit_tests(args)
|
||||
|
||||
|
||||
def database_tests(args):
|
||||
import_run().database_tests(args)
|
||||
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
subparsers = parser.add_subparsers(required=True)
|
||||
run_parser = subparsers.add_parser(
|
||||
'run', help='Run a test instance of locality'
|
||||
)
|
||||
run_parser.set_defaults(func=run)
|
||||
run_parser = subparsers.add_parser(
|
||||
'dbtest', help='Run database tests'
|
||||
)
|
||||
run_parser.set_defaults(func=database_tests)
|
||||
run_parser = subparsers.add_parser(
|
||||
'unittest', help='Run unit tests'
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,7 +8,33 @@ from .postgres_container import PostgresContainer
|
|||
ROOT_DIR = None
|
||||
|
||||
|
||||
def cargo(*args):
|
||||
def cargo(*args, env=None):
|
||||
global ROOT_DIR
|
||||
if env is None:
|
||||
env = {
|
||||
'LOCALITY_DATABASE_URL': "",
|
||||
'LOCALITY_TEST_DATABASE_URL': "",
|
||||
'LOCALITY_STATIC_FILE_PATH': os.path.join(
|
||||
ROOT_DIR,
|
||||
'static'),
|
||||
'LOCALITY_HMAC_SECRET': 'iknf4390-8guvmr3'
|
||||
}
|
||||
env = os.environ.copy() | env
|
||||
cargo_bin = shutil.which('cargo')
|
||||
locality_process = subprocess.Popen(
|
||||
[cargo_bin] + list(args), env=env, cwd=ROOT_DIR
|
||||
)
|
||||
try:
|
||||
while locality_process.poll() is None:
|
||||
time.sleep(0.5)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
if locality_process.poll() is None:
|
||||
locality_process.terminate()
|
||||
|
||||
|
||||
def cargo_with_db(*args):
|
||||
global ROOT_DIR
|
||||
with PostgresContainer() as postgres:
|
||||
locality_env = {
|
||||
|
|
@ -19,26 +45,16 @@ def cargo(*args):
|
|||
'static'),
|
||||
'LOCALITY_HMAC_SECRET': 'iknf4390-8guvmr3'
|
||||
}
|
||||
locality_env = os.environ.copy() | locality_env
|
||||
|
||||
cargo_bin = shutil.which('cargo')
|
||||
locality_process = subprocess.Popen(
|
||||
[cargo_bin, *args], env=locality_env, cwd=ROOT_DIR
|
||||
)
|
||||
|
||||
try:
|
||||
while locality_process.poll() is None:
|
||||
time.sleep(0.5)
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
finally:
|
||||
if locality_process.poll() is None:
|
||||
locality_process.terminate()
|
||||
cargo(env=locality_env, *args)
|
||||
|
||||
|
||||
def run(args):
|
||||
cargo('run')
|
||||
def run(*args):
|
||||
cargo_with_db('run')
|
||||
|
||||
|
||||
def unit_tests(args):
|
||||
def database_tests(*args):
|
||||
cargo_with_db("test", "db::migrations::test", "--", "--include-ignored")
|
||||
|
||||
|
||||
def unit_tests(*args):
|
||||
cargo("test")
|
||||
|
|
|
|||
|
|
@ -220,6 +220,7 @@ mod tests {
|
|||
PostgresDatabase::new(&url).unwrap()
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[test]
|
||||
fn migrations_have_sequential_versions() {
|
||||
for i in 0..MIGRATIONS.len() {
|
||||
|
|
@ -227,6 +228,7 @@ mod tests {
|
|||
}
|
||||
}
|
||||
|
||||
#[ignore]
|
||||
#[tokio::test]
|
||||
async fn migrate_up_and_down_all() {
|
||||
let db = test_db().await;
|
||||
|
|
|
|||
Loading…
Reference in New Issue