From 0689f7616fd941d8b8795880f0b30676cd85dbf9 Mon Sep 17 00:00:00 2001 From: Frederick Yin Date: Thu, 3 Feb 2022 16:53:10 +0800 Subject: Use Process for mock jForm in routine test --- jimbrella/test/test_routine.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'jimbrella') 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 -----") -- cgit v1.2.3