def _open_edit_url(self):
        browser = Browser('http://localhost/app/admin')
        browser.handleErrors = False
        link = browser.getLink('Bewerk personen')
        link.click()

        # click on one of the "bewerk" links
        link = browser.getLink('ewerk gegevens', index=0)
        link.click()
        return browser
Beispiel #2
0
def setupBrowser(auth=None):
    """Create a testbrowser object for use in pagetests.

    :param auth: HTTP authentication string. None for the anonymous user, or a
        string of the form 'Basic email:password' for an authenticated user.
    :return: A `Browser` object.
    """
    browser = Browser()
    # Set up our Browser objects with handleErrors set to False, since
    # that gives a tracebacks instead of unhelpful error messages.
    browser.handleErrors = False
    if auth is not None:
        browser.addHeader("Authorization", auth)
    return browser
Beispiel #3
0
def setupBrowser(auth=None):
    """Create a testbrowser object for use in pagetests.

    :param auth: HTTP authentication string. None for the anonymous user, or a
        string of the form 'Basic email:password' for an authenticated user.
    :return: A `Browser` object.
    """
    browser = Browser()
    # Set up our Browser objects with handleErrors set to False, since
    # that gives a tracebacks instead of unhelpful error messages.
    browser.handleErrors = False
    if auth is not None:
        browser.addHeader("Authorization", auth)
    return browser
Beispiel #4
0
 def test_import(self):
     try:
         import zope.app.testing
     except ImportError:
         return
     from zope.testbrowser.testing import Browser
     browser = Browser()
Beispiel #5
0
def logInManager():
    """Create a Browser instance and log in as a manager."""
    manager = Browser()
    manager.handleErrors = False
    manager.addHeader('Authorization', 'Basic manager:schooltool')
    manager.open('http://localhost/')
    assert 'SchoolTool' in manager.contents
    return manager
Beispiel #6
0
def logInManager():
    """Create a Browser instance and log in as a manager."""
    manager = Browser()
    manager.handleErrors = False
    manager.addHeader('Authorization', 'Basic manager:schooltool')
    manager.open('http://localhost/')
    assert 'SchoolTool' in manager.contents
    return manager
    def test_edit_names(self):
        # we had an error when, after identifying, there are more names in the merged_biography than in the bioport_biography...
        browser = Browser('http://localhost/app/admin/persons')
        # get some bioport_ids
        bioport_ids = re.findall('[0-9]{8}', browser.contents)
        bioport_ids = list(set(bioport_ids))
        bioport_ids.sort()
        bioport_id1 = bioport_ids[0]

        # create a bioport biography for one of the persons
        browser = Browser('http://localhost/app/admin/persoon?bioport_id=%s' % bioport_id1)
        browser.getControl(name='personname', index=0).value = 'changed name0'
        browser.getControl(name='name_new').value = 'new name1'
        browser.getForm().getControl(name='form.actions.save_everything', index=0).click()

        self.assertEqual(browser.getControl(name='personname', index=0).value, 'changed name0')
        self.assertEqual(browser.getControl(name='personname', index=1).value, 'new name1')
    def test_admin_panel(self):
        # set up
        root = self.getRootFolder()
        self.app = app = root['app']

        # define the db connection
        self.base_url = 'http://localhost/app'
        browser = Browser()
        browser.handleErrors = False  # show some information when an error occurs
        browser.open('http://localhost/app/admin')
#        link = browser.getLink(url=self.base_url + '/admin/edit')
#        link.click()
        browser.open(self.base_url + '/admin/edit')
        form = browser.getForm(index=0)
        form.getControl(name='form.DB_CONNECTION').value = DSN
        form.getControl(name='form.LIMIT').value = '20'
        form.submit('Save')

        repository = app.repository()
        repository.db.metadata.create_all()


        # test adding and deleting sources through the web interface
        # remember how many persons we have at this point
        n_persons = len(repository.get_persons())

        # add a source
        this_dir = os.path.dirname(__file__)
        source_url = 'file://%s' % os.path.join(this_dir, 'data/knaw/list.xml')
        browser.open('http://localhost/app/admin/sources')
        form = browser.getForm(index=0)
        new_source_id = u'new_source'
        form.getControl(name='source_id').value = new_source_id
        form.getControl(name='url').value = source_url
        form.submit()

        # now do we have this source available?
        self.assertEqual(repository.get_source(new_source_id).id, new_source_id)
        # download the biographies for this source
        # now check if they are available on the site
        browser.open('http://localhost/app/admin/source?source_id=%s' % new_source_id)
        form = browser.getForm(index=0)
        form.getControl(name='form.actions.download_biographies').click()

