File size: 14,406 Bytes
90e1657
 
 
 
 
71c8aa1
 
90e1657
 
 
 
 
e20dc23
71c8aa1
 
e20dc23
71c8aa1
 
e20dc23
a342aec
 
 
 
 
a974c1c
 
 
6bc1f7d
a342aec
 
a974c1c
 
a342aec
 
 
 
a974c1c
a342aec
 
a974c1c
 
 
 
 
 
 
 
 
 
 
 
9ba8701
a974c1c
 
71c8aa1
a342aec
a974c1c
 
 
 
 
 
 
71c8aa1
e20dc23
71c8aa1
90e1657
71c8aa1
 
 
90e1657
a342aec
a974c1c
 
 
 
 
e20dc23
71c8aa1
 
a342aec
a974c1c
71c8aa1
 
 
 
6bc1f7d
a342aec
 
71c8aa1
a974c1c
 
 
 
 
71c8aa1
a974c1c
 
 
 
 
71c8aa1
a342aec
a974c1c
 
 
 
 
 
71c8aa1
6bc1f7d
71c8aa1
 
a342aec
a974c1c
71c8aa1
 
 
a342aec
a974c1c
71c8aa1
 
 
 
a342aec
a974c1c
 
 
 
71c8aa1
a974c1c
71c8aa1
 
a974c1c
 
71c8aa1
a342aec
a974c1c
 
 
 
 
 
 
71c8aa1
a974c1c
a342aec
 
a974c1c
a342aec
71c8aa1
 
a342aec
a974c1c
71c8aa1
 
 
 
a342aec
a974c1c
71c8aa1
a974c1c
 
 
 
71c8aa1
 
a974c1c
 
71c8aa1
a342aec
a974c1c
 
 
 
 
 
 
71c8aa1
6bc1f7d
90e1657
71c8aa1
90e1657
a342aec
a974c1c
e20dc23
71c8aa1
e20dc23
71c8aa1
 
a342aec
a974c1c
71c8aa1
e20dc23
71c8aa1
 
a342aec
a974c1c
 
 
 
e20dc23
a974c1c
71c8aa1
e20dc23
a974c1c
 
a342aec
 
a974c1c
 
 
 
 
 
 
a342aec
6bc1f7d
a342aec
 
a974c1c
a342aec
 
 
 
a974c1c
a342aec
 
 
 
a974c1c
a342aec
 
a974c1c
 
a342aec
 
 
a974c1c
 
 
 
 
 
 
 
a342aec
6bc1f7d
a342aec
 
 
a974c1c
 
a342aec
a974c1c
a342aec
 
a974c1c
a342aec
 
 
 
a974c1c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a342aec
a974c1c
 
a342aec
 
a974c1c
 
 
 
 
 
 
a342aec
6bc1f7d
a342aec
 
