From 306010f6bf859ba664c1d58151142a8cd1cfd3aa Mon Sep 17 00:00:00 2001 From: Arwa Sharif Date: Thu, 5 Feb 2026 18:46:17 -0500 Subject: [PATCH 1/2] refactor(test/ci): implement client fixture and update CI triggers --- .github/workflows/ci.yml | 2 +- server/tests/test_main.py | 29 ++++++++++++++++------------- 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b32ba93..c4d4884 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -3,7 +3,7 @@ name: CI Pipeline # Trigger this workflow on Push to specific branches OR on Pull Requests to main on: push: - branches: ["dev"] + branches: ["**"] pull_request: branches: ["main"] diff --git a/server/tests/test_main.py b/server/tests/test_main.py index 7445c5c..35b5607 100644 --- a/server/tests/test_main.py +++ b/server/tests/test_main.py @@ -17,18 +17,17 @@ class MockDocRef: mock_db_client = mocker.Mock() # Ensure nested calls like db.collection().add() return valid mocks mock_db_client.collection.return_value.add.return_value = (None, MockDocRef()) - mock_db_client.collection.return_value.document.return_value = mocker.Mock() + # mock_db_client.collection.return_value.document.return_value = mocker.Mock() # Patch the External Firebase Calls (so they don't hit the network) mocker.patch("firebase_admin.credentials.Certificate") mocker.patch("firebase_admin.initialize_app") - mock_fs_client = mocker.patch("firebase_admin.firestore.client") - mock_fs_client.return_value = mock_db_client + mocker.patch("firebase_admin.firestore.client", return_value=mock_db_client) - # PATCH THE GLOBAL DB VARIABLE + # Patch the global db variable import main - # We overwrite the 'db' variable inside the 'main' module + # Overwrite the 'db' variable inside the 'main' module main.db = mock_db_client yield @@ -37,9 +36,14 @@ class MockDocRef: main.db = None -# It is safer to use a fixture for the client to ensure fresh state, -# but global is okay for simple tests if the app is stateless. -client = TestClient(app) +@pytest.fixture +def client(): + """ + Creates a fresh client for each test and triggers the lifespan + """ + + with TestClient(app) as c: + yield c # Fixture for sample job data @@ -55,7 +59,7 @@ def sample_job_data(): } -def test_client_is_working(): +def test_client_is_working(client): """ A simple "sanity check" test to make sure the client is working. We don't have a "/" route, so we expect a 404 "Not Found" error. @@ -64,7 +68,7 @@ def test_client_is_working(): assert response.status_code == 404 -def test_chat_endpoint(mocker): +def test_chat_endpoint(client, mocker): """ Tests the /chat endpoint. It uses 'mocker' to fake the Gemini AI call. @@ -72,8 +76,7 @@ def test_chat_endpoint(mocker): """ # --- ARRANGE (Mocks) --- - - # Mock the Gemini Client API call + # Mock Gemini class MockGeminiResponse: text = "This is a fake AI response." @@ -98,7 +101,7 @@ class MockGeminiResponse: mock_gemini_client.return_value.models.generate_content.assert_called_once() -def test_resume_tailor_endpoint(sample_job_data, mocker): +def test_resume_tailor_endpoint(client, sample_job_data, mocker): """ Tests the /resumes endpoint. From 353da291cc48ee8d3e38e5205aca4b522b29ac4b Mon Sep 17 00:00:00 2001 From: Arwa Sharif Date: Thu, 5 Feb 2026 19:01:35 -0500 Subject: [PATCH 2/2] fix(test): mock os.path.exists to satisfy lifespan check --- server/tests/test_main.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/tests/test_main.py b/server/tests/test_main.py index 35b5607..4b81db5 100644 --- a/server/tests/test_main.py +++ b/server/tests/test_main.py @@ -17,7 +17,9 @@ class MockDocRef: mock_db_client = mocker.Mock() # Ensure nested calls like db.collection().add() return valid mocks mock_db_client.collection.return_value.add.return_value = (None, MockDocRef()) - # mock_db_client.collection.return_value.document.return_value = mocker.Mock() + + # Bypass the FileNotFoundError in main.py + mocker.patch("main.os.path.exists", return_value=True) # Patch the External Firebase Calls (so they don't hit the network) mocker.patch("firebase_admin.credentials.Certificate")