#        repository.download_biographies(source=repository.get_source(new_source_id))
        # now check if they are available on the site
        # the amount of new persons
        n_new_persons = len(repository.get_persons(source_id=new_source_id))
        self.assertTrue(n_new_persons > 1, 'It seems no persons were downloaded')
        # now we should have the previous persons as well as the new persons available in the repository
        self.assertEqual(len(repository.get_persons()), n_persons + n_new_persons)
    def test_edit_workflow(self):
        """ test creating a bioport instance into Zope """
        browser = Browser('http://localhost/app/admin')
        browser.handleErrors = False
        link = browser.getLink('Bewerk personen')
        link.click()

        # click on one of the "bewerk" links
        link = browser.getLink('bewerk gegevens', index=0)
        link.click()
        edit_url = browser.url
        # remove the birth date
        form = browser.getForm(index=0)
        form.getControl(name='birth_y').value = ''
        form.getControl(name='birth_text').value = ''
        form.getControl(name='personname'). value = 'xxx'
        form.getControl(name='form.actions.save_everything', index=0).click()

        # go the the public view
        browser.getLink('in portaal').click()
        public_url = browser.url

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='birth_d').value = '1'
        form.getControl(name='birth_m').value = ['2']
        form.getControl(name='birth_y').value = '3333'
        form.getControl(name='form.actions.save_everything', index=0).click()
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='birth_d').value, '1')
        self.assertEqual(form.getControl(name='birth_m').value, ['2'])
        self.assertEqual(form.getControl(name='birth_y').value, '3333')
        browser.open(public_url)
        assert re.findall('3333', browser.contents, re.DOTALL)

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='death_y').value = '2222'
        form.getControl(name='death_m').value = ['2']
        form.getControl(name='death_d').value = '1'
        form.getControl(name='form.actions.save_everything', index=0).click()
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='death_y').value, '2222')
        self.assertEqual(form.getControl(name='death_m').value, ['2'])
        self.assertEqual(form.getControl(name='death_d').value, '1')
        browser.open(public_url)
        assert re.findall('1 februari 2222', browser.contents, re.DOTALL), browser.contents

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='funeral_y').value = '3333'
        form.getControl(name='form.actions.save_everything', index=0).click()
        browser.open(public_url)
        assert re.findall('3333', browser.contents, re.DOTALL)

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='baptism_y').value = '4444'
        form.getControl(name='form.actions.save_everything', index=0).click()
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='baptism_y').value, '4444')

        browser.open(public_url)
        assert re.findall('4444', browser.contents, re.DOTALL)

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='baptism_y').value = ''
        form.getControl(name='form.actions.save_everything', index=0).click()
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='baptism_y').value, '')

        # geslacht
        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='sex').value = ['2']
        form.getControl(name='form.actions.save_everything', index=0).click()
        browser.open(public_url)
        assert re.findall('vrouw', browser.contents, re.DOTALL)

        # remakrts bioport editor
        browser.open(edit_url)
        form = browser.getForm(index=0)
        s = 'Given the existence as uttered forth in the public works of Puncher and Wattmann of a personal God quaquaquaqua'
        form.getControl(name='remarks_bioport_editor').value = s
        form.getControl(name='form.actions.save_everything', index=0).click()
        browser.open(edit_url)
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='remarks_bioport_editor').value, s)
        assert re.findall('quaquaquaqua', browser.contents, re.DOTALL)
        browser.open(public_url)

        s = "Questo e' il ballo del qua qua e di un papero che sa fare solo <a href='qua'>qua</a> qua qua piu qua qua qua"

        browser.open(edit_url)
        form = browser.getForm(index=0)
        form.getControl(name='remarks').value = s
        form.getControl(name='form.actions.save_everything', index=0).click()
        browser.open(edit_url)
        form = browser.getForm(index=0)
        self.assertEqual(form.getControl(name='remarks').value, s)
        browser.open(public_url)
        assert re.findall("sa fare solo <a href='qua'>qua</a> qua qua", browser.contents, re.DOTALL), browser.contents

        # snippet
