import meta_oxide
import pytest
class TestLocalBusinessBasic:
def test_business_basic(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Joe's Coffee Shop"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "LocalBusiness"
assert objects[0]["name"] == "Joe's Coffee Shop"
def test_business_with_description(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Tech Repair Shop",
"description": "Expert computer and phone repairs"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "LocalBusiness"
assert objects[0]["name"] == "Tech Repair Shop"
assert objects[0]["description"] == "Expert computer and phone repairs"
class TestLocalBusinessAddress:
def test_business_with_address(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Main Street Bakery",
"address": {
"@type": "PostalAddress",
"streetAddress": "123 Main Street",
"addressLocality": "Springfield",
"addressRegion": "IL",
"postalCode": "62701",
"addressCountry": "US"
}
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "LocalBusiness"
assert objects[0]["name"] == "Main Street Bakery"
assert "address" in objects[0]
assert "streetAddress" in str(objects[0]["address"])
assert "Springfield" in str(objects[0]["address"])
def test_business_with_simple_address(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Corner Store",
"address": {
"@type": "PostalAddress",
"streetAddress": "456 Oak Avenue"
}
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert "address" in objects[0]
class TestLocalBusinessContact:
def test_business_with_telephone(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Pizza Palace",
"telephone": "+1-555-123-4567"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["telephone"] == "+1-555-123-4567"
def test_business_with_email(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Consulting LLC",
"email": "info@consulting.com"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["email"] == "info@consulting.com"
def test_business_with_url(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Web Design Co",
"url": "https://webdesign.example.com"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["url"] == "https://webdesign.example.com"
def test_business_with_contact(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Full Contact Business",
"telephone": "+1-555-999-0000",
"email": "contact@business.com",
"url": "https://business.com"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["telephone"] == "+1-555-999-0000"
assert objects[0]["email"] == "contact@business.com"
assert objects[0]["url"] == "https://business.com"
class TestLocalBusinessGeo:
def test_business_with_geo(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Mountain View Cafe",
"geo": {
"@type": "GeoCoordinates",
"latitude": "37.3861",
"longitude": "-122.0839"
}
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["name"] == "Mountain View Cafe"
assert "geo" in objects[0]
assert "latitude" in str(objects[0]["geo"])
assert "longitude" in str(objects[0]["geo"])
class TestLocalBusinessHours:
def test_business_with_hours(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Daily Diner",
"openingHoursSpecification": [
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": "Monday",
"opens": "08:00",
"closes": "18:00"
},
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": "Tuesday",
"opens": "08:00",
"closes": "18:00"
}
]
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["name"] == "Daily Diner"
assert "openingHoursSpecification" in objects[0]
hours_str = str(objects[0]["openingHoursSpecification"])
assert "Monday" in hours_str
assert "08:00" in hours_str
class TestLocalBusinessRating:
def test_business_with_rating(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Top Rated Store",
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.8",
"reviewCount": "127"
}
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["name"] == "Top Rated Store"
assert "aggregateRating" in objects[0]
rating_str = str(objects[0]["aggregateRating"])
assert "4.8" in rating_str
assert "127" in rating_str
def test_business_with_reviews(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Reviewed Business",
"review": [
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "John Doe"
},
"reviewRating": {
"@type": "Rating",
"ratingValue": "5"
},
"reviewBody": "Great service!"
}
]
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["name"] == "Reviewed Business"
assert "review" in objects[0]
review_str = str(objects[0]["review"])
assert "John Doe" in review_str
assert "Great service" in review_str
class TestLocalBusinessRestaurant:
def test_business_restaurant(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Restaurant",
"name": "Italian Bistro",
"servesCuisine": ["Italian", "Mediterranean"],
"priceRange": "$$"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "Restaurant"
assert objects[0]["name"] == "Italian Bistro"
assert "servesCuisine" in objects[0]
assert objects[0]["priceRange"] == "$$"
def test_business_with_price_range(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Budget Shop",
"priceRange": "$"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["priceRange"] == "$"
class TestLocalBusinessImages:
def test_business_with_single_image(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Photo Studio",
"image": "https://example.com/studio.jpg"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["image"] == "https://example.com/studio.jpg"
def test_business_with_multiple_images(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Gallery Shop",
"image": [
"https://example.com/img1.jpg",
"https://example.com/img2.jpg"
]
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert "image" in objects[0]
assert "img1.jpg" in str(objects[0]["image"])
class TestLocalBusinessComplete:
def test_business_complete(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Restaurant",
"name": "The Complete Restaurant",
"description": "A restaurant with everything",
"image": "https://example.com/restaurant.jpg",
"address": {
"@type": "PostalAddress",
"streetAddress": "789 Complete Ave",
"addressLocality": "Full City",
"addressRegion": "CA",
"postalCode": "90210",
"addressCountry": "US"
},
"telephone": "+1-555-FULL-123",
"email": "info@complete.com",
"url": "https://complete-restaurant.com",
"geo": {
"@type": "GeoCoordinates",
"latitude": "34.0522",
"longitude": "-118.2437"
},
"openingHoursSpecification": [
{
"@type": "OpeningHoursSpecification",
"dayOfWeek": ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"],
"opens": "11:00",
"closes": "22:00"
}
],
"aggregateRating": {
"@type": "AggregateRating",
"ratingValue": "4.9",
"reviewCount": "500"
},
"review": [
{
"@type": "Review",
"author": {
"@type": "Person",
"name": "Happy Customer"
},
"reviewRating": {
"@type": "Rating",
"ratingValue": "5"
},
"reviewBody": "Best restaurant ever!"
}
],
"priceRange": "$$$",
"servesCuisine": ["French", "American"]
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
obj = objects[0]
assert obj["@type"] == "Restaurant"
assert obj["name"] == "The Complete Restaurant"
assert obj["description"] == "A restaurant with everything"
assert obj["image"] == "https://example.com/restaurant.jpg"
assert obj["telephone"] == "+1-555-FULL-123"
assert obj["email"] == "info@complete.com"
assert obj["url"] == "https://complete-restaurant.com"
assert obj["priceRange"] == "$$$"
assert "address" in obj
assert "geo" in obj
assert "openingHoursSpecification" in obj
assert "aggregateRating" in obj
assert "review" in obj
assert "servesCuisine" in obj
class TestLocalBusinessSubtypes:
def test_store_subtype(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "Store",
"name": "General Store"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "Store"
assert objects[0]["name"] == "General Store"
def test_cafe_subtype(self):
html = """
<html>
<head>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "CafeOrCoffeeShop",
"name": "The Coffee House"
}
</script>
</head>
<body></body>
</html>
"""
objects = meta_oxide.extract_jsonld(html)
assert len(objects) == 1
assert objects[0]["@type"] == "CafeOrCoffeeShop"
class TestLocalBusinessIntegration:
def test_extract_all_includes_localbusiness(self):
html = """
<html>
<head>
<title>Business Page</title>
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "LocalBusiness",
"name": "Test Business",
"telephone": "+1-555-0000"
}
</script>
</head>
<body></body>
</html>
"""
data = meta_oxide.extract_all(html)
assert "jsonld" in data
assert len(data["jsonld"]) == 1
assert data["jsonld"][0]["@type"] == "LocalBusiness"
assert data["jsonld"][0]["name"] == "Test Business"
assert data["jsonld"][0]["telephone"] == "+1-555-0000"
if __name__ == "__main__":
pytest.main([__file__, "-v"])