Beispiel #1
0
def test_base__update_persons__2(zcmlS):
    """It returns a ZeroDivision message if dividing by zero."""
    person1 = Person()
    person1.__name__ = 'person1'
    call = ('icemac.addressbook.browser.search.result.handler.update.'
            'operators.NoneAppend.__call__')
    with mock.patch(call, side_effect=ZeroDivisionError):
        result = update_persons(
            [person1], person_entity,
            person_entity.getRawField('notes'), 'append', u'bar')
    assert ({'person1': u'Division by zero'}, {'person1': None}) == result
Beispiel #2
0
def test_base__update_persons__3(zcmlS):
    """It returns an Exception if another exception occurred."""
    call = ('icemac.addressbook.browser.search.result.handler.update.'
            'operators.NoneAppend.__call__')
    person1 = Person()
    person1.__name__ = 'person1'
    with mock.patch(call, side_effect=EOFError('file too short')):
        result = update_persons(
            [person1], person_entity,
            person_entity.getRawField('notes'), 'append', u'bar')
    errors = {key: zope.i18n.translate(val)
              for key, val in result[0].items()}
    assert (
        {'person1': u'Unexpected error occurred: EOFError: file too short'} ==
        errors)
Beispiel #3
0
def test_base__update_persons__1(zcmlS):
    """It updates only the specified field."""
    person1 = Person()
    person1.notes = u'p1'
    person2 = Person()
    person2.notes = u'p2'
    update_persons((person1, person2), person_entity,
                   person_entity.getRawField('notes'), 'append', u'bar')
    assert 'p1bar' == person1.notes
    assert 'p2bar' == person2.notes
    # no other attributes are in vars as they are not changed (only the
    # private container attributes are additionally here).
    assert set(['notes', '_BTreeContainer__len', '_SampleContainer__data',
                '__annotations__']) == set(vars(person1).keys())
def test_person__Person__get_name__3():
    """It returns the first name if the last name is not set."""
    person = Person()
    person.first_name = u'Berns'
    assert u'Berns' == person.get_name()
def test_person__Person__get_name__1():
    """It returns last name and first name if both are set."""
    person = Person()
    person.first_name = u'Bernd'
    person.last_name = u'Tester'
    assert u'Bernd Tester' == person.get_name()
def test_person__Person__get_name__2():
    """It returns the last name if the first name is not set."""
    person = Person()
    person.last_name = u'Tester'
    assert u'Tester' == person.get_name()
def test_person__Person__4():
    """It fulfils the `IPersonUnarchiving` interface."""
    assert gocept.reference.verify.verifyObject(IPersonUnarchiving, Person())
def test_person__Person__schema__1(zcmlS):
    """It can be adapted to ``ISchemaName``."""
    assert 'IPerson' == ISchemaName(Person()).schema_name
def test_person__Person__2():
    """It fulfils the `IPersonDefaults` interface."""
    assert gocept.reference.verify.verifyObject(IPersonDefaults, Person())
def test_person__title__3(zcmlS):
    """`title()` returns the last name and first name comma separated."""
    person = Person()
    person.first_name = u'Hans'
    person.last_name = u'Tester'
    assert u'Tester, Hans' == ITitle(person)
def test_person__title__2(zcmlS):
    """`title()` returns the last name if the first name is empty."""
    person = Person()
    person.last_name = u'Tester'
    assert u'Tester' == ITitle(person)
def test_person__title__1(zcmlS):
    """The title of a person without a name is a fix string."""
    assert u'<no name>' == ITitle(Person())
def test_person__Person__get_name__4():
    """It returns '' if neither first name nor last name is set."""
    assert u'' == Person().get_name()