File size: 7,409 Bytes
90e1657
 
 
 
 
71c8aa1
 
90e1657
 
 
 
 
e20dc23
71c8aa1
 
e20dc23
71c8aa1
 
e20dc23
a342aec
 
 
 
 
 
6bc1f7d
a342aec
 
 
 
 
 
 
 
 
 
 
 
9ba8701
71c8aa1
a342aec
 
71c8aa1
e20dc23
71c8aa1
90e1657
71c8aa1
 
 
90e1657
a342aec
e20dc23
71c8aa1
 
a342aec
71c8aa1
 
 
 
 
 
6bc1f7d
a342aec
 
71c8aa1
a342aec
71c8aa1
 
 
a342aec
 
71c8aa1
6bc1f7d
71c8aa1
 
a342aec
71c8aa1
 
 
a342aec
71c8aa1
 
 
 
 
 
a342aec
71c8aa1
a342aec
71c8aa1
 
 
a342aec
 
71c8aa1
a342aec
 
 
71c8aa1
 
a342aec
71c8aa1
 
 
 
 
 
a342aec
71c8aa1
a342aec
71c8aa1
 
 
a342aec
 
71c8aa1
6bc1f7d
90e1657
71c8aa1
90e1657
a342aec
e20dc23
71c8aa1
e20dc23
71c8aa1
 
a342aec
71c8aa1
 
 
e20dc23
71c8aa1
 
a342aec
e20dc23
a342aec
71c8aa1
e20dc23
a342aec
 
 
 
6bc1f7d
a342aec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bc1f7d
a342aec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6bc1f7d
a342aec
 
 
 
 
 
 
 
 
 
 
 
 
90e1657
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
"""
Unit tests for the gradio module.
"""

import unittest
from pathlib import Path
from unittest.mock import patch
from functions import gradio


class TestProcessInputs(unittest.TestCase):
    """Test cases for the process_inputs function."""

    def test_process_inputs_with_real_pdf(self):
        """Test process_inputs with the actual test PDF file."""

        # Get path to the test PDF file
        test_pdf_path = Path(__file__).parent / "test_data" / "linkedin_profile.pdf"

        # Skip test if PDF doesn't exist (optional test data)
        if not test_pdf_path.exists():
            self.skipTest(f"Test PDF file not found: {test_pdf_path}")

        with patch('functions.gradio.extract_text') as mock_extract, \
             patch('functions.gradio.get_github_repositories') as mock_github:

            mock_extract.return_value = {"test": "data"}
            mock_github.return_value = [{"name": "test-repo"}]

            result = gradio.process_inputs(
                linkedin_pdf_path=str(test_pdf_path),
                github_username="testuser",
                job_post_text="Software engineer position",
                user_instructions="Custom instructions"
            )

            # Function currently returns empty string
            self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_with_pdf_path_mocked(self, mock_github, mock_extract):
        """Test process_inputs with a PDF file path (mocked for controlled testing)."""

        # Mock successful LinkedIn text extraction
        mock_extract.return_value = {
            "contact_info": "John Doe, [email protected]",
            "summary": "Experienced software engineer",
            "experience": "Software Engineer at Company"
        }
        mock_github.return_value = [{"name": "test-repo"}]

        result = gradio.process_inputs(
            linkedin_pdf_path="/path/to/resume.pdf",
            github_username="testuser",
            job_post_text="Software engineer position",
            user_instructions="Custom instructions"
        )

        # Verify extract_text was called with the correct path
        mock_extract.assert_called_once_with("/path/to/resume.pdf")

        # Verify get_github_repositories was called with username
        mock_github.assert_called_once_with("testuser")

        # Function currently returns empty string
        self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_extraction_failure(self, mock_github, mock_extract):
        """Test process_inputs when LinkedIn extraction fails."""

        # Mock failed LinkedIn text extraction
        mock_extract.return_value = None
        mock_github.return_value = None

        result = gradio.process_inputs(
            linkedin_pdf_path="/path/to/resume.pdf",
            github_username="testuser",
            job_post_text="Software engineer position",
            user_instructions="Custom instructions"
        )

        # Verify extract_text was called
        mock_extract.assert_called_once_with("/path/to/resume.pdf")
        mock_github.assert_called_once_with("testuser")

        # Function currently returns empty string
        self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_no_pdf_path(self, mock_github, mock_extract):
        """Test process_inputs with no PDF path provided."""
        mock_extract.return_value = None
        mock_github.return_value = []

        result = gradio.process_inputs(
            linkedin_pdf_path=None,
            github_username="testuser",
            job_post_text="Software engineer position",
            user_instructions="Custom instructions"
        )

        # extract_text should be called with None
        mock_extract.assert_called_once_with(None)
        mock_github.assert_called_once_with("testuser")

        # Function currently returns empty string
        self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_with_long_job_post(self, mock_github, mock_extract):
        """Test process_inputs with a long job post text (for logging truncation)."""

        mock_extract.return_value = {
            "summary": "Test summary"
        }
        mock_github.return_value = []

        long_job_post = "This is a very long job posting " * 50  # Make it longer than 100 chars

        result = gradio.process_inputs(
            linkedin_pdf_path="/path/to/resume.pdf",
            github_username="testuser",
            job_post_text=long_job_post,
            user_instructions="Custom instructions"
        )

        # Verify extract_text was called
        mock_extract.assert_called_once_with("/path/to/resume.pdf")
        mock_github.assert_called_once_with("testuser")

        # Function currently returns empty string
        self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_github_username_whitespace(self, mock_github, mock_extract):
        """Test that github_username is properly stripped of whitespace."""

        mock_extract.return_value = None
        mock_github.return_value = []

        result = gradio.process_inputs(
            linkedin_pdf_path=None,
            github_username="  testuser  ",
            job_post_text="",
            user_instructions=""
        )

        # Verify get_github_repositories was called with stripped username
        mock_github.assert_called_once_with("testuser")
        self.assertEqual(result, "")

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    @patch('logging.getLogger')
    def test_logging_calls(self, mock_get_logger, mock_github, mock_extract):
        """Test that appropriate logging calls are made."""

        mock_logger = mock_get_logger.return_value
        mock_extract.return_value = {"test": "data"}
        mock_github.return_value = [{"name": "repo"}]

        gradio.process_inputs(
            linkedin_pdf_path="/path/to/resume.pdf",
            github_username="testuser",
            job_post_text="Job description here",
            user_instructions="Custom instructions"
        )

        # Verify logging calls were made
        mock_logger.info.assert_called()

    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_none_github_username(self, mock_github, mock_extract):
        """Test process_inputs with None github_username (should handle gracefully)."""

        mock_extract.return_value = None
        mock_github.return_value = None

        # This should raise a TypeError due to the bug in gradio.py
        # where it tries to slice job_post_text[:100] when job_post_text is None
        with self.assertRaises(TypeError):
            gradio.process_inputs(
                linkedin_pdf_path=None,
                github_username=None,
                job_post_text=None,
                user_instructions=None
            )


if __name__ == '__main__':
    unittest.main()