How to test content types with RelationValue fields

Hello everybody,

this is a snippet of a CT called Lecturer:

class ILecturer(Interface):
"""Interface for Lecturers"""

directives.widget(
    'person',
    RelatedItemsFieldWidget,
    pattern_options={"selectableTypes": ["person"], "basePath": get_person_base_path,
                     "favorites": [{"path": get_person_base_path, "title": "Person Folder"}]}
)
person = RelationChoice(
    title=_(u'label_person', default=u'Person'),
    source=CatalogSource(),
    required=True
)

directives.widget(
    'practice',
    RelatedItemsFieldWidget,
    pattern_options={"selectableTypes": ["practice"], "basePath": get_practice_base_path,
                     "favorites": [{"path": get_practice_base_path, "title": "Practice Folder"}]}
)
practice = RelationChoice(
    title=_(u'label_practice', default=u'Practice'),
    source=CatalogSource(),
    required=True
)

form.mode(lecturer_id='hidden')
lecturer_id = schema.ASCIILine(
    title=_(u'label_lecturer_id', default=u'Lecturer ID'),
    required=False,
    max_length=45,
)

educational_sector = schema.TextLine(
    title=_(u'label_educational_sector', default=u'Educational Sector'),
    required=False,
    max_length=45
)

application = schema.Date(
    title=_(u'label_application', default=u'Application'),
    required=False
)

approval = schema.Date(
    title=_(u'label_approval', default=u'Approval'),
    required=False
)

As you can see the CT has two RelationChoice fields.

The problem is that I don't know how to set the relation values in the browser while testing. I've tried it as shown below, but I didn't work like that:

def test_add_lecturer(self):
    self.browser.open(self.portal_url + '/de/lecturers/++add++lecturer')

    ctrl = self.browser.getControl
    ctrl(name="form.widgets.person").value = str(RelationValue(to_id=self.intids.getId(self.person)))
    ctrl(name="form.widgets.practice").value = str(RelationValue(to_id=self.intids.getId(self.practice)))
    ctrl(name="form.widgets.educational_sector").value = u'test_educational_sector'
    ctrl(name="form.widgets.application").value = str(datetime.date(year=2019, month=1, day=1))
    ctrl(name="form.widgets.approval").value = str(datetime.date(year=2019, month=2, day=1))

Does anybody know how to set relation values? Thanks in advance :slight_smile: