Improve tests
- Always default to 'python' if PYTHON env. var. unset. - Enable SQLAlchemy warnings in daemon tests. - Commit changes in schema initialisation script.
This commit is contained in:
parent
4977185ba1
commit
b6155ade96
3 changed files with 23 additions and 18 deletions
|
@ -23,15 +23,19 @@ import subprocess
|
|||
import os
|
||||
import time
|
||||
import unittest
|
||||
from typing import Dict
|
||||
|
||||
|
||||
def _spawn(cmd):
|
||||
def _spawn(cmd, *, env_add: Dict = None):
|
||||
env_dict = {
|
||||
"PATH": os.getenv("PATH"),
|
||||
"PYTHONPATH": os.getcwd(),
|
||||
"LANG": 'en_US.UTF-8',
|
||||
"LACRE_CONFIG": "test/lacre-daemon.conf"
|
||||
}
|
||||
if env_add:
|
||||
env_dict.update(env_add)
|
||||
|
||||
logging.debug(f"Spawning command: {cmd} with environment: {env_dict!r}")
|
||||
return subprocess.Popen(cmd,
|
||||
stdin=None,
|
||||
|
@ -45,7 +49,8 @@ def _interrupt(proc):
|
|||
|
||||
def _send(host, port, mail_from, mail_to, message):
|
||||
logging.debug(f"Sending message to {host}:{port}")
|
||||
p = _spawn([os.getenv("PYTHON") or "python",
|
||||
python = os.getenv("PYTHON") or "python"
|
||||
p = _spawn([python,
|
||||
"test/utils/sendmail.py",
|
||||
"-f", mail_from,
|
||||
"-t", mail_to,
|
||||
|
@ -83,7 +88,7 @@ class AdvancedMailFilterE2ETest(unittest.TestCase):
|
|||
python = os.getenv("PYTHON", "python")
|
||||
|
||||
logging.info('Starting the server...')
|
||||
cls.server = _spawn([python, '-m', 'lacre.daemon'])
|
||||
cls.server = _spawn([python, '-m', 'lacre.daemon'], env_add={'SQLALCHEMY_WARN_20': '1'})
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls):
|
||||
|
|
|
@ -101,7 +101,7 @@ class SimpleMailFilterE2ETest(unittest.TestCase):
|
|||
cls._e2e_config_path = os.path.join(os.getcwd(), CONFIG_FILE)
|
||||
|
||||
# This environment variable is set in Makefile.
|
||||
cls._python_path = os.getenv('PYTHON', 'python3')
|
||||
cls._python_path = os.getenv('PYTHON', 'python')
|
||||
|
||||
_write_test_config(cls._e2e_config_path,
|
||||
port = cls._e2e_config.get("relay", "port"),
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import sys
|
||||
import sqlalchemy
|
||||
from sqlalchemy.sql import insert
|
||||
|
||||
def define_db_schema():
|
||||
meta = sqlalchemy.MetaData()
|
||||
|
@ -25,17 +24,16 @@ if len(sys.argv) != 2:
|
|||
|
||||
(meta, lacre_keys, identities) = define_db_schema()
|
||||
|
||||
dbname = sys.argv[1]
|
||||
test_db = sqlalchemy.create_engine(f"sqlite:///{dbname}")
|
||||
test_db = sqlalchemy.create_engine(sqlalchemy.URL.create('sqlite', database=sys.argv[1]))
|
||||
|
||||
# Initialise the schema
|
||||
meta.create_all(test_db)
|
||||
|
||||
conn = test_db.connect()
|
||||
with test_db.connect() as conn:
|
||||
|
||||
# Populate the database with dummy data
|
||||
conn.execute(lacre_keys.insert(), [
|
||||
{"id": 1, "email": "alice@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
||||
# Populate the database with dummy data
|
||||
conn.execute(lacre_keys.insert(), [
|
||||
{"id": 1, "email": "alice@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
||||
\n\
|
||||
mQGNBGDYY5oBDAC+HAVjA05jsIpHfQ2KQ9m2olo1Qnlk+dkjD+Gagxj1ACezyiGL\n\
|
||||
cfZfoE/MJYLCH9yPcX1fUIAPwdAyfJKlvkVcz+MhEpgl3aP3NM2L2unSx3v9ZFwT\n\
|
||||
|
@ -77,7 +75,7 @@ pw==\n\
|
|||
=Tbwz\n\
|
||||
-----END PGP PUBLIC KEY BLOCK-----\
|
||||
", "status": 0, "confirm": "", "time": None},
|
||||
{"id": 2, "email": "bob@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
||||
{"id": 2, "email": "bob@disposlab", "publickey": "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\
|
||||
\n\
|
||||
mDMEYdTFkRYJKwYBBAHaRw8BAQdA2tgdP1pMt3cv3XAW7ov5AFn74mMZvyTksp9Q\n\
|
||||
eO1PkpK0GkJvYiBGb29iYXIgPGJvYkBkaXNwb3NsYWI+iJYEExYIAD4WIQQZz0tH\n\
|
||||
|
@ -91,11 +89,13 @@ OjjB6xRD0Q2FN+alsNGCtdutAs18AZ5l33RMzws=\n\
|
|||
=wWoq\n\
|
||||
-----END PGP PUBLIC KEY BLOCK-----\
|
||||
", "status": 1, "confirm": "", "time": None},
|
||||
{"id": 3, "email": "cecil@lacre.io", "publickey": "RUBBISH", "status": 2, "confirm": "", "time": None}
|
||||
{"id": 3, "email": "cecil@lacre.io", "publickey": "RUBBISH", "status": 2, "confirm": "", "time": None}
|
||||
])
|
||||
|
||||
conn.execute(identities.insert(), [
|
||||
{'fingerprint': '1CD245308F0963D038E88357973CF4D9387C44D7', 'email': 'alice@disposlab'},
|
||||
{'fingerprint': '19CF4B47ECC9C47AFA84D4BD96F39FDA0E31BB67', 'email': 'bob@disposlab'},
|
||||
{'fingerprint': '530B1BB2D0CC7971648198BBA4774E507D3AF5BC', 'email': 'evan@disposlab'}
|
||||
])
|
||||
conn.execute(identities.insert(), [
|
||||
{'fingerprint': '1CD245308F0963D038E88357973CF4D9387C44D7', 'email': 'alice@disposlab'},
|
||||
{'fingerprint': '19CF4B47ECC9C47AFA84D4BD96F39FDA0E31BB67', 'email': 'bob@disposlab'},
|
||||
{'fingerprint': '530B1BB2D0CC7971648198BBA4774E507D3AF5BC', 'email': 'evan@disposlab'}
|
||||
])
|
||||
|
||||
conn.commit()
|
||||
|
|
Loading…
Reference in a new issue