diff options
author | Frederick Yin <fkfd@fkfd.me> | 2022-02-03 16:53:10 +0800 |
---|---|---|
committer | Frederick Yin <fkfd@fkfd.me> | 2022-02-03 16:53:10 +0800 |
commit | 0689f7616fd941d8b8795880f0b30676cd85dbf9 (patch) | |
tree | e4e84a97357be30cce97f64bb0efa62b9aacc85b | |
parent | abff246c6af8bf64fce12e5f95fd54e3787d470b (diff) |
Use Process for mock jForm in routine test
-rw-r--r-- | jimbrella/test/test_routine.py | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/jimbrella/test/test_routine.py b/jimbrella/test/test_routine.py index acb1f1e..8d718be 100644 --- a/jimbrella/test/test_routine.py +++ b/jimbrella/test/test_routine.py @@ -1,5 +1,5 @@ from flask import Flask, Response, request -from threading import Thread +from multiprocessing import Process import json import os import shutil @@ -55,23 +55,28 @@ def api(endpoint): return Response(giveback, content_type="application/json") -Thread(target=jform.run, kwargs={"port": 5001}).start() +TEST_DATABASE_PATH = "/tmp/jimbrella.db" +TEST_ADMIN_LOG_PATH = "/tmp/jimbrella.admin.log" + if __name__ == "__main__": logging.info("----- BEGIN ROUTINE TEST -----") + mock_jform = Process(target=jform.run, kwargs={"port": 5001}) + mock_jform.start() """Initialize Database and JForm.""" - TEST_DATABASE_PATH = "/tmp/jimbrella.db" - TEST_ADMIN_LOG_PATH = "/tmp/jimbrella.admin.log" shutil.copyfile(DATABASE_PATH, TEST_DATABASE_PATH) db = Umbrellas(TEST_DATABASE_PATH) takeaway_jform = JForm("takeaway", "http://localhost:5001/takeaway", "/tmp") giveback_jform = JForm("giveback", "http://localhost:5001/giveback", "/tmp") admin = AdminLog(TEST_ADMIN_LOG_PATH) + + """Simulate routine.""" sync_jform(takeaway_jform, giveback_jform, db, admin) process_overdue(db, admin) """Cleanup""" os.remove(takeaway_jform._bookmark_fp) os.remove(giveback_jform._bookmark_fp) + mock_jform.terminate() logging.info("----- END ROUTINE TEST -----") |