Address contact info
========================

Implementation of a behavior providing an address set of fields

Test Address Contact Info
---------------------------

When we create a dexterity content type::

    >>> app = layer['app']
    >>> portal = layer['portal']
    >>> portalURL = portal.absolute_url()
    >>> from plone.dexterity.fti import DexterityFTI
    >>> from collective.behavior.contactinfo.behavior.address import IAddress
    >>> fti = DexterityFTI('address_type')
    >>> fti.behaviors = ('collective.behavior.contactinfo.behavior.address.IAddress',)
    >>> portal.portal_types._setObject('address_type', fti)
    'address_type'
    >>> schema = fti.lookupSchema()

If we access the site as an admin TTW::
    
    >>> from plone.app.testing import TEST_USER_ID, TEST_USER_PASSWORD, setRoles
    >>> setRoles(portal, TEST_USER_ID, ['Manager'])
    >>> import transaction; transaction.commit()
    >>> from plone.testing.z2 import Browser
    >>> browser = Browser(app)
    >>> browser.addHeader('Authorization', 'Basic %s:%s' % (TEST_USER_ID, TEST_USER_PASSWORD,))

We can see this type in the addable types at the root of the site::

    >>> browser.open("http://nohost/plone/folder_factories")
    >>> "address_type" in browser.contents
    True
    >>> browser.getControl("address_type").click()
    >>> browser.getControl("Add").click()
    >>> browser.getControl(name="form.widgets.title").value = "Foo"
    >>> browser.getControl(name="form.widgets.IAddress.address").value = "R. dos Pinheiros 836"
    >>> browser.getControl(name="form.widgets.IAddress.city").value = "Sao Paulo"
    >>> browser.getControl(name="form.widgets.IAddress.state").value = "SP"
    >>> browser.getControl(name="form.widgets.IAddress.postcode").value = "05422-001"
    >>> browser.getControl('Country').value = ["br",]
    >>> browser.getControl(name="form.buttons.save").click()
    >>> browser.url
    'http://nohost/plone/address_type/view'

We can now access our type and its values::

    >>> md = portal.address_type
    >>> md.address
    u'R. dos Pinheiros 836'
    >>> md.city
    u'Sao Paulo'
    >>> md.state
    u'SP'
    >>> md.postcode
    u'05422-001'
    >>> md.country
    u'br'

Test Behavior selection
----------------------------

This will test adding a behavior to an existing content type.

When we create a dexterity content type::

    >>> fti = DexterityFTI('new_address_type')
    >>> portal.portal_types._setObject('new_address_type', fti)
    'new_address_type'
    >>> schema = fti.lookupSchema()
    >>> import transaction; transaction.commit()

We can see this type in the addable types at the root of the site::

    >>> browser.open("http://nohost/plone/folder_factories")
    >>> "new_address_type" in browser.contents
    True
    >>> browser.getControl("new_address_type").click()
    >>> browser.getControl("Add").click()
    >>> browser.getControl(name="form.widgets.title").value = "Foo"
    >>> browser.getControl(name="form.buttons.save").click()
    >>> browser.url
    'http://nohost/plone/new_address_type/view'

Now we add the behavior to this new content type::

    >>> portal.portal_types['new_address_type'].behaviors = ('collective.behavior.contactinfo.behavior.address.IAddress',)
    >>> import transaction; transaction.commit()

And visit an existing content::

    >>> browser.open("http://nohost/plone/new_address_type/view")
    >>> "city" in browser.contents
    True
    
    
