| """ |
| Test script for the document updater module. |
| This is a mock test since we don't want to make actual API calls during testing. |
| """ |
|
|
| import os |
| import sys |
| import docx |
| from unittest import mock |
|
|
| |
| sys.path.append('/home/ubuntu/cv_tailoring_project') |
|
|
| from src.updaters.document_updater import DocumentUpdater |
| from src.utils.openai_integration import OpenAIIntegration |
|
|
| def test_document_updater(): |
| """Test the document updater module with mock responses.""" |
| print("Testing document updater module...") |
| |
| |
| cv_path = '/home/ubuntu/cv_tailoring_project/data/Imon Hosen - Resume_Template_ATS.docx' |
| cover_letter_path = '/home/ubuntu/cv_tailoring_project/data/Cover Letter_Imon .docx' |
| |
| |
| mock_openai = mock.MagicMock(spec=OpenAIIntegration) |
| |
| |
| mock_openai.analyze_job_description.return_value = { |
| "raw_response": """ |
| { |
| "profile_summary": "Information Engineering student at HAW Hamburg with experience in data analysis and project coordination, seeking a part-time working student role in IT Project Management.", |
| "skills": ["Project coordination", "MS Office", "Data analysis", "Documentation"], |
| "experience_highlights": ["Assisted in project tracking", "Created documentation", "Analyzed data"], |
| "keywords_to_emphasize": ["project management", "coordination", "documentation"] |
| } |
| """ |
| } |
| |
| mock_openai.tailor_cover_letter.return_value = "This is a tailored cover letter body text for testing purposes." |
| |
| |
| document_updater = DocumentUpdater(cv_path, cover_letter_path, mock_openai) |
| |
| |
| job_description = "This is a test job description for an IT Project Management position." |
| analysis = document_updater.analyze_job_description(job_description) |
| |
| assert "raw_response" in analysis |
| print("✓ analyze_job_description method works correctly") |
| |
| |
| output_cv_path = '/home/ubuntu/cv_tailoring_project/output/test_cv.docx' |
| output_cl_path = '/home/ubuntu/cv_tailoring_project/output/test_cover_letter.docx' |
| |
| |
| os.makedirs(os.path.dirname(output_cv_path), exist_ok=True) |
| |
| |
| cv_result = document_updater.update_cv(job_description, output_cv_path) |
| assert os.path.exists(cv_result) |
| print(f"✓ update_cv method works correctly, file created at {cv_result}") |
| |
| |
| cl_result = document_updater.update_cover_letter(job_description, output_cl_path) |
| assert os.path.exists(cl_result) |
| print(f"✓ update_cover_letter method works correctly, file created at {cl_result}") |
| |
| print("\nDocument updater module tests completed successfully!") |
| return True |
|
|
| if __name__ == "__main__": |
| |
| with mock.patch('src.utils.openai_integration.OpenAIIntegration') as MockOpenAI: |
| test_document_updater() |
|
|