diff --git a/services/listing_synthesis.py b/services/listing_synthesis.py index 82a593a..13c4b63 100644 --- a/services/listing_synthesis.py +++ b/services/listing_synthesis.py @@ -61,7 +61,7 @@ def create_listing_draft( # Strip markdown clean_json = response_text - json_match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', response_text, re.DOTALL) + json_match = re.search(r'```(?:json)?\s*({.*?})\s*```', response_text, re.DOTALL) if json_match: clean_json = json_match.group(1) else: diff --git a/tests/test_listing_reconstruction.py b/tests/test_listing_reconstruction.py index a2cb7ff..8459873 100644 --- a/tests/test_listing_reconstruction.py +++ b/tests/test_listing_reconstruction.py @@ -101,7 +101,14 @@ def test_generate_title_empty_data(self): self.assertEqual(title, "Item") class TestListingReconstruction(unittest.TestCase): + @patch.dict(os.environ, {'GOOGLE_API_KEY': 'test_key'}) def setUp(self): + # We need to explicitly initialize listing_engine and ebay_integration for app_enhanced to not fail + import app_enhanced + from services.listing_synthesis import ListingSynthesisEngine + from services.ebay_integration import eBayIntegration + app_enhanced.listing_engine = ListingSynthesisEngine() + app_enhanced.ebay_integration = eBayIntegration(use_sandbox=True) # Setup a test database self.db_path = 'test_listings.db' if os.path.exists(self.db_path):