Spaces:
Configuration error
Configuration error
Updated tests
Browse files- tests/test_github.py +95 -95
- tests/test_gradio.py +30 -8
tests/test_github.py
CHANGED
@@ -22,12 +22,12 @@ class TestExtractGitHubUsername(unittest.TestCase):
|
|
22 |
("https://github.com/user123", "user123"),
|
23 |
("https://github.com/octocat/Hello-World", "octocat"),
|
24 |
]
|
25 |
-
|
26 |
for url, expected in test_cases:
|
27 |
with self.subTest(url=url):
|
28 |
result = github._extract_github_username(url)
|
29 |
self.assertEqual(result, expected)
|
30 |
-
|
31 |
def test_invalid_github_urls(self):
|
32 |
"""Test handling of invalid GitHub URLs."""
|
33 |
invalid_urls = [
|
@@ -38,12 +38,12 @@ class TestExtractGitHubUsername(unittest.TestCase):
|
|
38 |
"https://github.com/user-with-very-long-name-that-exceeds-github-limit",
|
39 |
None
|
40 |
]
|
41 |
-
|
42 |
for url in invalid_urls:
|
43 |
with self.subTest(url=url):
|
44 |
result = github._extract_github_username(url)
|
45 |
self.assertIsNone(result)
|
46 |
-
|
47 |
def test_username_validation(self):
|
48 |
"""Test username format validation."""
|
49 |
# Valid usernames
|
@@ -52,7 +52,7 @@ class TestExtractGitHubUsername(unittest.TestCase):
|
|
52 |
with self.subTest(username=username):
|
53 |
result = github._extract_github_username(f"github.com/{username}")
|
54 |
self.assertEqual(result, username)
|
55 |
-
|
56 |
# Invalid usernames
|
57 |
invalid_usernames = ["", "a" * 40, "user@name", "user.name"]
|
58 |
for username in invalid_usernames:
|
@@ -63,7 +63,7 @@ class TestExtractGitHubUsername(unittest.TestCase):
|
|
63 |
|
64 |
class TestGetGitHubUserInfo(unittest.TestCase):
|
65 |
"""Test cases for the _get_github_user_info function."""
|
66 |
-
|
67 |
@patch('requests.get')
|
68 |
def test_successful_user_info(self, mock_get):
|
69 |
"""Test successful user info retrieval."""
|
@@ -75,51 +75,51 @@ class TestGetGitHubUserInfo(unittest.TestCase):
|
|
75 |
"name": "The Octocat"
|
76 |
}
|
77 |
mock_get.return_value = mock_response
|
78 |
-
|
79 |
result = github._get_github_user_info("octocat")
|
80 |
-
|
81 |
self.assertEqual(result["status"], "success")
|
82 |
self.assertIn("data", result)
|
83 |
self.assertEqual(result["data"]["login"], "octocat")
|
84 |
-
|
85 |
@patch('requests.get')
|
86 |
def test_user_not_found(self, mock_get):
|
87 |
"""Test handling of non-existent user."""
|
88 |
mock_response = MagicMock()
|
89 |
mock_response.status_code = 404
|
90 |
mock_get.return_value = mock_response
|
91 |
-
|
92 |
result = github._get_github_user_info("nonexistentuser")
|
93 |
-
|
94 |
self.assertEqual(result["status"], "error")
|
95 |
self.assertIn("not found", result["message"])
|
96 |
-
|
97 |
@patch('requests.get')
|
98 |
def test_rate_limit_exceeded(self, mock_get):
|
99 |
"""Test handling of rate limit exceeded."""
|
100 |
mock_response = MagicMock()
|
101 |
mock_response.status_code = 403
|
102 |
mock_get.return_value = mock_response
|
103 |
-
|
104 |
result = github._get_github_user_info("octocat")
|
105 |
-
|
106 |
self.assertEqual(result["status"], "error")
|
107 |
self.assertIn("rate limit", result["message"])
|
108 |
-
|
109 |
@patch('requests.get')
|
110 |
def test_network_error(self, mock_get):
|
111 |
"""Test handling of network errors."""
|
112 |
mock_get.side_effect = requests.RequestException("Connection error")
|
113 |
-
|
114 |
result = github._get_github_user_info("octocat")
|
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 test_successful_repository_retrieval(self, mock_get):
|
125 |
"""Test successful repository retrieval."""
|
@@ -135,14 +135,14 @@ class TestGetUserRepositories(unittest.TestCase):
|
|
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 |
@patch('requests.get')
|
147 |
def test_empty_repository_list(self, mock_get):
|
148 |
"""Test handling of empty repository list."""
|
@@ -150,28 +150,28 @@ class TestGetUserRepositories(unittest.TestCase):
|
|
150 |
mock_response.status_code = 200
|
151 |
mock_response.json.return_value = []
|
152 |
mock_get.return_value = mock_response
|
153 |
-
|
154 |
result = github._get_user_repositories("octocat")
|
155 |
-
|
156 |
self.assertEqual(result["status"], "success")
|
157 |
self.assertEqual(len(result["data"]), 0)
|
158 |
-
|
159 |
@patch('requests.get')
|
160 |
def test_api_error(self, mock_get):
|
161 |
"""Test handling of API errors."""
|
162 |
mock_response = MagicMock()
|
163 |
mock_response.status_code = 500
|
164 |
mock_get.return_value = mock_response
|
165 |
-
|
166 |
result = github._get_user_repositories("octocat")
|
167 |
-
|
168 |
self.assertEqual(result["status"], "error")
|
169 |
self.assertIn("GitHub API error", result["message"])
|
170 |
|
171 |
|
172 |
class TestProcessRepositoryData(unittest.TestCase):
|
173 |
"""Test cases for the _process_repository_data function."""
|
174 |
-
|
175 |
def test_basic_processing(self):
|
176 |
"""Test basic repository data processing."""
|
177 |
raw_repos = [
|
@@ -187,9 +187,9 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
187 |
"fork": False
|
188 |
}
|
189 |
]
|
190 |
-
|
191 |
result = github._process_repository_data(raw_repos)
|
192 |
-
|
193 |
self.assertEqual(len(result), 1)
|
194 |
processed_repo = result[0]
|
195 |
self.assertEqual(processed_repo["name"], "test-repo")
|
@@ -198,7 +198,7 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
198 |
self.assertEqual(processed_repo["stars"], 10)
|
199 |
self.assertEqual(processed_repo["forks"], 5)
|
200 |
self.assertFalse(processed_repo["is_fork"])
|
201 |
-
|
202 |
def test_fork_filtering(self):
|
203 |
"""Test filtering of unmodified forks."""
|
204 |
raw_repos = [
|
@@ -218,16 +218,16 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
218 |
"stargazers_count": 3
|
219 |
}
|
220 |
]
|
221 |
-
|
222 |
result = github._process_repository_data(raw_repos)
|
223 |
-
|
224 |
# Should include original repo and modified fork, exclude unmodified fork
|
225 |
self.assertEqual(len(result), 2)
|
226 |
repo_names = [repo["name"] for repo in result]
|
227 |
self.assertIn("original-repo", repo_names)
|
228 |
self.assertIn("modified-fork", repo_names)
|
229 |
self.assertNotIn("unmodified-fork", repo_names)
|
230 |
-
|
231 |
def test_missing_fields(self):
|
232 |
"""Test handling of missing fields in repository data."""
|
233 |
raw_repos = [
|
@@ -236,9 +236,9 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
236 |
# Missing most optional fields
|
237 |
}
|
238 |
]
|
239 |
-
|
240 |
result = github._process_repository_data(raw_repos)
|
241 |
-
|
242 |
self.assertEqual(len(result), 1)
|
243 |
processed_repo = result[0]
|
244 |
self.assertEqual(processed_repo["name"], "minimal-repo")
|
@@ -250,17 +250,17 @@ class TestProcessRepositoryData(unittest.TestCase):
|
|
250 |
|
251 |
class TestGetGitHubRepositories(unittest.TestCase):
|
252 |
"""Test cases for the get_github_repositories function."""
|
253 |
-
|
254 |
def test_empty_url(self):
|
255 |
"""Test handling of empty or None URL."""
|
256 |
test_cases = [None, "", " "]
|
257 |
-
|
258 |
for url in test_cases:
|
259 |
with self.subTest(url=url):
|
260 |
result = github.get_github_repositories(url)
|
261 |
self.assertEqual(result["status"], "error")
|
262 |
self.assertIn("No GitHub URL provided", result["message"])
|
263 |
-
|
264 |
@patch('functions.github._get_user_repositories')
|
265 |
@patch('functions.github._get_github_user_info')
|
266 |
@patch('functions.github._extract_github_username')
|
@@ -275,25 +275,25 @@ class TestGetGitHubRepositories(unittest.TestCase):
|
|
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 = {
|
@@ -315,28 +315,28 @@ class TestFormatRepositoriesForLLM(unittest.TestCase):
|
|
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 = {
|
@@ -344,12 +344,12 @@ class TestFormatRepositoriesForLLM(unittest.TestCase):
|
|
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 = []
|
@@ -364,15 +364,15 @@ class TestFormatRepositoriesForLLM(unittest.TestCase):
|
|
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
|
@@ -384,7 +384,7 @@ class TestFormatRepositoriesForLLM(unittest.TestCase):
|
|
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 = [
|
@@ -395,13 +395,13 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
395 |
"https://github.com/user",
|
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):
|
@@ -411,12 +411,12 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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')
|
@@ -424,13 +424,13 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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",
|
@@ -463,23 +463,23 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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": [
|
@@ -492,7 +492,7 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
492 |
}
|
493 |
]
|
494 |
}
|
495 |
-
|
496 |
mock_contributors.return_value = {
|
497 |
"status": "success",
|
498 |
"data": [
|
@@ -504,15 +504,15 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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")
|
@@ -520,7 +520,7 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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"])
|
@@ -529,13 +529,13 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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 = [
|
@@ -545,12 +545,12 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
545 |
("github.com/test/example", ("test", "example")),
|
546 |
("https://github.com/user/repo/issues", ("user", "repo")),
|
547 |
]
|
548 |
-
|
549 |
for url, expected in test_cases:
|
550 |
with self.subTest(url=url):
|
551 |
result = github._extract_repo_info(url)
|
552 |
self.assertEqual(result, expected)
|
553 |
-
|
554 |
def test_extract_repo_info_invalid_urls(self):
|
555 |
"""Test _extract_repo_info with invalid repository URLs."""
|
556 |
invalid_urls = [
|
@@ -560,12 +560,12 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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."""
|
@@ -576,25 +576,25 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
576 |
"full_name": "user/test-repo"
|
577 |
}
|
578 |
mock_get.return_value = mock_response
|
579 |
-
|
580 |
result = github._get_repository_info("user", "test-repo")
|
581 |
-
|
582 |
self.assertEqual(result["status"], "success")
|
583 |
self.assertIn("data", result)
|
584 |
self.assertEqual(result["data"]["name"], "test-repo")
|
585 |
-
|
586 |
@patch('requests.get')
|
587 |
def test_get_repository_info_not_found(self, mock_get):
|
588 |
"""Test _get_repository_info with 404 response."""
|
589 |
mock_response = MagicMock()
|
590 |
mock_response.status_code = 404
|
591 |
mock_get.return_value = mock_response
|
592 |
-
|
593 |
result = github._get_repository_info("user", "nonexistent")
|
594 |
-
|
595 |
self.assertEqual(result["status"], "error")
|
596 |
self.assertIn("not found", result["message"])
|
597 |
-
|
598 |
@patch('requests.get')
|
599 |
def test_get_repository_languages_success(self, mock_get):
|
600 |
"""Test _get_repository_languages with successful response."""
|
@@ -606,13 +606,13 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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."""
|
@@ -622,19 +622,19 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
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."""
|
@@ -647,9 +647,9 @@ class TestGetRepositoryDetails(unittest.TestCase):
|
|
647 |
{"name": "tests", "type": "dir"}
|
648 |
]
|
649 |
mock_get.return_value = mock_response
|
650 |
-
|
651 |
result = github._get_repository_contents("user", "repo")
|
652 |
-
|
653 |
self.assertEqual(result["status"], "success")
|
654 |
expected_structure = ["src/", "tests/", "README.md", "setup.py"]
|
655 |
self.assertEqual(result["data"], expected_structure)
|
|
|
22 |
("https://github.com/user123", "user123"),
|
23 |
("https://github.com/octocat/Hello-World", "octocat"),
|
24 |
]
|
25 |
+
|
26 |
for url, expected in test_cases:
|
27 |
with self.subTest(url=url):
|
28 |
result = github._extract_github_username(url)
|
29 |
self.assertEqual(result, expected)
|
30 |
+
|
31 |
def test_invalid_github_urls(self):
|
32 |
"""Test handling of invalid GitHub URLs."""
|
33 |
invalid_urls = [
|
|
|
38 |
"https://github.com/user-with-very-long-name-that-exceeds-github-limit",
|
39 |
None
|
40 |
]
|
41 |
+
|
42 |
for url in invalid_urls:
|
43 |
with self.subTest(url=url):
|
44 |
result = github._extract_github_username(url)
|
45 |
self.assertIsNone(result)
|
46 |
+
|
47 |
def test_username_validation(self):
|
48 |
"""Test username format validation."""
|
49 |
# 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 |
# Invalid usernames
|
57 |
invalid_usernames = ["", "a" * 40, "user@name", "user.name"]
|
58 |
for username in invalid_usernames:
|
|
|
63 |
|
64 |
class TestGetGitHubUserInfo(unittest.TestCase):
|
65 |
"""Test cases for the _get_github_user_info function."""
|
66 |
+
|
67 |
@patch('requests.get')
|
68 |
def test_successful_user_info(self, mock_get):
|
69 |
"""Test successful user info retrieval."""
|
|
|
75 |
"name": "The Octocat"
|
76 |
}
|
77 |
mock_get.return_value = mock_response
|
78 |
+
|
79 |
result = github._get_github_user_info("octocat")
|
80 |
+
|
81 |
self.assertEqual(result["status"], "success")
|
82 |
self.assertIn("data", result)
|
83 |
self.assertEqual(result["data"]["login"], "octocat")
|
84 |
+
|
85 |
@patch('requests.get')
|
86 |
def test_user_not_found(self, mock_get):
|
87 |
"""Test handling of non-existent user."""
|
88 |
mock_response = MagicMock()
|
89 |
mock_response.status_code = 404
|
90 |
mock_get.return_value = mock_response
|
91 |
+
|
92 |
result = github._get_github_user_info("nonexistentuser")
|
93 |
+
|
94 |
self.assertEqual(result["status"], "error")
|
95 |
self.assertIn("not found", result["message"])
|
96 |
+
|
97 |
@patch('requests.get')
|
98 |
def test_rate_limit_exceeded(self, mock_get):
|
99 |
"""Test handling of rate limit exceeded."""
|
100 |
mock_response = MagicMock()
|
101 |
mock_response.status_code = 403
|
102 |
mock_get.return_value = mock_response
|
103 |
+
|
104 |
result = github._get_github_user_info("octocat")
|
105 |
+
|
106 |
self.assertEqual(result["status"], "error")
|
107 |
self.assertIn("rate limit", result["message"])
|
108 |
+
|
109 |
@patch('requests.get')
|
110 |
def test_network_error(self, mock_get):
|
111 |
"""Test handling of network errors."""
|
112 |
mock_get.side_effect = requests.RequestException("Connection error")
|
113 |
+
|
114 |
result = github._get_github_user_info("octocat")
|
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 test_successful_repository_retrieval(self, mock_get):
|
125 |
"""Test successful repository retrieval."""
|
|
|
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 |
@patch('requests.get')
|
147 |
def test_empty_repository_list(self, mock_get):
|
148 |
"""Test handling of empty repository list."""
|
|
|
150 |
mock_response.status_code = 200
|
151 |
mock_response.json.return_value = []
|
152 |
mock_get.return_value = mock_response
|
153 |
+
|
154 |
result = github._get_user_repositories("octocat")
|
155 |
+
|
156 |
self.assertEqual(result["status"], "success")
|
157 |
self.assertEqual(len(result["data"]), 0)
|
158 |
+
|
159 |
@patch('requests.get')
|
160 |
def test_api_error(self, mock_get):
|
161 |
"""Test handling of API errors."""
|
162 |
mock_response = MagicMock()
|
163 |
mock_response.status_code = 500
|
164 |
mock_get.return_value = mock_response
|
165 |
+
|
166 |
result = github._get_user_repositories("octocat")
|
167 |
+
|
168 |
self.assertEqual(result["status"], "error")
|
169 |
self.assertIn("GitHub API error", result["message"])
|
170 |
|
171 |
|
172 |
class TestProcessRepositoryData(unittest.TestCase):
|
173 |
"""Test cases for the _process_repository_data function."""
|
174 |
+
|
175 |
def test_basic_processing(self):
|
176 |
"""Test basic repository data processing."""
|
177 |
raw_repos = [
|
|
|
187 |
"fork": False
|
188 |
}
|
189 |
]
|
190 |
+
|
191 |
result = github._process_repository_data(raw_repos)
|
192 |
+
|
193 |
self.assertEqual(len(result), 1)
|
194 |
processed_repo = result[0]
|
195 |
self.assertEqual(processed_repo["name"], "test-repo")
|
|
|
198 |
self.assertEqual(processed_repo["stars"], 10)
|
199 |
self.assertEqual(processed_repo["forks"], 5)
|
200 |
self.assertFalse(processed_repo["is_fork"])
|
201 |
+
|
202 |
def test_fork_filtering(self):
|
203 |
"""Test filtering of unmodified forks."""
|
204 |
raw_repos = [
|
|
|
218 |
"stargazers_count": 3
|
219 |
}
|
220 |
]
|
221 |
+
|
222 |
result = github._process_repository_data(raw_repos)
|
223 |
+
|
224 |
# Should include original repo and modified fork, exclude unmodified fork
|
225 |
self.assertEqual(len(result), 2)
|
226 |
repo_names = [repo["name"] for repo in result]
|
227 |
self.assertIn("original-repo", repo_names)
|
228 |
self.assertIn("modified-fork", repo_names)
|
229 |
self.assertNotIn("unmodified-fork", repo_names)
|
230 |
+
|
231 |
def test_missing_fields(self):
|
232 |
"""Test handling of missing fields in repository data."""
|
233 |
raw_repos = [
|
|
|
236 |
# Missing most optional fields
|
237 |
}
|
238 |
]
|
239 |
+
|
240 |
result = github._process_repository_data(raw_repos)
|
241 |
+
|
242 |
self.assertEqual(len(result), 1)
|
243 |
processed_repo = result[0]
|
244 |
self.assertEqual(processed_repo["name"], "minimal-repo")
|
|
|
250 |
|
251 |
class TestGetGitHubRepositories(unittest.TestCase):
|
252 |
"""Test cases for the get_github_repositories function."""
|
253 |
+
|
254 |
def test_empty_url(self):
|
255 |
"""Test handling of empty or None URL."""
|
256 |
test_cases = [None, "", " "]
|
257 |
+
|
258 |
for url in test_cases:
|
259 |
with self.subTest(url=url):
|
260 |
result = github.get_github_repositories(url)
|
261 |
self.assertEqual(result["status"], "error")
|
262 |
self.assertIn("No GitHub URL provided", result["message"])
|
263 |
+
|
264 |
@patch('functions.github._get_user_repositories')
|
265 |
@patch('functions.github._get_github_user_info')
|
266 |
@patch('functions.github._extract_github_username')
|
|
|
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 = {
|
|
|
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 = {
|
|
|
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 = []
|
|
|
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
|
|
|
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 = [
|
|
|
395 |
"https://github.com/user",
|
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):
|
|
|
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')
|
|
|
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",
|
|
|
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": [
|
|
|
492 |
}
|
493 |
]
|
494 |
}
|
495 |
+
|
496 |
mock_contributors.return_value = {
|
497 |
"status": "success",
|
498 |
"data": [
|
|
|
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")
|
|
|
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"])
|
|
|
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 = [
|
|
|
545 |
("github.com/test/example", ("test", "example")),
|
546 |
("https://github.com/user/repo/issues", ("user", "repo")),
|
547 |
]
|
548 |
+
|
549 |
for url, expected in test_cases:
|
550 |
with self.subTest(url=url):
|
551 |
result = github._extract_repo_info(url)
|
552 |
self.assertEqual(result, expected)
|
553 |
+
|
554 |
def test_extract_repo_info_invalid_urls(self):
|
555 |
"""Test _extract_repo_info with invalid repository URLs."""
|
556 |
invalid_urls = [
|
|
|
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."""
|
|
|
576 |
"full_name": "user/test-repo"
|
577 |
}
|
578 |
mock_get.return_value = mock_response
|
579 |
+
|
580 |
result = github._get_repository_info("user", "test-repo")
|
581 |
+
|
582 |
self.assertEqual(result["status"], "success")
|
583 |
self.assertIn("data", result)
|
584 |
self.assertEqual(result["data"]["name"], "test-repo")
|
585 |
+
|
586 |
@patch('requests.get')
|
587 |
def test_get_repository_info_not_found(self, mock_get):
|
588 |
"""Test _get_repository_info with 404 response."""
|
589 |
mock_response = MagicMock()
|
590 |
mock_response.status_code = 404
|
591 |
mock_get.return_value = mock_response
|
592 |
+
|
593 |
result = github._get_repository_info("user", "nonexistent")
|
594 |
+
|
595 |
self.assertEqual(result["status"], "error")
|
596 |
self.assertIn("not found", result["message"])
|
597 |
+
|
598 |
@patch('requests.get')
|
599 |
def test_get_repository_languages_success(self, mock_get):
|
600 |
"""Test _get_repository_languages with successful response."""
|
|
|
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."""
|
|
|
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."""
|
|
|
647 |
{"name": "tests", "type": "dir"}
|
648 |
]
|
649 |
mock_get.return_value = mock_response
|
650 |
+
|
651 |
result = github._get_repository_contents("user", "repo")
|
652 |
+
|
653 |
self.assertEqual(result["status"], "success")
|
654 |
expected_structure = ["src/", "tests/", "README.md", "setup.py"]
|
655 |
self.assertEqual(result["data"], expected_structure)
|
tests/test_gradio.py
CHANGED
@@ -20,7 +20,8 @@ class TestProcessInputs(unittest.TestCase):
|
|
20 |
|
21 |
self.assertIn("❌ No LinkedIn resume PDF file uploaded", result)
|
22 |
self.assertIn("✅ Using default GitHub Profile URL", result)
|
23 |
-
self.assertIn("
|
|
|
24 |
self.assertIn("ℹ️ No additional instructions provided", result)
|
25 |
self.assertIn("❌ Cannot generate resume: No valid LinkedIn data extracted", result)
|
26 |
|
@@ -159,7 +160,8 @@ class TestProcessInputs(unittest.TestCase):
|
|
159 |
|
160 |
self.assertIn("❌ No LinkedIn resume PDF file uploaded", result)
|
161 |
self.assertIn("✅ Using default GitHub Profile URL", result)
|
162 |
-
self.assertIn("
|
|
|
163 |
self.assertIn("ℹ️ No additional instructions provided", result)
|
164 |
self.assertIn("❌ Cannot generate resume: No valid LinkedIn data extracted", result)
|
165 |
|
@@ -247,8 +249,25 @@ class TestProcessInputs(unittest.TestCase):
|
|
247 |
class TestGetProcessedData(unittest.TestCase):
|
248 |
"""Test cases for the get_processed_data function."""
|
249 |
|
250 |
-
|
|
|
251 |
"""Test with no inputs provided."""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
252 |
|
253 |
result = gradio.get_processed_data(None, "", "", "")
|
254 |
|
@@ -358,20 +377,23 @@ class TestGetProcessedData(unittest.TestCase):
|
|
358 |
self.assertIn("LinkedIn: LinkedIn error", result["errors"])
|
359 |
self.assertIn("GitHub: GitHub error", result["errors"])
|
360 |
|
361 |
-
|
|
|
362 |
"""Test job post whitespace handling."""
|
|
|
|
|
363 |
|
364 |
# Test with leading/trailing whitespace
|
365 |
result = gradio.get_processed_data(None, "", " Job content ", "")
|
366 |
self.assertEqual(result["job_post"], "Job content")
|
367 |
|
368 |
-
# Test with only whitespace
|
369 |
result = gradio.get_processed_data(None, "", " ", "")
|
370 |
-
self.
|
371 |
|
372 |
-
# Test with empty string
|
373 |
result = gradio.get_processed_data(None, "", "", "")
|
374 |
-
self.
|
375 |
|
376 |
def test_github_url_whitespace_handling(self):
|
377 |
"""Test GitHub URL whitespace handling."""
|
|
|
20 |
|
21 |
self.assertIn("❌ No LinkedIn resume PDF file uploaded", result)
|
22 |
self.assertIn("✅ Using default GitHub Profile URL", result)
|
23 |
+
self.assertIn("ℹ️ No job post provided, attempting to use default", result)
|
24 |
+
self.assertIn("✅ Using default job post", result)
|
25 |
self.assertIn("ℹ️ No additional instructions provided", result)
|
26 |
self.assertIn("❌ Cannot generate resume: No valid LinkedIn data extracted", result)
|
27 |
|
|
|
160 |
|
161 |
self.assertIn("❌ No LinkedIn resume PDF file uploaded", result)
|
162 |
self.assertIn("✅ Using default GitHub Profile URL", result)
|
163 |
+
self.assertIn("ℹ️ No job post provided, attempting to use default", result)
|
164 |
+
self.assertIn("✅ Using default job post", result)
|
165 |
self.assertIn("ℹ️ No additional instructions provided", result)
|
166 |
self.assertIn("❌ Cannot generate resume: No valid LinkedIn data extracted", result)
|
167 |
|
|
|
249 |
class TestGetProcessedData(unittest.TestCase):
|
250 |
"""Test cases for the get_processed_data function."""
|
251 |
|
252 |
+
@patch('functions.gradio.load_default_job_call')
|
253 |
+
def test_no_inputs(self, mock_load_default):
|
254 |
"""Test with no inputs provided."""
|
255 |
+
# Mock the default job call loading
|
256 |
+
mock_load_default.return_value = "Default job call content from sample_job.txt"
|
257 |
+
|
258 |
+
result = gradio.get_processed_data(None, "", "", "")
|
259 |
+
|
260 |
+
self.assertIsNone(result["linkedin"])
|
261 |
+
self.assertIsNone(result["github"])
|
262 |
+
self.assertEqual(result["job_post"], "Default job call content from sample_job.txt")
|
263 |
+
self.assertIsNone(result["user_instructions"])
|
264 |
+
self.assertEqual(len(result["errors"]), 0)
|
265 |
+
|
266 |
+
@patch('functions.gradio.load_default_job_call')
|
267 |
+
def test_no_inputs_no_default_job(self, mock_load_default):
|
268 |
+
"""Test with no inputs provided and no default job available."""
|
269 |
+
# Mock the default job call loading to return None
|
270 |
+
mock_load_default.return_value = None
|
271 |
|
272 |
result = gradio.get_processed_data(None, "", "", "")
|
273 |
|
|
|
377 |
self.assertIn("LinkedIn: LinkedIn error", result["errors"])
|
378 |
self.assertIn("GitHub: GitHub error", result["errors"])
|
379 |
|
380 |
+
@patch('functions.gradio.load_default_job_call')
|
381 |
+
def test_job_post_whitespace_handling(self, mock_load_default):
|
382 |
"""Test job post whitespace handling."""
|
383 |
+
# Mock the default job call loading
|
384 |
+
mock_load_default.return_value = "Default job content"
|
385 |
|
386 |
# Test with leading/trailing whitespace
|
387 |
result = gradio.get_processed_data(None, "", " Job content ", "")
|
388 |
self.assertEqual(result["job_post"], "Job content")
|
389 |
|
390 |
+
# Test with only whitespace - should load default
|
391 |
result = gradio.get_processed_data(None, "", " ", "")
|
392 |
+
self.assertEqual(result["job_post"], "Default job content")
|
393 |
|
394 |
+
# Test with empty string - should load default
|
395 |
result = gradio.get_processed_data(None, "", "", "")
|
396 |
+
self.assertEqual(result["job_post"], "Default job content")
|
397 |
|
398 |
def test_github_url_whitespace_handling(self):
|
399 |
"""Test GitHub URL whitespace handling."""
|