From 238addd9d57dd3290df92fa3b43138d61f8eae7c Mon Sep 17 00:00:00 2001 From: Tom Naccarato <108072398+tnaccarato@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:43:48 +0100 Subject: [PATCH] Update tests to handle timestamp server --- custom_admin/tests.py | 17 +++++++++++++++++ payapp/tests.py | 18 +++++++++++++++++- register/tests.py | 18 +++++++++++++++++- timestamp_server/thrift_server.py | 13 ++++++++++++- webapps.db | Bin 184320 -> 184320 bytes 5 files changed, 63 insertions(+), 3 deletions(-) diff --git a/custom_admin/tests.py b/custom_admin/tests.py index e8c9647..172c08e 100644 --- a/custom_admin/tests.py +++ b/custom_admin/tests.py @@ -1,3 +1,4 @@ +from threading import Thread from unittest.mock import patch from django.contrib.auth.models import User, Group @@ -5,10 +6,26 @@ from django.urls import reverse from payapp.models import Account, Transfer, Request from register.forms import UserForm +from timestamp_server import thrift_server class CustomAdminViewTests(TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Start the Thrift server in a separate thread + cls.thrift_server_thread = Thread(target=thrift_server.start_thrift_server) + cls.thrift_server_thread.daemon = True + cls.thrift_server_thread.start() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + # Stop the Thrift server + thrift_server.stop_thrift_server() + def setUp(self): + super().setUp() self.client = Client() # Create a user and an admin user self.user = User.objects.create_user(username='user', password='userpassword') diff --git a/payapp/tests.py b/payapp/tests.py index 1fedb15..002c2ff 100644 --- a/payapp/tests.py +++ b/payapp/tests.py @@ -1,11 +1,27 @@ +from threading import Thread from django.test import TestCase, Client from django.urls import reverse from django.contrib.auth.models import User, Group from payapp.models import Account, Request, Notification - +from timestamp_server import thrift_server class PayAppViewTests(TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Start the Thrift server in a separate thread + cls.thrift_server_thread = Thread(target=thrift_server.start_thrift_server) + cls.thrift_server_thread.daemon = True + cls.thrift_server_thread.start() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + # Stop the Thrift server + thrift_server.stop_thrift_server() + def setUp(self): + super().setUp() self.client = Client() # Create a user and an admin user self.user = User.objects.create_user(username='user', password='userpassword') diff --git a/register/tests.py b/register/tests.py index b5f6e47..1db0084 100644 --- a/register/tests.py +++ b/register/tests.py @@ -1,15 +1,31 @@ +from threading import Thread from unittest.mock import patch - from django.test import TestCase from django.urls import reverse from django.contrib.auth.models import User, Group from register.forms import UserForm, LoginForm from payapp.utils import convert_currency +from timestamp_server import thrift_server class UserViewTests(TestCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + # Start the Thrift server in a separate thread + cls.thrift_server_thread = Thread(target=thrift_server.start_thrift_server) + cls.thrift_server_thread.daemon = True + cls.thrift_server_thread.start() + + @classmethod + def tearDownClass(cls): + super().tearDownClass() + # Stop the Thrift server + thrift_server.stop_thrift_server() + def setUp(self): + super().setUp() # Setup code for the tests, like creating a user or a group if needed # self.admin_group = Group.objects.create(name='AdminGroup') User.objects.create_user(username='testuser1',first_name='Test',last_name='User' ,password='testpassword123', email='test@example.com') diff --git a/timestamp_server/thrift_server.py b/timestamp_server/thrift_server.py index 346f46e..f44f545 100644 --- a/timestamp_server/thrift_server.py +++ b/timestamp_server/thrift_server.py @@ -8,12 +8,18 @@ from gen_py.timestamp_service import TimestampService +# Global variable to hold the Thrift server instance +server = None +# Global variable to control the server loop +server_running = True class TimestampHandler: def getCurrentTimestamp(self): return datetime.now().strftime("%Y-%m-%d %H:%M:%S") def start_thrift_server(): + global server + global server_running handler = TimestampHandler() processor = TimestampService.Processor(handler) transport = TSocket.TServerSocket(port=9090) @@ -22,7 +28,12 @@ def start_thrift_server(): server = TServer.TSimpleServer(processor, transport, tfactory, pfactory) print("Starting the Thrift server...") - server.serve() + while server_running: + server.handle() + +def stop_thrift_server(): + global server_running + server_running = False if __name__ == '__main__': logging.basicConfig(level=logging.INFO) diff --git a/webapps.db b/webapps.db index 5dd8d03045da601043a7ece3b0188080256c11c7..3f40824d8a15d389d4fddc09f28f5c14811b6331 100644 GIT binary patch delta 846 zcm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