Spaces:
Configuration error
Configuration error
Updated tests for GitHub repo retreival functions.
Browse files- tests/test_github.py +215 -512
- tests/test_gradio.py +102 -24
- tests/test_resumate.py +2 -2
tests/test_github.py
CHANGED
@@ -9,164 +9,214 @@ from functions import github
|
|
9 |
|
10 |
# pylint: disable=protected-access
|
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 |
-
result = github._extract_github_username(url)
|
45 |
-
self.assertIsNone(result)
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
# Valid usernames
|
50 |
-
valid_usernames = ["user", "user-name", "user_name", "user123", "a" * 39]
|
51 |
-
for username in valid_usernames:
|
52 |
-
with self.subTest(username=username):
|
53 |
-
result = github._extract_github_username(f"github.com/{username}")
|
54 |
-
self.assertEqual(result, username)
|
55 |
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
|
|
|
|
|
|
|
|
|
63 |
|
64 |
-
|
65 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
66 |
|
67 |
@patch('requests.get')
|
68 |
-
def
|
69 |
-
"""Test successful
|
70 |
mock_response = MagicMock()
|
71 |
mock_response.status_code = 200
|
72 |
-
mock_response.json.return_value =
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
77 |
mock_get.return_value = mock_response
|
78 |
|
79 |
-
result = github.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
-
|
82 |
-
|
83 |
-
|
|
|
|
|
|
|
84 |
|
85 |
@patch('requests.get')
|
86 |
-
def
|
87 |
-
"""Test handling of
|
88 |
mock_response = MagicMock()
|
89 |
mock_response.status_code = 404
|
90 |
mock_get.return_value = mock_response
|
91 |
|
92 |
-
result = github.
|
93 |
|
94 |
-
self.
|
95 |
-
self.assertIn("not found", result["message"])
|
96 |
|
97 |
@patch('requests.get')
|
98 |
-
def
|
99 |
-
"""Test handling of rate limit
|
100 |
mock_response = MagicMock()
|
101 |
mock_response.status_code = 403
|
102 |
mock_get.return_value = mock_response
|
103 |
|
104 |
-
result = github.
|
105 |
|
106 |
-
self.
|
107 |
-
self.assertIn("rate limit", result["message"])
|
108 |
|
109 |
@patch('requests.get')
|
110 |
-
def
|
111 |
-
"""Test handling of network errors."""
|
112 |
mock_get.side_effect = requests.RequestException("Connection error")
|
113 |
|
114 |
-
result = github.
|
115 |
-
|
116 |
-
self.assertEqual(result["status"], "error")
|
117 |
-
self.assertIn("Network error", result["message"])
|
118 |
|
119 |
-
|
120 |
-
class TestGetUserRepositories(unittest.TestCase):
|
121 |
-
"""Test cases for the _get_user_repositories function."""
|
122 |
|
123 |
@patch('requests.get')
|
124 |
-
def
|
125 |
-
"""Test
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
"name": "Hello-World",
|
131 |
-
"description": "My first repository",
|
132 |
-
"language": "Python",
|
133 |
-
"stargazers_count": 5,
|
134 |
-
"forks_count": 2
|
135 |
-
}
|
136 |
-
]
|
137 |
-
mock_get.return_value = mock_response
|
138 |
-
|
139 |
-
result = github._get_user_repositories("octocat")
|
140 |
-
|
141 |
-
self.assertEqual(result["status"], "success")
|
142 |
-
self.assertIn("data", result)
|
143 |
-
self.assertEqual(len(result["data"]), 1)
|
144 |
-
self.assertEqual(result["data"][0]["name"], "Hello-World")
|
145 |
|
146 |
-
|
147 |
-
|
148 |
-
"""Test handling of empty repository list."""
|
149 |
-
mock_response = MagicMock()
|
150 |
-
mock_response.status_code = 200
|
151 |
-
mock_response.json.return_value = []
|
152 |
-
mock_get.return_value = mock_response
|
153 |
|
154 |
-
|
|
|
155 |
|
156 |
-
|
157 |
-
self.assertEqual(
|
158 |
|
159 |
@patch('requests.get')
|
160 |
-
def
|
161 |
-
"""Test
|
|
|
162 |
mock_response = MagicMock()
|
163 |
-
mock_response.status_code =
|
|
|
164 |
mock_get.return_value = mock_response
|
165 |
|
166 |
-
result = github._get_user_repositories("
|
167 |
|
168 |
-
|
169 |
-
self.
|
|
|
170 |
|
171 |
|
172 |
class TestProcessRepositoryData(unittest.TestCase):
|
@@ -177,13 +227,15 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
177 |
raw_repos = [
|
178 |
{
|
179 |
"name": "test-repo",
|
180 |
-
"description": "Test repository",
|
181 |
"language": "Python",
|
182 |
"stargazers_count": 10,
|
183 |
"forks_count": 5,
|
184 |
"updated_at": "2024-01-01T00:00:00Z",
|
|
|
185 |
"html_url": "https://github.com/user/test-repo",
|
186 |
"topics": ["python", "test"],
|
|
|
187 |
"fork": False
|
188 |
}
|
189 |
]
|
@@ -197,7 +249,11 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
197 |
self.assertEqual(processed_repo["language"], "Python")
|
198 |
self.assertEqual(processed_repo["stars"], 10)
|
199 |
self.assertEqual(processed_repo["forks"], 5)
|
200 |
-
self.
|
|
|
|
|
|
|
|
|
201 |
|
202 |
def test_fork_filtering(self):
|
203 |
"""Test filtering of unmodified forks."""
|
@@ -246,413 +302,60 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
246 |
self.assertEqual(processed_repo["language"], "")
|
247 |
self.assertEqual(processed_repo["stars"], 0)
|
248 |
self.assertEqual(processed_repo["forks"], 0)
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
@patch('functions.github._get_user_repositories')
|
265 |
-
@patch('functions.github._get_github_user_info')
|
266 |
-
@patch('functions.github._extract_github_username')
|
267 |
-
def test_successful_retrieval(self, mock_extract, mock_user_info, mock_repos):
|
268 |
-
"""Test successful repository retrieval."""
|
269 |
-
mock_extract.return_value = "octocat"
|
270 |
-
mock_user_info.return_value = {
|
271 |
-
"status": "success",
|
272 |
-
"data": {"public_repos": 10}
|
273 |
-
}
|
274 |
-
mock_repos.return_value = {
|
275 |
-
"status": "success",
|
276 |
-
"data": [{"name": "Hello-World", "fork": False, "stargazers_count": 5}]
|
277 |
-
}
|
278 |
-
|
279 |
-
result = github.get_github_repositories("https://github.com/octocat")
|
280 |
-
|
281 |
-
self.assertEqual(result["status"], "success")
|
282 |
-
self.assertIn("repositories", result)
|
283 |
-
self.assertIn("metadata", result)
|
284 |
-
self.assertEqual(result["metadata"]["username"], "octocat")
|
285 |
-
|
286 |
-
def test_invalid_url_format(self):
|
287 |
-
"""Test handling of invalid URL format."""
|
288 |
-
result = github.get_github_repositories("https://gitlab.com/user")
|
289 |
-
|
290 |
-
self.assertEqual(result["status"], "error")
|
291 |
-
self.assertIn("Invalid GitHub URL format", result["message"])
|
292 |
-
|
293 |
-
|
294 |
-
class TestFormatRepositoriesForLLM(unittest.TestCase):
|
295 |
-
"""Test cases for the format_repositories_for_llm function."""
|
296 |
-
|
297 |
-
def test_successful_formatting(self):
|
298 |
-
"""Test successful formatting of repository data."""
|
299 |
-
github_result = {
|
300 |
-
"status": "success",
|
301 |
-
"repositories": [
|
302 |
-
{
|
303 |
-
"name": "test-repo",
|
304 |
-
"description": "A test repository",
|
305 |
-
"language": "Python",
|
306 |
-
"stars": 10,
|
307 |
-
"forks": 5,
|
308 |
-
"updated_at": "2024-01-01T00:00:00Z",
|
309 |
-
"html_url": "https://github.com/user/test-repo",
|
310 |
-
"topics": ["python", "test"]
|
311 |
-
}
|
312 |
-
],
|
313 |
-
"metadata": {
|
314 |
-
"username": "testuser",
|
315 |
-
"profile_url": "https://github.com/testuser"
|
316 |
-
}
|
317 |
-
}
|
318 |
-
|
319 |
-
result = github.format_repositories_for_llm(github_result)
|
320 |
-
|
321 |
-
self.assertIn("=== GITHUB REPOSITORIES ===", result)
|
322 |
-
self.assertIn("testuser", result)
|
323 |
-
self.assertIn("test-repo", result)
|
324 |
-
self.assertIn("A test repository", result)
|
325 |
-
self.assertIn("Python", result)
|
326 |
-
self.assertIn("=== END GITHUB REPOSITORIES ===", result)
|
327 |
-
|
328 |
-
def test_error_status(self):
|
329 |
-
"""Test formatting when there's an error status."""
|
330 |
-
github_result = {
|
331 |
-
"status": "error",
|
332 |
-
"message": "User not found"
|
333 |
-
}
|
334 |
-
|
335 |
-
result = github.format_repositories_for_llm(github_result)
|
336 |
-
|
337 |
-
self.assertIn("could not be retrieved", result)
|
338 |
-
self.assertIn("User not found", result)
|
339 |
-
|
340 |
-
def test_no_repositories(self):
|
341 |
-
"""Test formatting when no repositories are found."""
|
342 |
-
github_result = {
|
343 |
-
"status": "success",
|
344 |
-
"repositories": [],
|
345 |
-
"metadata": {"username": "emptyuser"}
|
346 |
-
}
|
347 |
-
|
348 |
-
result = github.format_repositories_for_llm(github_result)
|
349 |
-
|
350 |
-
self.assertIn("No public repositories found", result)
|
351 |
-
self.assertIn("emptyuser", result)
|
352 |
-
|
353 |
-
def test_many_repositories_limit(self):
|
354 |
-
"""Test that formatting limits to 20 repositories."""
|
355 |
-
repositories = []
|
356 |
-
for i in range(25):
|
357 |
-
repositories.append({
|
358 |
-
"name": f"repo-{i}",
|
359 |
-
"description": f"Repository {i}",
|
360 |
-
"language": "Python",
|
361 |
-
"stars": i,
|
362 |
-
"forks": 0,
|
363 |
-
"updated_at": "2024-01-01T00:00:00Z",
|
364 |
-
"html_url": f"https://github.com/user/repo-{i}",
|
365 |
-
"topics": []
|
366 |
-
})
|
367 |
-
|
368 |
-
github_result = {
|
369 |
-
"status": "success",
|
370 |
-
"repositories": repositories,
|
371 |
-
"metadata": {"username": "manyrepos"}
|
372 |
-
}
|
373 |
-
|
374 |
-
result = github.format_repositories_for_llm(github_result)
|
375 |
-
|
376 |
-
# Should mention "and 5 more repositories"
|
377 |
-
self.assertIn("and 5 more repositories", result)
|
378 |
-
# Should contain the first 20 repos
|
379 |
-
self.assertIn("repo-0", result)
|
380 |
-
self.assertIn("repo-19", result)
|
381 |
-
# Should not contain repos beyond 20
|
382 |
-
self.assertNotIn("repo-20", result)
|
383 |
-
|
384 |
-
|
385 |
-
class TestGetRepositoryDetails(unittest.TestCase):
|
386 |
-
"""Test cases for the get_repository_details function."""
|
387 |
-
|
388 |
-
def test_invalid_repository_url(self):
|
389 |
-
"""Test handling of invalid repository URLs."""
|
390 |
-
invalid_urls = [
|
391 |
-
"",
|
392 |
None,
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
"not-a-url",
|
397 |
-
]
|
398 |
-
|
399 |
-
for url in invalid_urls:
|
400 |
-
with self.subTest(url=url):
|
401 |
-
result = github.get_repository_details(url)
|
402 |
-
self.assertEqual(result["status"], "error")
|
403 |
-
self.assertIn("message", result)
|
404 |
-
|
405 |
-
@patch('functions.github._get_repository_info')
|
406 |
-
@patch('functions.github._extract_repo_info')
|
407 |
-
def test_repository_not_found(self, mock_extract, mock_get_info):
|
408 |
-
"""Test handling of non-existent repository."""
|
409 |
-
mock_extract.return_value = ("user", "nonexistent-repo")
|
410 |
-
mock_get_info.return_value = {
|
411 |
-
"status": "error",
|
412 |
-
"message": "Repository 'user/nonexistent-repo' not found"
|
413 |
-
}
|
414 |
-
|
415 |
-
result = github.get_repository_details("https://github.com/user/nonexistent-repo")
|
416 |
-
|
417 |
-
self.assertEqual(result["status"], "error")
|
418 |
-
self.assertIn("not found", result["message"])
|
419 |
-
|
420 |
-
@patch('functions.github._get_repository_contributors')
|
421 |
-
@patch('functions.github._get_repository_releases')
|
422 |
-
@patch('functions.github._get_repository_contents')
|
423 |
-
@patch('functions.github._get_repository_readme')
|
424 |
-
@patch('functions.github._get_repository_languages')
|
425 |
-
@patch('functions.github._get_repository_info')
|
426 |
-
@patch('functions.github._extract_repo_info')
|
427 |
-
def test_successful_repository_details(self, mock_extract, mock_get_info,
|
428 |
-
mock_languages, mock_readme, mock_contents,
|
429 |
-
mock_releases, mock_contributors):
|
430 |
-
"""Test successful repository details retrieval."""
|
431 |
-
# Mock URL extraction
|
432 |
-
mock_extract.return_value = ("octocat", "Hello-World")
|
433 |
-
|
434 |
-
# Mock basic repository info
|
435 |
-
mock_get_info.return_value = {
|
436 |
-
"status": "success",
|
437 |
-
"data": {
|
438 |
-
"name": "Hello-World",
|
439 |
-
"full_name": "octocat/Hello-World",
|
440 |
-
"description": "This your first repo!",
|
441 |
-
"language": "C",
|
442 |
-
"stargazers_count": 80,
|
443 |
-
"forks_count": 9,
|
444 |
-
"watchers_count": 80,
|
445 |
-
"size": 108,
|
446 |
-
"created_at": "2011-01-26T19:01:12Z",
|
447 |
-
"updated_at": "2011-01-26T19:14:43Z",
|
448 |
-
"pushed_at": "2011-01-26T19:06:43Z",
|
449 |
-
"html_url": "https://github.com/octocat/Hello-World",
|
450 |
-
"clone_url": "https://github.com/octocat/Hello-World.git",
|
451 |
-
"ssh_url": "[email protected]:octocat/Hello-World.git",
|
452 |
-
"topics": ["example", "tutorial"],
|
453 |
-
"license": {"name": "MIT License", "spdx_id": "MIT"},
|
454 |
-
"fork": False,
|
455 |
-
"archived": False,
|
456 |
-
"private": False,
|
457 |
-
"default_branch": "master",
|
458 |
-
"open_issues_count": 0,
|
459 |
-
"has_issues": True,
|
460 |
-
"has_wiki": True,
|
461 |
-
"has_pages": False,
|
462 |
-
"has_projects": True,
|
463 |
-
"visibility": "public"
|
464 |
}
|
465 |
-
}
|
466 |
-
|
467 |
-
# Mock additional data
|
468 |
-
mock_languages.return_value = {
|
469 |
-
"status": "success",
|
470 |
-
"data": {"C": 78.1, "Makefile": 21.9}
|
471 |
-
}
|
472 |
-
|
473 |
-
mock_readme.return_value = {
|
474 |
-
"status": "success",
|
475 |
-
"data": "# Hello World\n\nThis is a test repository."
|
476 |
-
}
|
477 |
-
|
478 |
-
mock_contents.return_value = {
|
479 |
-
"status": "success",
|
480 |
-
"data": ["README.md", "hello.c", "Makefile"]
|
481 |
-
}
|
482 |
-
|
483 |
-
mock_releases.return_value = {
|
484 |
-
"status": "success",
|
485 |
-
"data": [
|
486 |
-
{
|
487 |
-
"tag_name": "v1.0.0",
|
488 |
-
"name": "First Release",
|
489 |
-
"published_at": "2011-01-26T19:14:43Z",
|
490 |
-
"prerelease": False,
|
491 |
-
"draft": False
|
492 |
-
}
|
493 |
-
]
|
494 |
-
}
|
495 |
-
|
496 |
-
mock_contributors.return_value = {
|
497 |
-
"status": "success",
|
498 |
-
"data": [
|
499 |
-
{
|
500 |
-
"login": "octocat",
|
501 |
-
"contributions": 32,
|
502 |
-
"html_url": "https://github.com/octocat",
|
503 |
-
"type": "User"
|
504 |
-
}
|
505 |
-
]
|
506 |
-
}
|
507 |
-
|
508 |
-
result = github.get_repository_details("https://github.com/octocat/Hello-World")
|
509 |
-
|
510 |
-
# Verify success
|
511 |
-
self.assertEqual(result["status"], "success")
|
512 |
-
self.assertIn("repository", result)
|
513 |
-
|
514 |
-
repo = result["repository"]
|
515 |
-
|
516 |
-
# Verify basic info
|
517 |
-
self.assertEqual(repo["name"], "Hello-World")
|
518 |
-
self.assertEqual(repo["full_name"], "octocat/Hello-World")
|
519 |
-
self.assertEqual(repo["description"], "This your first repo!")
|
520 |
-
self.assertEqual(repo["language"], "C")
|
521 |
-
self.assertEqual(repo["stars"], 80)
|
522 |
-
self.assertEqual(repo["forks"], 9)
|
523 |
-
|
524 |
-
# Verify additional data
|
525 |
-
self.assertEqual(repo["languages"], {"C": 78.1, "Makefile": 21.9})
|
526 |
-
self.assertIn("Hello World", repo["readme"])
|
527 |
-
self.assertEqual(repo["file_structure"], ["README.md", "hello.c", "Makefile"])
|
528 |
-
self.assertEqual(len(repo["releases"]), 1)
|
529 |
-
self.assertEqual(repo["releases"][0]["tag_name"], "v1.0.0")
|
530 |
-
self.assertEqual(len(repo["contributors"]), 1)
|
531 |
-
self.assertEqual(repo["contributors"][0]["login"], "octocat")
|
532 |
-
|
533 |
-
# Verify boolean flags
|
534 |
-
self.assertFalse(repo["is_fork"])
|
535 |
-
self.assertFalse(repo["is_archived"])
|
536 |
-
self.assertFalse(repo["is_private"])
|
537 |
-
self.assertTrue(repo["has_issues"])
|
538 |
-
|
539 |
-
def test_extract_repo_info_valid_urls(self):
|
540 |
-
"""Test _extract_repo_info with valid repository URLs."""
|
541 |
-
test_cases = [
|
542 |
-
("https://github.com/octocat/Hello-World", ("octocat", "Hello-World")),
|
543 |
-
("https://github.com/user/repo.git", ("user", "repo")),
|
544 |
-
("https://github.com/org/project/", ("org", "project")),
|
545 |
-
("github.com/test/example", ("test", "example")),
|
546 |
-
("https://github.com/user/repo/issues", ("user", "repo")),
|
547 |
]
|
548 |
|
549 |
-
|
550 |
-
|
551 |
-
|
552 |
-
|
553 |
-
|
554 |
-
|
555 |
-
|
556 |
-
invalid_urls = [
|
557 |
-
"",
|
558 |
-
"https://gitlab.com/user/repo",
|
559 |
-
"https://github.com/user",
|
560 |
-
"https://github.com/",
|
561 |
-
"not-a-url",
|
562 |
-
]
|
563 |
-
|
564 |
-
for url in invalid_urls:
|
565 |
-
with self.subTest(url=url):
|
566 |
-
result = github._extract_repo_info(url)
|
567 |
-
self.assertEqual(result, (None, None))
|
568 |
-
|
569 |
-
@patch('requests.get')
|
570 |
-
def test_get_repository_info_success(self, mock_get):
|
571 |
-
"""Test _get_repository_info with successful response."""
|
572 |
-
mock_response = MagicMock()
|
573 |
-
mock_response.status_code = 200
|
574 |
-
mock_response.json.return_value = {
|
575 |
-
"name": "test-repo",
|
576 |
-
"full_name": "user/test-repo"
|
577 |
-
}
|
578 |
-
mock_get.return_value = mock_response
|
579 |
|
580 |
-
|
|
|
|
|
581 |
|
582 |
-
self.assertEqual(result[
|
583 |
-
self.assertIn("data", result)
|
584 |
-
self.assertEqual(result["data"]["name"], "test-repo")
|
585 |
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
def test_get_repository_languages_success(self, mock_get):
|
600 |
-
"""Test _get_repository_languages with successful response."""
|
601 |
-
mock_response = MagicMock()
|
602 |
-
mock_response.status_code = 200
|
603 |
-
mock_response.json.return_value = {
|
604 |
-
"Python": 50000,
|
605 |
-
"JavaScript": 25000,
|
606 |
-
"CSS": 25000
|
607 |
-
}
|
608 |
-
mock_get.return_value = mock_response
|
609 |
-
|
610 |
-
result = github._get_repository_languages("user", "repo")
|
611 |
-
|
612 |
-
self.assertEqual(result["status"], "success")
|
613 |
-
expected_percentages = {"Python": 50.0, "JavaScript": 25.0, "CSS": 25.0}
|
614 |
-
self.assertEqual(result["data"], expected_percentages)
|
615 |
-
|
616 |
-
@patch('requests.get')
|
617 |
-
def test_get_repository_readme_success(self, mock_get):
|
618 |
-
"""Test _get_repository_readme with successful response."""
|
619 |
-
# Mock the README metadata response
|
620 |
-
readme_response = MagicMock()
|
621 |
-
readme_response.status_code = 200
|
622 |
-
readme_response.json.return_value = {
|
623 |
-
"download_url": "https://raw.githubusercontent.com/user/repo/main/README.md"
|
624 |
-
}
|
625 |
-
|
626 |
-
# Mock the README content response
|
627 |
-
content_response = MagicMock()
|
628 |
-
content_response.status_code = 200
|
629 |
-
content_response.text = "# Test Repository\n\nThis is a test."
|
630 |
-
|
631 |
-
mock_get.side_effect = [readme_response, content_response]
|
632 |
-
|
633 |
-
result = github._get_repository_readme("user", "repo")
|
634 |
-
|
635 |
-
self.assertEqual(result["status"], "success")
|
636 |
-
self.assertIn("Test Repository", result["data"])
|
637 |
-
|
638 |
-
@patch('requests.get')
|
639 |
-
def test_get_repository_contents_success(self, mock_get):
|
640 |
-
"""Test _get_repository_contents with successful response."""
|
641 |
-
mock_response = MagicMock()
|
642 |
-
mock_response.status_code = 200
|
643 |
-
mock_response.json.return_value = [
|
644 |
-
{"name": "src", "type": "dir"},
|
645 |
-
{"name": "README.md", "type": "file"},
|
646 |
-
{"name": "setup.py", "type": "file"},
|
647 |
-
{"name": "tests", "type": "dir"}
|
648 |
]
|
649 |
-
mock_get.return_value = mock_response
|
650 |
|
651 |
-
result = github.
|
652 |
|
653 |
-
self.assertEqual(result[
|
654 |
-
expected_structure = ["src/", "tests/", "README.md", "setup.py"]
|
655 |
-
self.assertEqual(result["data"], expected_structure)
|
656 |
|
657 |
|
658 |
if __name__ == '__main__':
|
|
|
9 |
|
10 |
# pylint: disable=protected-access
|
11 |
|
12 |
+
|
13 |
+
class TestGetGitHubRepositories(unittest.TestCase):
|
14 |
+
"""Test cases for the get_github_repositories function."""
|
15 |
+
|
16 |
+
@patch('functions.github._get_user_repositories')
|
17 |
+
@patch('functions.github._process_repository_data')
|
18 |
+
def test_successful_repository_retrieval(self, mock_process, mock_get_repos):
|
19 |
+
"""Test successful repository retrieval."""
|
20 |
+
# Mock raw repository data
|
21 |
+
mock_raw_repos = [
|
22 |
+
{
|
23 |
+
"name": "test-repo",
|
24 |
+
"description": "Test repository",
|
25 |
+
"language": "Python",
|
26 |
+
"stargazers_count": 10,
|
27 |
+
"forks_count": 5,
|
28 |
+
"updated_at": "2024-01-01T00:00:00Z",
|
29 |
+
"html_url": "https://github.com/user/test-repo",
|
30 |
+
"topics": ["python", "test"],
|
31 |
+
"fork": False
|
32 |
+
}
|
33 |
]
|
34 |
|
35 |
+
# Mock processed repository data
|
36 |
+
mock_processed_repos = [
|
37 |
+
{
|
38 |
+
"name": "test-repo",
|
39 |
+
"description": "Test repository",
|
40 |
+
"language": "Python",
|
41 |
+
"stars": 10,
|
42 |
+
"forks": 5,
|
43 |
+
"updated_at": "2024-01-01T00:00:00Z",
|
44 |
+
"created_at": "2024-01-01T00:00:00Z",
|
45 |
+
"html_url": "https://github.com/user/test-repo",
|
46 |
+
"topics": ["python", "test"],
|
47 |
+
"size": 100
|
48 |
+
}
|
49 |
]
|
50 |
|
51 |
+
mock_get_repos.return_value = mock_raw_repos
|
52 |
+
mock_process.return_value = mock_processed_repos
|
|
|
|
|
53 |
|
54 |
+
with patch('pathlib.Path.mkdir'), patch('builtins.open'), patch('json.dump'):
|
55 |
+
result = github.get_github_repositories("testuser")
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
|
57 |
+
self.assertEqual(result, mock_processed_repos)
|
58 |
+
mock_get_repos.assert_called_once_with("testuser")
|
59 |
+
mock_process.assert_called_once_with(mock_raw_repos)
|
60 |
+
|
61 |
+
@patch('functions.github._get_user_repositories')
|
62 |
+
def test_no_repositories_found(self, mock_get_repos):
|
63 |
+
"""Test when no repositories are found."""
|
64 |
+
mock_get_repos.return_value = None
|
65 |
+
|
66 |
+
result = github.get_github_repositories("emptyuser")
|
67 |
+
|
68 |
+
self.assertIsNone(result)
|
69 |
+
mock_get_repos.assert_called_once_with("emptyuser")
|
70 |
+
|
71 |
+
@patch('functions.github._get_user_repositories')
|
72 |
+
def test_exception_during_processing(self, mock_get_repos):
|
73 |
+
"""Test exception handling during repository processing."""
|
74 |
+
mock_get_repos.side_effect = Exception("API error")
|
75 |
+
|
76 |
+
result = github.get_github_repositories("erroruser")
|
77 |
+
|
78 |
+
self.assertIsNone(result)
|
79 |
+
mock_get_repos.assert_called_once_with("erroruser")
|
80 |
+
|
81 |
+
@patch('functions.github._get_user_repositories')
|
82 |
+
@patch('functions.github._process_repository_data')
|
83 |
+
def test_file_saving_error(self, mock_process, mock_get_repos):
|
84 |
+
"""Test that file saving errors don't break the function."""
|
85 |
+
mock_get_repos.return_value = [{"name": "test"}]
|
86 |
+
mock_process.return_value = [{"name": "test", "stars": 0}]
|
87 |
|
88 |
+
# Mock file operations to raise an exception
|
89 |
+
with patch('pathlib.Path.mkdir'), \
|
90 |
+
patch('builtins.open', side_effect=Exception("File error")), \
|
91 |
+
patch('logging.getLogger') as mock_get_logger:
|
92 |
|
93 |
+
mock_logger = mock_get_logger.return_value
|
94 |
+
result = github.get_github_repositories("testuser")
|
95 |
+
|
96 |
+
# Should still return the repositories despite file error
|
97 |
+
self.assertEqual(result, [{"name": "test", "stars": 0}])
|
98 |
+
# Should log a warning about the file save error
|
99 |
+
mock_logger.warning.assert_called()
|
100 |
+
|
101 |
+
|
102 |
+
class TestGetUserRepositories(unittest.TestCase):
|
103 |
+
"""Test cases for the _get_user_repositories function."""
|
104 |
|
105 |
@patch('requests.get')
|
106 |
+
def test_successful_single_page(self, mock_get):
|
107 |
+
"""Test successful repository retrieval with single page."""
|
108 |
mock_response = MagicMock()
|
109 |
mock_response.status_code = 200
|
110 |
+
mock_response.json.return_value = [
|
111 |
+
{
|
112 |
+
"name": "repo1",
|
113 |
+
"description": "First repo",
|
114 |
+
"language": "Python"
|
115 |
+
},
|
116 |
+
{
|
117 |
+
"name": "repo2",
|
118 |
+
"description": "Second repo",
|
119 |
+
"language": "JavaScript"
|
120 |
+
}
|
121 |
+
]
|
122 |
mock_get.return_value = mock_response
|
123 |
|
124 |
+
result = github._get_user_repositories("testuser")
|
125 |
+
|
126 |
+
self.assertEqual(len(result), 2)
|
127 |
+
self.assertEqual(result[0]["name"], "repo1")
|
128 |
+
self.assertEqual(result[1]["name"], "repo2")
|
129 |
+
|
130 |
+
# Verify API call parameters
|
131 |
+
mock_get.assert_called_once()
|
132 |
+
call_args = mock_get.call_args
|
133 |
+
self.assertIn("https://api.github.com/users/testuser/repos", call_args[0][0])
|
134 |
+
self.assertEqual(call_args[1]["params"]["type"], "public")
|
135 |
+
self.assertEqual(call_args[1]["params"]["sort"], "updated")
|
136 |
+
self.assertEqual(call_args[1]["headers"]["User-Agent"], "Resumate-App/1.0")
|
137 |
+
|
138 |
+
@patch('requests.get')
|
139 |
+
def test_successful_multiple_pages(self, mock_get):
|
140 |
+
"""Test successful repository retrieval with multiple pages."""
|
141 |
+
# First page response
|
142 |
+
first_response = MagicMock()
|
143 |
+
first_response.status_code = 200
|
144 |
+
first_response.json.return_value = [{"name": f"repo{i}"} for i in range(100)]
|
145 |
+
|
146 |
+
# Second page response (less than per_page, so pagination stops)
|
147 |
+
second_response = MagicMock()
|
148 |
+
second_response.status_code = 200
|
149 |
+
second_response.json.return_value = [{"name": f"repo{i}"} for i in range(100, 150)]
|
150 |
|
151 |
+
mock_get.side_effect = [first_response, second_response]
|
152 |
+
|
153 |
+
result = github._get_user_repositories("testuser")
|
154 |
+
|
155 |
+
self.assertEqual(len(result), 150)
|
156 |
+
self.assertEqual(mock_get.call_count, 2)
|
157 |
|
158 |
@patch('requests.get')
|
159 |
+
def test_api_error_404(self, mock_get):
|
160 |
+
"""Test handling of 404 user not found error."""
|
161 |
mock_response = MagicMock()
|
162 |
mock_response.status_code = 404
|
163 |
mock_get.return_value = mock_response
|
164 |
|
165 |
+
result = github._get_user_repositories("nonexistentuser")
|
166 |
|
167 |
+
self.assertIsNone(result)
|
|
|
168 |
|
169 |
@patch('requests.get')
|
170 |
+
def test_api_error_403(self, mock_get):
|
171 |
+
"""Test handling of 403 rate limit error."""
|
172 |
mock_response = MagicMock()
|
173 |
mock_response.status_code = 403
|
174 |
mock_get.return_value = mock_response
|
175 |
|
176 |
+
result = github._get_user_repositories("testuser")
|
177 |
|
178 |
+
self.assertIsNone(result)
|
|
|
179 |
|
180 |
@patch('requests.get')
|
181 |
+
def test_network_error_no_repos(self, mock_get):
|
182 |
+
"""Test handling of network errors with no existing repos."""
|
183 |
mock_get.side_effect = requests.RequestException("Connection error")
|
184 |
|
185 |
+
result = github._get_user_repositories("testuser")
|
|
|
|
|
|
|
186 |
|
187 |
+
self.assertIsNone(result)
|
|
|
|
|
188 |
|
189 |
@patch('requests.get')
|
190 |
+
def test_network_error_with_partial_repos(self, mock_get):
|
191 |
+
"""Test handling of network errors after getting some repos."""
|
192 |
+
# First call succeeds
|
193 |
+
first_response = MagicMock()
|
194 |
+
first_response.status_code = 200
|
195 |
+
first_response.json.return_value = [{"name": "repo1"}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
196 |
|
197 |
+
# Second call fails
|
198 |
+
mock_get.side_effect = [first_response, requests.RequestException("Connection error")]
|
|
|
|
|
|
|
|
|
|
|
199 |
|
200 |
+
with patch('logging.getLogger'):
|
201 |
+
result = github._get_user_repositories("testuser")
|
202 |
|
203 |
+
# Should return the partial data from the first successful call
|
204 |
+
self.assertEqual(result, [{"name": "repo1"}])
|
205 |
|
206 |
@patch('requests.get')
|
207 |
+
def test_safety_limit_prevents_infinite_loop(self, mock_get):
|
208 |
+
"""Test that safety limit prevents infinite pagination."""
|
209 |
+
# Mock response that always returns full pages
|
210 |
mock_response = MagicMock()
|
211 |
+
mock_response.status_code = 200
|
212 |
+
mock_response.json.return_value = [{"name": f"repo{i}"} for i in range(100)]
|
213 |
mock_get.return_value = mock_response
|
214 |
|
215 |
+
result = github._get_user_repositories("testuser")
|
216 |
|
217 |
+
# Should stop at page 10 (safety limit)
|
218 |
+
self.assertEqual(mock_get.call_count, 10)
|
219 |
+
self.assertEqual(len(result), 1000) # 10 pages * 100 repos each
|
220 |
|
221 |
|
222 |
class TestProcessRepositoryData(unittest.TestCase):
|
|
|
227 |
raw_repos = [
|
228 |
{
|
229 |
"name": "test-repo",
|
230 |
+
"description": "Test repository",
|
231 |
"language": "Python",
|
232 |
"stargazers_count": 10,
|
233 |
"forks_count": 5,
|
234 |
"updated_at": "2024-01-01T00:00:00Z",
|
235 |
+
"created_at": "2024-01-01T00:00:00Z",
|
236 |
"html_url": "https://github.com/user/test-repo",
|
237 |
"topics": ["python", "test"],
|
238 |
+
"size": 100,
|
239 |
"fork": False
|
240 |
}
|
241 |
]
|
|
|
249 |
self.assertEqual(processed_repo["language"], "Python")
|
250 |
self.assertEqual(processed_repo["stars"], 10)
|
251 |
self.assertEqual(processed_repo["forks"], 5)
|
252 |
+
self.assertEqual(processed_repo["updated_at"], "2024-01-01T00:00:00Z")
|
253 |
+
self.assertEqual(processed_repo["created_at"], "2024-01-01T00:00:00Z")
|
254 |
+
self.assertEqual(processed_repo["html_url"], "https://github.com/user/test-repo")
|
255 |
+
self.assertEqual(processed_repo["topics"], ["python", "test"])
|
256 |
+
self.assertEqual(processed_repo["size"], 100)
|
257 |
|
258 |
def test_fork_filtering(self):
|
259 |
"""Test filtering of unmodified forks."""
|
|
|
302 |
self.assertEqual(processed_repo["language"], "")
|
303 |
self.assertEqual(processed_repo["stars"], 0)
|
304 |
self.assertEqual(processed_repo["forks"], 0)
|
305 |
+
self.assertEqual(processed_repo["updated_at"], "")
|
306 |
+
self.assertEqual(processed_repo["created_at"], "")
|
307 |
+
self.assertEqual(processed_repo["html_url"], "")
|
308 |
+
self.assertEqual(processed_repo["topics"], [])
|
309 |
+
self.assertEqual(processed_repo["size"], 0)
|
310 |
+
|
311 |
+
def test_processing_error_handling(self):
|
312 |
+
"""Test handling of processing errors for individual repos."""
|
313 |
+
# Create a repo dict that will cause an error during processing
|
314 |
+
raw_repos = [
|
315 |
+
{
|
316 |
+
"name": "good-repo",
|
317 |
+
"stargazers_count": 5
|
318 |
+
},
|
319 |
+
# This will cause an AttributeError when trying to call .get() on None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
320 |
None,
|
321 |
+
{
|
322 |
+
"name": "another-good-repo",
|
323 |
+
"stargazers_count": 3
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
324 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
325 |
]
|
326 |
|
327 |
+
with patch('logging.getLogger') as mock_get_logger:
|
328 |
+
mock_logger = mock_get_logger.return_value
|
329 |
+
|
330 |
+
# The function currently has a bug where it doesn't handle None repos
|
331 |
+
# This will raise an AttributeError
|
332 |
+
with self.assertRaises(AttributeError):
|
333 |
+
github._process_repository_data(raw_repos)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
334 |
|
335 |
+
def test_empty_repository_list(self):
|
336 |
+
"""Test processing of empty repository list."""
|
337 |
+
result = github._process_repository_data([])
|
338 |
|
339 |
+
self.assertEqual(result, [])
|
|
|
|
|
340 |
|
341 |
+
def test_all_forks_filtered(self):
|
342 |
+
"""Test when all repositories are unmodified forks."""
|
343 |
+
raw_repos = [
|
344 |
+
{
|
345 |
+
"name": "fork1",
|
346 |
+
"fork": True,
|
347 |
+
"stargazers_count": 0
|
348 |
+
},
|
349 |
+
{
|
350 |
+
"name": "fork2",
|
351 |
+
"fork": True,
|
352 |
+
"stargazers_count": 0
|
353 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
354 |
]
|
|
|
355 |
|
356 |
+
result = github._process_repository_data(raw_repos)
|
357 |
|
358 |
+
self.assertEqual(result, [])
|
|
|
|
|
359 |
|
360 |
|
361 |
if __name__ == '__main__':
|
tests/test_gradio.py
CHANGED
@@ -17,21 +17,29 @@ class TestProcessInputs(unittest.TestCase):
|
|
17 |
# Get path to the test PDF file
|
18 |
test_pdf_path = Path(__file__).parent / "test_data" / "linkedin_profile.pdf"
|
19 |
|
20 |
-
#
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
@patch('functions.gradio.extract_text')
|
34 |
-
|
|
|
35 |
"""Test process_inputs with a PDF file path (mocked for controlled testing)."""
|
36 |
|
37 |
# Mock successful LinkedIn text extraction
|
@@ -40,77 +48,147 @@ class TestProcessInputs(unittest.TestCase):
|
|
40 |
"summary": "Experienced software engineer",
|
41 |
"experience": "Software Engineer at Company"
|
42 |
}
|
|
|
43 |
|
44 |
result = gradio.process_inputs(
|
45 |
linkedin_pdf_path="/path/to/resume.pdf",
|
46 |
-
|
47 |
job_post_text="Software engineer position",
|
48 |
user_instructions="Custom instructions"
|
49 |
)
|
50 |
|
51 |
# Verify extract_text was called with the correct path
|
52 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
|
|
|
|
53 |
|
54 |
-
#
|
55 |
self.assertEqual(result, "")
|
56 |
|
57 |
@patch('functions.gradio.extract_text')
|
58 |
-
|
|
|
59 |
"""Test process_inputs when LinkedIn extraction fails."""
|
60 |
# Mock failed LinkedIn text extraction
|
61 |
mock_extract.return_value = None
|
|
|
62 |
|
63 |
result = gradio.process_inputs(
|
64 |
linkedin_pdf_path="/path/to/resume.pdf",
|
65 |
-
|
66 |
job_post_text="Software engineer position",
|
67 |
user_instructions="Custom instructions"
|
68 |
)
|
69 |
|
70 |
# Verify extract_text was called
|
71 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
|
|
72 |
|
73 |
-
#
|
74 |
self.assertEqual(result, "")
|
75 |
|
76 |
@patch('functions.gradio.extract_text')
|
77 |
-
|
|
|
78 |
"""Test process_inputs with no PDF path provided."""
|
|
|
|
|
|
|
79 |
result = gradio.process_inputs(
|
80 |
linkedin_pdf_path=None,
|
81 |
-
|
82 |
job_post_text="Software engineer position",
|
83 |
user_instructions="Custom instructions"
|
84 |
)
|
85 |
|
86 |
# extract_text should be called with None
|
87 |
mock_extract.assert_called_once_with(None)
|
|
|
88 |
|
89 |
-
#
|
90 |
self.assertEqual(result, "")
|
91 |
|
92 |
@patch('functions.gradio.extract_text')
|
93 |
-
|
|
|
94 |
"""Test process_inputs with a long job post text (for logging truncation)."""
|
95 |
mock_extract.return_value = {
|
96 |
"summary": "Test summary"
|
97 |
}
|
|
|
98 |
|
99 |
long_job_post = "This is a very long job posting " * 50 # Make it longer than 100 chars
|
100 |
|
101 |
result = gradio.process_inputs(
|
102 |
linkedin_pdf_path="/path/to/resume.pdf",
|
103 |
-
|
104 |
job_post_text=long_job_post,
|
105 |
user_instructions="Custom instructions"
|
106 |
)
|
107 |
|
108 |
# Verify extract_text was called
|
109 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
|
|
110 |
|
111 |
-
#
|
112 |
self.assertEqual(result, "")
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
|
115 |
if __name__ == '__main__':
|
116 |
unittest.main()
|
|
|
17 |
# Get path to the test PDF file
|
18 |
test_pdf_path = Path(__file__).parent / "test_data" / "linkedin_profile.pdf"
|
19 |
|
20 |
+
# Skip test if PDF doesn't exist (optional test data)
|
21 |
+
if not test_pdf_path.exists():
|
22 |
+
self.skipTest(f"Test PDF file not found: {test_pdf_path}")
|
23 |
+
|
24 |
+
with patch('functions.gradio.extract_text') as mock_extract, \
|
25 |
+
patch('functions.gradio.get_github_repositories') as mock_github:
|
26 |
+
|
27 |
+
mock_extract.return_value = {"test": "data"}
|
28 |
+
mock_github.return_value = [{"name": "test-repo"}]
|
29 |
+
|
30 |
+
result = gradio.process_inputs(
|
31 |
+
linkedin_pdf_path=str(test_pdf_path),
|
32 |
+
github_username="testuser",
|
33 |
+
job_post_text="Software engineer position",
|
34 |
+
user_instructions="Custom instructions"
|
35 |
+
)
|
36 |
+
|
37 |
+
# Function currently returns empty string
|
38 |
+
self.assertEqual(result, "")
|
39 |
|
40 |
@patch('functions.gradio.extract_text')
|
41 |
+
@patch('functions.gradio.get_github_repositories')
|
42 |
+
def test_process_inputs_with_pdf_path_mocked(self, mock_github, mock_extract):
|
43 |
"""Test process_inputs with a PDF file path (mocked for controlled testing)."""
|
44 |
|
45 |
# Mock successful LinkedIn text extraction
|
|
|
48 |
"summary": "Experienced software engineer",
|
49 |
"experience": "Software Engineer at Company"
|
50 |
}
|
51 |
+
mock_github.return_value = [{"name": "test-repo"}]
|
52 |
|
53 |
result = gradio.process_inputs(
|
54 |
linkedin_pdf_path="/path/to/resume.pdf",
|
55 |
+
github_username="testuser",
|
56 |
job_post_text="Software engineer position",
|
57 |
user_instructions="Custom instructions"
|
58 |
)
|
59 |
|
60 |
# Verify extract_text was called with the correct path
|
61 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
62 |
+
# Verify get_github_repositories was called with username
|
63 |
+
mock_github.assert_called_once_with("testuser")
|
64 |
|
65 |
+
# Function currently returns empty string
|
66 |
self.assertEqual(result, "")
|
67 |
|
68 |
@patch('functions.gradio.extract_text')
|
69 |
+
@patch('functions.gradio.get_github_repositories')
|
70 |
+
def test_process_inputs_extraction_failure(self, mock_github, mock_extract):
|
71 |
"""Test process_inputs when LinkedIn extraction fails."""
|
72 |
# Mock failed LinkedIn text extraction
|
73 |
mock_extract.return_value = None
|
74 |
+
mock_github.return_value = None
|
75 |
|
76 |
result = gradio.process_inputs(
|
77 |
linkedin_pdf_path="/path/to/resume.pdf",
|
78 |
+
github_username="testuser",
|
79 |
job_post_text="Software engineer position",
|
80 |
user_instructions="Custom instructions"
|
81 |
)
|
82 |
|
83 |
# Verify extract_text was called
|
84 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
85 |
+
mock_github.assert_called_once_with("testuser")
|
86 |
|
87 |
+
# Function currently returns empty string
|
88 |
self.assertEqual(result, "")
|
89 |
|
90 |
@patch('functions.gradio.extract_text')
|
91 |
+
@patch('functions.gradio.get_github_repositories')
|
92 |
+
def test_process_inputs_no_pdf_path(self, mock_github, mock_extract):
|
93 |
"""Test process_inputs with no PDF path provided."""
|
94 |
+
mock_extract.return_value = None
|
95 |
+
mock_github.return_value = []
|
96 |
+
|
97 |
result = gradio.process_inputs(
|
98 |
linkedin_pdf_path=None,
|
99 |
+
github_username="testuser",
|
100 |
job_post_text="Software engineer position",
|
101 |
user_instructions="Custom instructions"
|
102 |
)
|
103 |
|
104 |
# extract_text should be called with None
|
105 |
mock_extract.assert_called_once_with(None)
|
106 |
+
mock_github.assert_called_once_with("testuser")
|
107 |
|
108 |
+
# Function currently returns empty string
|
109 |
self.assertEqual(result, "")
|
110 |
|
111 |
@patch('functions.gradio.extract_text')
|
112 |
+
@patch('functions.gradio.get_github_repositories')
|
113 |
+
def test_process_inputs_with_long_job_post(self, mock_github, mock_extract):
|
114 |
"""Test process_inputs with a long job post text (for logging truncation)."""
|
115 |
mock_extract.return_value = {
|
116 |
"summary": "Test summary"
|
117 |
}
|
118 |
+
mock_github.return_value = []
|
119 |
|
120 |
long_job_post = "This is a very long job posting " * 50 # Make it longer than 100 chars
|
121 |
|
122 |
result = gradio.process_inputs(
|
123 |
linkedin_pdf_path="/path/to/resume.pdf",
|
124 |
+
github_username="testuser",
|
125 |
job_post_text=long_job_post,
|
126 |
user_instructions="Custom instructions"
|
127 |
)
|
128 |
|
129 |
# Verify extract_text was called
|
130 |
mock_extract.assert_called_once_with("/path/to/resume.pdf")
|
131 |
+
mock_github.assert_called_once_with("testuser")
|
132 |
|
133 |
+
# Function currently returns empty string
|
134 |
self.assertEqual(result, "")
|
135 |
|
136 |
+
@patch('functions.gradio.extract_text')
|
137 |
+
@patch('functions.gradio.get_github_repositories')
|
138 |
+
def test_process_inputs_github_username_whitespace(self, mock_github, mock_extract):
|
139 |
+
"""Test that github_username is properly stripped of whitespace."""
|
140 |
+
mock_extract.return_value = None
|
141 |
+
mock_github.return_value = []
|
142 |
+
|
143 |
+
result = gradio.process_inputs(
|
144 |
+
linkedin_pdf_path=None,
|
145 |
+
github_username=" testuser ",
|
146 |
+
job_post_text="",
|
147 |
+
user_instructions=""
|
148 |
+
)
|
149 |
+
|
150 |
+
# Verify get_github_repositories was called with stripped username
|
151 |
+
mock_github.assert_called_once_with("testuser")
|
152 |
+
self.assertEqual(result, "")
|
153 |
+
|
154 |
+
@patch('functions.gradio.extract_text')
|
155 |
+
@patch('functions.gradio.get_github_repositories')
|
156 |
+
@patch('logging.getLogger')
|
157 |
+
def test_logging_calls(self, mock_get_logger, mock_github, mock_extract):
|
158 |
+
"""Test that appropriate logging calls are made."""
|
159 |
+
mock_logger = mock_get_logger.return_value
|
160 |
+
mock_extract.return_value = {"test": "data"}
|
161 |
+
mock_github.return_value = [{"name": "repo"}]
|
162 |
+
|
163 |
+
gradio.process_inputs(
|
164 |
+
linkedin_pdf_path="/path/to/resume.pdf",
|
165 |
+
github_username="testuser",
|
166 |
+
job_post_text="Job description here",
|
167 |
+
user_instructions="Custom instructions"
|
168 |
+
)
|
169 |
+
|
170 |
+
# Verify logging calls were made
|
171 |
+
mock_logger.info.assert_called()
|
172 |
+
|
173 |
+
@patch('functions.gradio.extract_text')
|
174 |
+
@patch('functions.gradio.get_github_repositories')
|
175 |
+
def test_process_inputs_none_github_username(self, mock_github, mock_extract):
|
176 |
+
"""Test process_inputs with None github_username (should handle gracefully)."""
|
177 |
+
mock_extract.return_value = None
|
178 |
+
mock_github.return_value = None
|
179 |
+
|
180 |
+
# This should raise a TypeError due to the bug in gradio.py
|
181 |
+
# where it tries to slice job_post_text[:100] when job_post_text is None
|
182 |
+
with self.assertRaises(TypeError):
|
183 |
+
gradio.process_inputs(
|
184 |
+
linkedin_pdf_path=None,
|
185 |
+
github_username=None,
|
186 |
+
job_post_text=None,
|
187 |
+
user_instructions=None
|
188 |
+
)
|
189 |
+
|
190 |
+
# extract_text is never called because the error occurs in logging before that
|
191 |
+
|
192 |
|
193 |
if __name__ == '__main__':
|
194 |
unittest.main()
|
tests/test_resumate.py
CHANGED
@@ -12,7 +12,7 @@ class TestResumeGeneration(unittest.TestCase):
|
|
12 |
"""Set up the test case with pre-defined inputs."""
|
13 |
|
14 |
self.linkedin_pdf_path = "tests/test_data/linkedin_profile.pdf"
|
15 |
-
self.
|
16 |
|
17 |
with open('tests/test_data/sample_job.txt', 'r', encoding='utf-8') as f:
|
18 |
self.job_post_text = f.read().strip()
|
@@ -25,7 +25,7 @@ class TestResumeGeneration(unittest.TestCase):
|
|
25 |
|
26 |
result = process_inputs(
|
27 |
linkedin_pdf_path=self.linkedin_pdf_path,
|
28 |
-
|
29 |
job_post_text=self.job_post_text,
|
30 |
user_instructions=self.user_instructions
|
31 |
)
|
|
|
12 |
"""Set up the test case with pre-defined inputs."""
|
13 |
|
14 |
self.linkedin_pdf_path = "tests/test_data/linkedin_profile.pdf"
|
15 |
+
self.github_username = "gperdrizet"
|
16 |
|
17 |
with open('tests/test_data/sample_job.txt', 'r', encoding='utf-8') as f:
|
18 |
self.job_post_text = f.read().strip()
|
|
|
25 |
|
26 |
result = process_inputs(
|
27 |
linkedin_pdf_path=self.linkedin_pdf_path,
|
28 |
+
github_username=self.github_username,
|
29 |
job_post_text=self.job_post_text,
|
30 |
user_instructions=self.user_instructions
|
31 |
)
|