mirror of
https://github.com/timberjoegithub/GoogleScrape.git
synced 2026-07-22 00:19:48 +00:00
- Remove dead imports/duplication from Google2xls.py and social.py - Centralize shared logic in review_workflow_utils.py - Add focused posting-flow tests in tests/test_social.py (all pass) - Update .gitignore for secrets and local artifacts - Trim requirements.txt to direct deps - Improve CI: compile all scripts, run focused tests - Prep repo for clean commit (no secrets, no local artifacts)
62 lines
1.9 KiB
Python
62 lines
1.9 KiB
Python
import unittest
|
|
from datetime import datetime
|
|
|
|
from review_workflow_utils import (
|
|
build_review_media_path,
|
|
count_google_review_pages,
|
|
normalize_google_media_url,
|
|
normalize_wordpress_date,
|
|
sanitize_review_name,
|
|
)
|
|
|
|
|
|
class FakeElement:
|
|
def __init__(self, text):
|
|
self.text = text
|
|
|
|
|
|
class FakeDriver:
|
|
def __init__(self, text):
|
|
self.text = text
|
|
|
|
def find_element(self, by, value):
|
|
self.last_lookup = (by, value)
|
|
return FakeElement(self.text)
|
|
|
|
|
|
class ReviewWorkflowUtilsTests(unittest.TestCase):
|
|
def test_count_google_review_pages_rounds_up_by_review_page(self):
|
|
driver = FakeDriver("25 reviews")
|
|
|
|
page_count = count_google_review_pages(driver)
|
|
|
|
self.assertEqual(page_count, 3)
|
|
self.assertEqual(driver.last_lookup, ("class name", "Qha3nb"))
|
|
|
|
def test_normalize_wordpress_date_handles_relative_weeks(self):
|
|
publish_date = normalize_wordpress_date("2 weeks ago", now=datetime(2026, 5, 27, 9, 30, 0))
|
|
|
|
self.assertEqual(publish_date, "2026-05-13T22:00:00")
|
|
|
|
def test_normalize_wordpress_date_handles_month_year_strings(self):
|
|
publish_date = normalize_wordpress_date("Jan 2025")
|
|
|
|
self.assertEqual(publish_date, "2025-01-01T22:00:00")
|
|
|
|
def test_normalize_google_media_url_strips_thumbnail_suffix(self):
|
|
style_text = 'background-image: url("https://example.com/photo=s1600-p-k-no");'
|
|
|
|
self.assertEqual(
|
|
normalize_google_media_url(style_text),
|
|
"https://example.com/photo=-no",
|
|
)
|
|
|
|
def test_build_review_media_path_sanitizes_review_name(self):
|
|
media_path = build_review_media_path("Joe's Diner!", "20260527", "front.jpg", base_dir="/tmp/review-tests")
|
|
|
|
self.assertEqual(media_path, "/tmp/review-tests/JoesDiner/20260527/front.jpg")
|
|
self.assertEqual(sanitize_review_name("Joe's Diner!"), "JoesDiner")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main() |