changed image version; small typos
All checks were successful
Build Docker Image / build (push) Successful in 2m31s

This commit is contained in:
Tudor Sitaru
2025-10-23 17:00:25 +01:00
parent e8df11bc16
commit acfb22cbea
6 changed files with 149 additions and 116 deletions

View File

@@ -44,7 +44,7 @@ class SnapshotDownloaderTester:
"date_to": "2024-01-31", # Small range for testing
"max_pages": 2, # Limit for testing
"email": self.email,
"password": self.password
"password": self.password,
}
config.update(kwargs)
return config
@@ -59,9 +59,7 @@ class SnapshotDownloaderTester:
print("1. Testing basic initialization...")
downloader = SnapshotDownloader(
output_dir=temp_dir,
email=self.email,
password=self.password
output_dir=temp_dir, email=self.email, password=self.password
)
# Check initialization
@@ -77,7 +75,7 @@ class SnapshotDownloaderTester:
print(" ❌ Email not set correctly")
return False
if downloader.stats['total_snapshots'] == 0:
if downloader.stats["total_snapshots"] == 0:
print(" ✅ Statistics initialized correctly")
else:
print(" ❌ Statistics not initialized correctly")
@@ -85,8 +83,7 @@ class SnapshotDownloaderTester:
print("\n2. Testing with API key...")
downloader_api = SnapshotDownloader(
output_dir=temp_dir,
api_key=self.api_key
output_dir=temp_dir, api_key=self.api_key
)
if downloader_api.api_key == self.api_key:
@@ -107,13 +104,10 @@ class SnapshotDownloaderTester:
with tempfile.TemporaryDirectory() as temp_dir:
print("1. Testing API key headers...")
downloader = SnapshotDownloader(
output_dir=temp_dir,
api_key=self.api_key
)
downloader = SnapshotDownloader(output_dir=temp_dir, api_key=self.api_key)
headers = downloader.get_auth_headers()
if 'x-api-key' in headers and headers['x-api-key'] == self.api_key:
if "x-api-key" in headers and headers["x-api-key"] == self.api_key:
print(" ✅ API key header set correctly")
else:
print(" ❌ API key header not set correctly")
@@ -121,8 +115,13 @@ class SnapshotDownloaderTester:
print("\n2. Testing standard headers...")
expected_headers = [
'accept', 'accept-language', 'origin', 'user-agent',
'sec-fetch-dest', 'sec-fetch-mode', 'sec-fetch-site'
"accept",
"accept-language",
"origin",
"user-agent",
"sec-fetch-dest",
"sec-fetch-mode",
"sec-fetch-site",
]
for header in expected_headers:
@@ -145,22 +144,23 @@ class SnapshotDownloaderTester:
print("1. Testing login authentication...")
downloader = SnapshotDownloader(
output_dir=temp_dir,
email=self.email,
password=self.password
output_dir=temp_dir, email=self.email, password=self.password
)
try:
await downloader.authenticate()
if downloader.auth_manager and downloader.auth_manager.is_authenticated():
if (
downloader.auth_manager
and downloader.auth_manager.is_authenticated()
):
print(" ✅ Login authentication successful")
# Check if API key was obtained
headers = downloader.get_auth_headers()
if 'x-api-key' in headers:
if "x-api-key" in headers:
print(" ✅ API key obtained from authentication")
obtained_key = headers['x-api-key']
obtained_key = headers["x-api-key"]
if obtained_key:
print(f" ✅ API key: {obtained_key[:20]}...")
else:
@@ -222,7 +222,7 @@ class SnapshotDownloaderTester:
date_from="2024-01-01",
date_to="2024-01-31",
page=1,
per_page=100
per_page=100,
)
except Exception as e:
# Expected - we just want to capture the URL
@@ -285,21 +285,12 @@ class SnapshotDownloaderTester:
"content": "This is a test snapshot with some content & special characters",
"created_at": "2024-01-15T10:30:00Z",
"updated_at": "2024-01-15T10:30:00Z",
"author": {
"name": "Test Author"
},
"child": {
"name": "Test Child"
},
"activity": {
"name": "Test Activity"
},
"author": {"name": "Test Author"},
"child": {"name": "Test Child"},
"activity": {"name": "Test Activity"},
"images": [
{
"url": "https://example.com/image1.jpg",
"name": "Test Image"
}
]
{"url": "https://example.com/image1.jpg", "name": "Test Image"}
],
}
html = downloader.format_snapshot_html(mock_snapshot)
@@ -389,7 +380,7 @@ class SnapshotDownloaderTester:
config_data = self.create_test_config(temp_dir)
config_file = Path(temp_dir) / "test_config.json"
with open(config_file, 'w') as f:
with open(config_file, "w") as f:
json.dump(config_data, f, indent=2)
# Test config loading
@@ -398,7 +389,7 @@ class SnapshotDownloaderTester:
print(" ✅ Configuration loaded successfully")
# Check if underlying downloader was created
if hasattr(config_downloader, 'downloader'):
if hasattr(config_downloader, "downloader"):
print(" ✅ Underlying downloader created")
else:
print(" ❌ Underlying downloader not created")
@@ -412,12 +403,12 @@ class SnapshotDownloaderTester:
# Test invalid config (missing auth)
invalid_config = config_data.copy()
del invalid_config['email']
del invalid_config['password']
del invalid_config["email"]
del invalid_config["password"]
# Don't set api_key either
invalid_config_file = Path(temp_dir) / "invalid_config.json"
with open(invalid_config_file, 'w') as f:
with open(invalid_config_file, "w") as f:
json.dump(invalid_config, f, indent=2)
try:
@@ -449,7 +440,7 @@ class SnapshotDownloaderTester:
("2024-01-15T10:30:00.123Z", "2024-01-15 10:30:00"),
("2024-01-15T10:30:00+00:00", "2024-01-15 10:30:00"),
("invalid-date", "invalid-date"), # Should pass through unchanged
("", "") # Should handle empty string
("", ""), # Should handle empty string
]
for input_date, expected_prefix in test_dates:
@@ -484,18 +475,18 @@ class SnapshotDownloaderTester:
# Page 1
{
"data": [{"id": "snap1"}, {"id": "snap2"}],
"pagination": {"current_page": 1, "last_page": 3}
"pagination": {"current_page": 1, "last_page": 3},
},
# Page 2
{
"data": [{"id": "snap3"}, {"id": "snap4"}],
"pagination": {"current_page": 2, "last_page": 3}
"pagination": {"current_page": 2, "last_page": 3},
},
# Page 3
{
"data": [{"id": "snap5"}],
"pagination": {"current_page": 3, "last_page": 3}
}
"pagination": {"current_page": 3, "last_page": 3},
},
]
async def get(self, url, headers=None, timeout=None):
@@ -523,10 +514,12 @@ class SnapshotDownloaderTester:
# Override the fetch_snapshots_page method to use our mock
original_method = downloader.fetch_snapshots_page
async def mock_fetch_page(session, type_ids, date_from, date_to, page, per_page):
async def mock_fetch_page(
session, type_ids, date_from, date_to, page, per_page
):
response_data = mock_session.pages[page - 1]
mock_session.call_count += 1
downloader.stats['pages_fetched'] += 1
downloader.stats["pages_fetched"] += 1
return response_data
downloader.fetch_snapshots_page = mock_fetch_page
@@ -543,14 +536,16 @@ class SnapshotDownloaderTester:
print(f" ❌ Expected 5 snapshots, got {len(snapshots)}")
return False
if downloader.stats['pages_fetched'] == 3:
if downloader.stats["pages_fetched"] == 3:
print(" ✅ Page count tracked correctly")
else:
print(f" ❌ Expected 3 pages, tracked {downloader.stats['pages_fetched']}")
print(
f" ❌ Expected 3 pages, tracked {downloader.stats['pages_fetched']}"
)
return False
# Test max_pages limit
downloader.stats['pages_fetched'] = 0 # Reset
downloader.stats["pages_fetched"] = 0 # Reset
mock_session.call_count = 0 # Reset
snapshots_limited = await downloader.fetch_all_snapshots(
@@ -560,7 +555,9 @@ class SnapshotDownloaderTester:
if len(snapshots_limited) == 4: # First 2 pages only
print(" ✅ Max pages limit respected")
else:
print(f" ❌ Expected 4 snapshots with limit, got {len(snapshots_limited)}")
print(
f" ❌ Expected 4 snapshots with limit, got {len(snapshots_limited)}"
)
return False
except Exception as e:
@@ -622,7 +619,9 @@ def show_usage_examples():
print("python3 snapshot_downloader.py --email user@example.com --password password")
print()
print("# Specify date range")
print("python3 snapshot_downloader.py --api-key KEY --date-from 2024-01-01 --date-to 2024-12-31")
print(
"python3 snapshot_downloader.py --api-key KEY --date-from 2024-01-01 --date-to 2024-12-31"
)
print()
print("# Limit pages for testing")
print("python3 snapshot_downloader.py --api-key KEY --max-pages 5")
@@ -635,7 +634,9 @@ def show_usage_examples():
print("python3 config_snapshot_downloader.py --config snapshot_config.json")
print()
print("# Show config summary")
print("python3 config_snapshot_downloader.py --config snapshot_config.json --show-config")
print(
"python3 config_snapshot_downloader.py --config snapshot_config.json --show-config"
)
print("\n📄 Features:")
print("• Downloads all snapshots with pagination support")