a974c1c
a342aec
 
 
 
 
 
 
a974c1c
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
"""
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, \
             patch('functions.gradio.summarize_job_call') as mock_job_call, \
             patch('functions.gradio.write_resume') as mock_write_resume:

            mock_extract.return_value = {"test": "data"}
            mock_github.return_value = [{"name": "test-repo"}]
            mock_job_call.return_value = {"title": "Software Engineer", "requirements": ["Python"]}
            mock_write_resume.return_value = "# Generated Resume\n\nTest resume content"

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

            # Verify all functions were called
            mock_extract.assert_called_once_with(str(test_pdf_path))
            mock_github.assert_called_once_with("testuser")
            mock_job_call.assert_called_once_with("Software engineer position")
            mock_write_resume.assert_called_once_with(
                {"test": "data"},
                [{"name": "test-repo"}],
                {"title": "Software Engineer", "requirements": ["Python"]}
            )

            # Function should return the generated resume
            self.assertEqual(result, "# Generated Resume\n\nTest resume content")

    @patch('functions.gradio.write_resume')
    @patch('functions.gradio.summarize_job_call')
    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_with_pdf_path_mocked(
        self,
        mock_github,
        mock_extract,
        mock_job_call,
        mock_write_resume
    ):
        """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"}]
        mock_job_call.return_value = {
            "title": "Software Engineer",
            "requirements": ["Python", "JavaScript"]
        }
        mock_write_resume.return_value = "# John Doe\n\n## Summary\nExperienced software engineer"

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

        # 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")

        # Verify job post was processed
        mock_job_call.assert_called_once_with("Software engineer position")

        # Verify resume generation was called with correct arguments
        mock_write_resume.assert_called_once()

        # Function should return the generated resume content
        self.assertEqual(result, "# John Doe\n\n## Summary\nExperienced software engineer")

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

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

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

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

        # write_resume should NOT be called when data is missing
        mock_write_resume.assert_not_called()

        # Function should return empty string when processing fails
        self.assertEqual(result, "")

    @patch('functions.gradio.write_resume')
    @patch('functions.gradio.summarize_job_call')
    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_no_pdf_path(
        self,
        mock_github,
        mock_extract,
        mock_job_call,
        mock_write_resume
    ):
        """Test process_inputs with no PDF path provided."""

        mock_extract.return_value = None
        mock_github.return_value = []
        mock_job_call.return_value = {"title": "Software Engineer"}

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

        # extract_text should be called with None
        mock_extract.assert_called_once_with(None)
        mock_github.assert_called_once_with("testuser")
        mock_job_call.assert_called_once_with("Software engineer position")

        # write_resume should NOT be called when LinkedIn data is missing
        mock_write_resume.assert_not_called()

        # Function should return empty string when data is insufficient
        self.assertEqual(result, "")

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

        mock_extract.return_value = {
            "summary": "Test summary"
        }
        mock_github.return_value = []
        mock_job_call.return_value = {"title": "Software Engineer", "requirements": ["Python"]}

        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
        )

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

        # write_resume should NOT be called when GitHub repos are empty
        mock_write_resume.assert_not_called()

        # Function should return empty string when GitHub data is missing
        self.assertEqual(result, "")

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

        mock_extract.return_value = None
        mock_github.return_value = []
        mock_job_call.return_value = {"title": "Engineer"}

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

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

    @patch('functions.gradio.write_resume')
    @patch('functions.gradio.summarize_job_call')
    @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,
        mock_job_call,
        mock_write_resume
    ):
        """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"}]
        mock_job_call.return_value = {"title": "Engineer"}
        mock_write_resume.return_value = "# Resume Content"

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

        # Verify logging calls were made
        mock_logger.info.assert_called()
        # Verify resume was generated successfully
        self.assertEqual(result, "# Resume Content")

    @patch('functions.gradio.write_resume')
    @patch('functions.gradio.summarize_job_call')
    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_write_resume_exception(
        self,
        mock_github,
        mock_extract,
        mock_job_call,
        mock_write_resume
    ):
        """Test process_inputs when write_resume raises an exception."""

        mock_extract.return_value = {"test": "data"}
        mock_github.return_value = [{"name": "repo"}]
        mock_job_call.return_value = {"title": "Engineer"}
        mock_write_resume.side_effect = Exception("API Error")

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

        # Verify all functions were called
        mock_extract.assert_called_once_with("/path/to/resume.pdf")
        mock_github.assert_called_once_with("testuser")
        mock_job_call.assert_called_once_with("Job description here")
        mock_write_resume.assert_called_once()

        # Function should return empty string when write_resume fails
        self.assertEqual(result, "")

    @patch('functions.gradio.write_resume')
    @patch('functions.gradio.summarize_job_call')
    @patch('functions.gradio.extract_text')
    @patch('functions.gradio.get_github_repositories')
    def test_process_inputs_complete_success_flow(
        self,
        mock_github,
        mock_extract,
        mock_job_call,
        mock_write_resume
    ):
        """Test the complete successful flow with all components working."""

        # Mock all successful responses
        linkedin_data = {
            "contact_info": "Jane Doe, [email protected]",
            "summary": "Senior Python Developer",
            "experience": "5 years experience in Python development"
        }
        github_repos = [
            {"name": "awesome-python-app", "description": "A Python web application"},
            {"name": "data-analysis-tool", "description": "Data analysis with pandas"}
        ]
        job_data = {
            "title": "Senior Python Developer",
            "requirements": ["Python", "Django", "PostgreSQL"],
            "company": "Tech Corp"
        }
        resume_content = (
            "# Jane Doe\n\n## Experience\n"
            "Senior Python Developer with 5 years experience..."
        )

        mock_extract.return_value = linkedin_data
        mock_github.return_value = github_repos
        mock_job_call.return_value = job_data
        mock_write_resume.return_value = resume_content

        result = gradio.process_inputs(
            linkedin_pdf_path="/path/to/jane_resume.pdf",
            github_username="jane_dev",
            job_post_text="We are looking for a Senior Python Developer with Django experience..."
        )

        # Verify all functions were called with correct arguments
        mock_extract.assert_called_once_with("/path/to/jane_resume.pdf")
        mock_github.assert_called_once_with("jane_dev")
        mock_job_call.assert_called_once_with(
            "We are looking for a Senior Python Developer with Django experience..."
        )
        mock_write_resume.assert_called_once_with(linkedin_data, github_repos, job_data)

        # Verify the complete resume is returned
        self.assertEqual(result, resume_content)
        self.assertIn("Jane Doe", result)
        self.assertIn("Senior Python Developer", result)

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

        mock_extract.return_value = None
        mock_github.return_value = None
        mock_job_call.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
            )


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