-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_basic.py
More file actions
165 lines (140 loc) · 5.11 KB
/
Copy pathtest_basic.py
File metadata and controls
165 lines (140 loc) · 5.11 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
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
"""
Basic test for French Rental Scanner - without actual web scraping
"""
import sys
import os
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
def test_imports():
"""Test that all modules import correctly"""
print("[*] Testing imports...")
try:
from scraper.base import BaseScraper
from scraper.bienici import BieniciScraper
from scraper.seloger import SeLogerScraper
from scraper.leboncoin import LeBonCoinScraper
from database.models import Base, Listing
from database.connection import DatabaseManager
print(" [OK] All imports successful")
return True
except Exception as e:
print(f" [FAIL] Import failed: {e}")
import traceback
traceback.print_exc()
return False
def test_database():
"""Test database functionality"""
print("\n[*] Testing database...")
try:
from database.connection import DatabaseManager
# Create test database
db = DatabaseManager("test_rental.db")
print(" [OK] Database initialized")
# Test adding a listing
test_listing = {
'listing_id': 'test_001',
'source': 'SeLoger',
'url': 'https://example.com/listing/1',
'title': 'Beautiful Apartment in Paris',
'description': 'A lovely 2BR apartment in the heart of Paris',
'price': 1500.0,
'area': 65.0,
'location': 'Paris 11eme',
'city': 'Paris',
'property_type': 'apartment',
'features': ['Elevator', 'Balcony', 'Near Metro'],
'images': ['https://example.com/image1.jpg']
}
listing = db.add_listing(test_listing)
if listing:
print(" [OK] Test listing added to database")
else:
print(" [FAIL] Failed to add test listing")
return False
# Test getting listings
listings = db.get_listings(limit=5)
if listings:
print(f" [OK] Retrieved {len(listings)} listings from database")
for lst in listings:
print(f" - {lst.title}: {lst.price}EUR in {lst.location}")
else:
print(" [WARN] No listings found in database")
# Test stats
stats = db.get_stats()
print(f" [OK] Database stats: {stats['total_listings']} total listings")
return True
except Exception as e:
print(f" [FAIL] Database test failed: {e}")
import traceback
traceback.print_exc()
return False
def test_scraper_init():
"""Test scraper initialization"""
print("\n[*] Testing scrapers...")
try:
from scraper.bienici import BieniciScraper
from scraper.seloger import SeLogerScraper
from scraper.leboncoin import LeBonCoinScraper
bienici = BieniciScraper()
print(" [OK] Bien'ici scraper initialized")
print(f" Name: {bienici.name}")
print(f" Base URL: {bienici.BASE_URL}")
seloger = SeLogerScraper()
print(" [OK] SeLoger scraper initialized")
print(f" Name: {seloger.name}")
print(f" Base URL: {seloger.BASE_URL}")
leboncoin = LeBonCoinScraper()
print(" [OK] LeBonCoin scraper initialized")
print(f" Name: {leboncoin.name}")
print(f" Base URL: {leboncoin.BASE_URL}")
return True
except Exception as e:
print(f" [FAIL] Scraper init failed: {e}")
import traceback
traceback.print_exc()
return False
def test_main_module():
"""Test main module"""
print("\n[*] Testing main module...")
try:
import main
print(" [OK] Main module loaded")
print(f" Module file: {main.__file__}")
return True
except Exception as e:
print(f" [FAIL] Main module failed: {e}")
return False
def main_test():
"""Run all tests"""
print("=" * 60)
print("French Rental Scanner - Basic Tests")
print("=" * 60)
results = []
# Run tests
results.append(("Imports", test_imports()))
results.append(("Database", test_database()))
results.append(("Scrapers", test_scraper_init()))
results.append(("Main Module", test_main_module()))
# Summary
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
passed = sum(1 for _, result in results if result)
total = len(results)
for test_name, result in results:
status = "[PASS]" if result else "[FAIL]"
print(f"{test_name:20s} {status}")
print("-" * 60)
print(f"Total: {passed}/{total} tests passed")
if passed == total:
print("\n[SUCCESS] All tests passed!")
print("\nThe tool is ready to use!")
print("\nNext steps:")
print("1. Test with real data: python main.py scan --location Huningue")
print("2. Launch dashboard: python main.py dashboard")
return True
else:
print("\n[WARNING] Some tests failed. Please fix the errors above.")
return False
if __name__ == "__main__":
success = main_test()
sys.exit(0 if success else 1)