From 339bb01fb7b30c098180032efbfba558d8d3258f Mon Sep 17 00:00:00 2001 From: xuwenyihust Date: Mon, 19 Aug 2024 15:50:04 +0800 Subject: [PATCH] Add test case for getting a Spark app by ID in test_spark_app_service.py --- .../tests/services/test_spark_app_service.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/server/tests/services/test_spark_app_service.py b/server/tests/services/test_spark_app_service.py index b8bd30e..0ac905e 100644 --- a/server/tests/services/test_spark_app_service.py +++ b/server/tests/services/test_spark_app_service.py @@ -23,6 +23,29 @@ def tearDown(self): db.session.remove() db.drop_all() + def test_get_spark_by_id(self): + with self.app.app_context(): + # Create User + user_0 = UserModel(name='testuser0', eemail='testuser0@example.com') + password = 'test_password' + user_0.set_password(password) + db.session.add(user_0) + db.session.commit() + g.user = user_0 + + # Create notebook + notebook_0 = NotebookModel(name='Test Notebook', path='/path/to/notebook', user_id=user_0.id) + db.session.add(notebook_0) + db.session.commit() + + # Create spark app + spark_app_0 = SparkAppModel(spark_app_id='1234', notebook_id=notebook_0.id, user_id=user_0.id) + db.session.add(spark_app_0) + + # Get spark app by id + spark_app_1 = SparkApp.get_spark_app_by_id(spark_app_id='1234') + self.assertEqual(spark_app_1.spark_app_id, '1234') + def test_create_spark_app(self): with self.app.app_context(): user_0 = UserModel(name='testuser0', email='testuser0@example.com') @@ -46,3 +69,4 @@ def test_create_spark_app(self): spark_app = SparkAppModel.query.filter_by(spark_app_id='1234').first() self.assertIsNotNone(spark_app) +