import unittest
from pathlib import Path
from agent import safe_profile
from form_completion import FIELD_PATTERNS
import re

class AddressFlowTests(unittest.TestCase):
 def test_profile_transport(self):
  profile={'address_line1':'Example Road 1','address_line2':'Flat 2','city':'Bengaluru','state':'Karnataka','postal_code':'560000','country':'India','phone_country_code':'+91'}
  self.assertEqual({k:safe_profile(profile)[k] for k in profile},profile)
 def test_address_labels(self):
  labels={'address_line1':'Address Line 1','address_line2':'Address Line 2','city':'City','state':'State / Province','postal_code':'Postal Code'}
  for k,label in labels.items():
   matches=[name for name,pat in FIELD_PATTERNS.items() if re.search(pat,label,re.I)]
   self.assertEqual(matches,[k],(label,matches))
 def test_no_address_from_location(self):
  p=safe_profile({'location':'Bengaluru','country':'India'})
  self.assertFalse(any(k in p for k in ('address_line1','address_line2','city','state','postal_code')))
 def test_profile_ui_fields(self):
  s=Path(__file__).with_name('profile.html').read_text()
  for k in ('address_line1','address_line2','city','state','postal_code'):
   self.assertIn(k+':',s)
if __name__=='__main__':unittest.main()
