133 lines
5.5 KiB
Python
133 lines
5.5 KiB
Python
from industries.adventure_travel import fields, prompt, schema
|
|
|
|
|
|
def test_field_maps_have_matching_keys_for_shared_fields():
|
|
shared_keys = set(fields.STANDARD_FIELDS) & set(fields.NGS_FIELDS)
|
|
assert 'tripName' in shared_keys
|
|
assert 'majorityPrice' in shared_keys
|
|
assert 'exclusiveAccess' not in fields.STANDARD_FIELDS
|
|
assert 'exclusiveAccess' in fields.NGS_FIELDS
|
|
|
|
|
|
def test_build_prompt_embeds_page_content_and_context():
|
|
page_data = {'text': 'Peru Classic 15 days itinerary...', 'tables': 'Day | Activity', 'url': 'https://intrepidtravel.com/peru'}
|
|
result = prompt.build_prompt('Intrepid Travel', page_data, 'Inca Trail', 'Peru', 15, 'Classic')
|
|
|
|
assert 'Intrepid Travel' in result
|
|
assert 'Peru Classic 15 days itinerary' in result
|
|
assert 'Day | Activity' in result
|
|
assert 'Peru' in result
|
|
assert '"exclusiveAccess"' not in result
|
|
|
|
|
|
def test_build_prompt_uses_real_company_name_not_hardcoded_g_adventures():
|
|
# Regression test — build_prompt() hardcoded "G Adventures" (the
|
|
# hackathon-origin reference client) into every tenant's prompt,
|
|
# regardless of who was actually running the analysis.
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://example.com'}
|
|
result = prompt.build_prompt(
|
|
'Competitor', page_data, 'Peru Trek', 'Peru', 10, 'Classic',
|
|
company_name='Wild Horizons Travel',
|
|
)
|
|
assert 'Wild Horizons Travel' in result
|
|
assert 'G Adventures' not in result
|
|
|
|
|
|
def test_build_prompt_falls_back_to_generic_placeholder_without_company_name():
|
|
# Covers the dry-run /preview-prompt route, which has no tenant
|
|
# context to draw a real company name from.
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://example.com'}
|
|
result = prompt.build_prompt('Competitor', page_data, 'Peru Trek', 'Peru', 10, 'Classic')
|
|
assert 'the client' in result
|
|
assert 'G Adventures' not in result
|
|
|
|
|
|
def test_build_prompt_enriches_comparison_with_real_own_trip_data_when_given():
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://example.com'}
|
|
own_trip = {
|
|
'tripName': 'Inca Trail Classic', 'majorityPrice': 1999,
|
|
'duration': 15, 'activities': 'Trekking, Camping', 'serviceLevel': 'Mid-range',
|
|
}
|
|
result = prompt.build_prompt(
|
|
'Competitor', page_data, 'Inca Trail Classic', 'Peru', 15, 'Classic',
|
|
company_name='Wild Horizons Travel', own_trip=own_trip,
|
|
)
|
|
assert 'Inca Trail Classic' in result
|
|
assert '1999' in result
|
|
assert 'Trekking, Camping' in result
|
|
assert "Wild Horizons Travel's own Inca Trail Classic" in result
|
|
|
|
|
|
def test_build_prompt_falls_back_to_generic_comments_wording_without_own_trip():
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://example.com'}
|
|
result = prompt.build_prompt(
|
|
'Competitor', page_data, 'Inca Trail Classic', 'Peru', 15, 'Classic',
|
|
company_name='Wild Horizons Travel',
|
|
)
|
|
assert 'key differences from Wild Horizons Travel,' in result
|
|
assert 'own site' not in result
|
|
|
|
|
|
def test_build_own_trip_prompt_frames_extraction_as_the_clients_own_page_not_a_competitor():
|
|
page_data = {'text': 'Peru Classic 15 days itinerary...', 'tables': '', 'url': 'https://client.com/peru'}
|
|
result = prompt.build_own_trip_prompt(
|
|
page_data, 'Inca Trail Classic', 'Peru', 15, 'Classic', 'Wild Horizons Travel',
|
|
)
|
|
assert "Wild Horizons Travel's own tour page" in result
|
|
assert 'not a competitor' in result
|
|
assert '"tripName"' in result
|
|
assert '"relevancy"' not in result
|
|
assert '"comments"' not in result
|
|
|
|
|
|
def test_build_own_trip_prompt_includes_ngs_fields_when_flagged():
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://client.com/peru'}
|
|
result = prompt.build_own_trip_prompt(
|
|
page_data, 'Product', 'Peru', 10, 'NGS', 'Wild Horizons Travel', is_ngs=True,
|
|
)
|
|
assert '"exclusiveAccess"' in result
|
|
|
|
|
|
def test_build_prompt_includes_ngs_fields_when_flagged():
|
|
page_data = {'text': 'content', 'tables': '', 'url': 'https://example.com'}
|
|
result = prompt.build_prompt('Competitor', page_data, 'Product', 'Peru', 10, 'NGS', is_ngs=True)
|
|
assert '"exclusiveAccess"' in result
|
|
assert '"groupLeader"' in result
|
|
assert '"sustainability"' in result
|
|
|
|
|
|
def test_build_prompt_handles_missing_page_data():
|
|
result = prompt.build_prompt('Competitor', None, 'Product', 'Peru', 10, 'Classic')
|
|
assert '[PAGE CONTENT WILL BE INSERTED HERE]' in result
|
|
assert '[COMPETITOR URL]' in result
|
|
|
|
|
|
def test_inject_page_content_replaces_placeholders():
|
|
template = (
|
|
'Scraped from Competitor tour page at: [COMPETITOR URL]\n'
|
|
'PAGE CONTENT:\n[PAGE CONTENT WILL BE INSERTED HERE]'
|
|
)
|
|
page_data = {'text': 'Real scraped content', 'tables': '', 'url': 'https://intrepidtravel.com/peru'}
|
|
|
|
result = prompt.inject_page_content(template, 'Competitor', page_data)
|
|
|
|
assert 'Real scraped content' in result
|
|
assert 'https://intrepidtravel.com/peru' in result
|
|
assert '[COMPETITOR URL]' not in result
|
|
|
|
|
|
def test_inject_page_content_appends_table_data():
|
|
template = 'PAGE CONTENT:\n[PAGE CONTENT WILL BE INSERTED HERE]\nat [COMPETITOR URL]'
|
|
page_data = {'text': 'Base text', 'tables': 'Day | Meal', 'url': 'https://example.com'}
|
|
|
|
result = prompt.inject_page_content(template, 'Competitor', page_data)
|
|
|
|
assert 'TABLE DATA' in result
|
|
assert 'Day | Meal' in result
|
|
|
|
|
|
def test_ngs_schema_extends_standard_schema():
|
|
assert set(schema.STANDARD_SCHEMA).issubset(set(schema.NGS_SCHEMA))
|
|
assert 'exclusiveAccess' in schema.NGS_SCHEMA
|
|
assert 'exclusiveAccess' not in schema.STANDARD_SCHEMA
|