#        browser.open(edit_url)
#        form = browser.getForm(index=0)
#        form.getControl(name='snippet').value=['test for snippet']
#        form.getControl(name='form.actions.save_snippet').click()
#        browser.open(public_url)
#        assert re.findall('test for snippet', browser.contents, re.DOTALL)

        """does the 'save everyting' button indeed save everything? """
        browser.open(edit_url)
        form = browser.getForm(index=0)
        vals = [
            ('sex', ['1']),
            ('baptism_y', '555'),
            ('birth_text', 'ladida'),
            ('birth_y', ''),
            ('state_floruit_from_y', '2000'),
            ('status', ['1']),
        ]
        for k, v in vals:
            try:
                form.getControl(name=k, index=0).value = v
            except:
                print '********', k, v
                raise
        form.getControl(name='form.actions.save_everything', index=0).click()
        form = browser.getForm(index=0)
        for k, v in vals:
            self.assertEqual(form.getControl(name=k).value, v)

        browser.open(public_url)
        assert re.findall('man', browser.contents, re.DOTALL), browser.contents
        assert re.findall('%s' % dict(vals)['baptism_y'], browser.contents, re.DOTALL)
        assert re.findall(dict(vals)['birth_text'], browser.contents, re.DOTALL), browser.contents

        # changes in, e.g., birth events, should turn up in the master list
        browser = Browser('http://localhost/app/admin/persons')
    def test_personidentify_workflow(self):

        browser = Browser('http://localhost/app/admin/persoonidentify')
        browser.handleErrors = False

        # search for the first person
        form = browser.getForm(index=0)
        form.getControl(name='search_name').value = 'hilbrand'
        form.getControl(name='form.actions.search_persons').click()
        assert 'Hilbrand' in browser.contents, browser.contents

        # choose it and put it in the list
        browser.getLink('kies').click()

        # we now selected the person
        # we can find the name of the person, followed by a 'verwijder' link
        assert re.findall('Hilbrand.*verwijder', browser.contents, re.DOTALL), browser.contents

        # the page remembered the search term
        form = browser.getForm()
        self.assertEqual(form.getControl(name='search_name').value, 'hilbrand')

        # search for a second person, using a wildcard pattern
        form.getControl(name='search_name').value = 'heyns*'
        form.getControl(name='form.actions.search_persons').click()

        # choose it as well
        browser.getLink('kies').click()

        assert re.findall('Hilbrand.*verwijder', browser.contents, re.DOTALL), browser.contents
        assert re.findall('Heyns.*verwijder', browser.contents, re.DOTALL), browser.contents
        # remove the first person
        browser.getLink('verwijder keuze').click()

        assert not re.findall('Hilbrand.*verwijder', browser.contents, re.DOTALL), browser.contents
        assert re.findall('Heyns.*verwijder', browser.contents, re.DOTALL), browser.contents

        # choose another person
        form = browser.getForm()
        form.getControl(name='search_name').value = 'kraemer'
        form.getControl(name='form.actions.search_persons').click()
        browser.getLink('kies').click()

        # identify the two
        link = browser.getLink(id='identify')
        bioport_id1, bioport_id2 = link.url.split('bioport_ids=')[1:]
        bioport_id1 = bioport_id1[:bioport_id1.find('&')]

        # just check if we did not make parsing errors
        self.assertTrue(len(bioport_id1), 8)
        self.assertTrue(len(bioport_id2), 8)
        link.click()

        # now the two items names are identified
        # if we go to the first url, it should redirect us to the second url
        self.assertNotEqual(bioport_id1, bioport_id2)
        url1 = 'http://localhost/app/persoon/%s' % bioport_id1
        url2 = 'http://localhost/app/persoon/%s' % bioport_id2
        browser1 = Browser(url1)
        browser2 = Browser(url2)
        # one of the two pages should have redirected to the other - both will now have the same url
        self.assertEqual(browser1.url, browser2.url)

        # open an edit page and detach a biography
        browser = Browser('http://localhost/app/admin/persoon?bioport_id=%s' % bioport_id2)
        link = browser.getLink('koppel', index=0)
        link.click()