-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_base_module.py
More file actions
66 lines (55 loc) · 2.18 KB
/
test_base_module.py
File metadata and controls
66 lines (55 loc) · 2.18 KB
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
import sys
import os
# Add backend to path
sys.path.append(os.path.join(os.getcwd(), 'backend'))
from services.github_scraper import GitHubScraper
def test_parsing():
scraper = GitHubScraper()
print("Testing URL parsing...")
test_cases = [
("https://github.com/odoo/odoo/tree/18.0/odoo/addons/base", ("odoo/addons", "base", "")),
("https://github.com/odoo/odoo/tree/18.0/addons/account", ("addons", "account", "")),
("account", ("addons", "account", "")),
]
for url, expected in test_cases:
result = scraper.parse_github_url(url)
print(f"URL: {url} -> {result}")
assert result == expected, f"Expected {expected}, got {result}"
print("Parsing tests passed!")
def test_base_listing():
scraper = GitHubScraper()
print("\nTesting listing of 'base' module...")
# Use parent_path='odoo/addons'
files, actual_parent = scraper.get_folder_files("odoo/addons", "base")
print(f"Found {len(files)} files in 'base' using parent 'odoo/addons'")
assert actual_parent == "odoo/addons"
assert len(files) > 0
# Test fallback
print("Testing fallback listing for 'base'...")
files, actual_parent = scraper.get_folder_files("addons", "base")
print(f"Found {len(files)} files in 'base' using fallback from 'addons' to '{actual_parent}'")
assert actual_parent == "odoo/addons"
assert len(files) > 0
print("Listing tests passed!")
def test_content_fetch():
scraper = GitHubScraper()
print("\nTesting content fetch for a single file in 'base'...")
# Fetch just one file
parent_path = "odoo/addons"
addon_name = "base"
file_path = "models/res_partner.py"
content = scraper.get_file_content(parent_path, addon_name, file_path)
print(f"Fetched {len(content)} characters from {file_path}")
assert len(content) > 0
assert "class Partner" in content
print("Content fetch test passed!")
if __name__ == "__main__":
try:
test_parsing()
test_base_listing()
test_content_fetch()
print("\nALL TESTS PASSED!")
except Exception as e:
print(f"\nTEST FAILED: {e}")
import traceback
traceback.print_exc()