==============================================================================
Test back reference field for the field 'repeals' on Normativa
==============================================================================

Create the browser object we'll be using.

    >>> from DateTime.DateTime import DateTime
    >>> from Products.Five.testbrowser import Browser
    >>> browser = Browser()
    >>> portal_url = self.portal.absolute_url()
    >>> browser.handleErrors = False
    >>> self.portal.error_log._ignored_exceptions = ()

Log in into the site as manager.

    >>> from Products.PloneTestCase.setup import portal_owner, default_user, default_password
    >>> login_url = portal_url + '/login_form'
    >>> logout_url = portal_url + '/logout'
    >>> browser.open(login_url)

We have the login portlet, so let's use that.

    >>> browser.getControl(name='__ac_name').value = portal_owner
    >>> browser.getControl(name='__ac_password').value = default_password
    >>> browser.getControl(name='submit').click()
    >>> browser.open(portal_url)

First, let's create an area where to place our normativas.

    >>> browser.getLink('Add new').click()
    >>> browser.getControl('Area').click()
    >>> browser.getControl(name='form.button.Add').click()
    >>> browser.getControl(name='title').value = 'An Area'
    >>> browser.getControl(name='sources.source:records:ignore_empty').value = 'Rector'
    >>> browser.getControl(name='sources.kinds:records:ignore_empty:list').value = ['Ley']
    >>> browser.getControl(name='addressBook:lines').value = ['test@test.com']
    >>> browser.getControl('Save').click()

Now let's create a normativa.

    >>> browser.getLink('Add Normativa').click()
    >>> browser.getControl(name='title').value = 'Normativa Uno'
    >>> browser.getControl(name='date').value = str(DateTime('2006/04/04'))
    >>> browser.getControl(name='source').value = 'emisor1'
    >>> browser.getControl(name='number').value = '123'
    >>> browser.getControl(name='kind').value = 'tipo1'
    >>> browser.getControl('Save').click()

Let's now create a normativa that repeals the one previously created.

    >>> browser.getLink('An Area').click()
    >>> browser.getLink('Add Normativa').click()
    >>> browser.getControl(name='title').value = 'Normativa Dos'
    >>> browser.getControl(name='date').value = str(DateTime('2007/04/04'))
    >>> browser.getControl(name='source').value = 'emisor2'
    >>> browser.getControl(name='number').value = '456'
    >>> browser.getControl(name='kind').value = 'tipo2'
    >>> area = getattr(self.portal, 'an-area')
    >>> print area.objectIds()
    ['']
    >>> n1uid = getattr(area, '123_2006')
    >>> browser.getControl(name='repeals:default:list').value = n1uid.UID()
    >>> browser.getControl('Save').click()

Finally, let's check that in the first normativa we created, the second one
appears under the repealed by field.

    >>> browser.open(portal_url+'/an-area/123_2006')
    >>> 'Normativa Dos' in browser.contents
    True
