def test_unique_id_of_reference_returns_existing_reference(self): content = self.repository['content'] content.references = (content.references.create( self.repository['target']),) widget = ReferenceSequenceWidget( self.field, self.field.source, request=mock.Mock()) self.assertEqual( (content.references[0],), widget._toFieldValue([ 'reference://?source=http%3A%2F%2Fxml.zeit.de%2Fcontent' '&attribute=references' '&target=http%3A%2F%2Fxml.zeit.de%2Ftarget']))
def test_content_not_in_source_should_raise(self): class FakeSource(object): def __contains__(self, value): return False def get_check_types(self): return [] self.field.vocabulary = FakeSource() widget = ReferenceSequenceWidget( self.field, self.field.vocabulary, request=mock.Mock()) self.assertRaises( zope.formlib.interfaces.ConversionError, lambda: widget._toFieldValue(['http://xml.zeit.de/target']))
def test_unique_id_of_content_returns_reference_to_content(self): widget = ReferenceSequenceWidget(self.field, self.field.source, request=mock.Mock()) result = widget._toFieldValue(['http://xml.zeit.de/target']) self.assertEqual(self.repository['target'], result[0].target)
def test_invalid_unique_id_fails_validation(self): widget = ReferenceSequenceWidget(self.field, mock.Mock(), mock.Mock()) with self.assertRaises(zope.formlib.interfaces.ConversionError): widget._toFieldValue([mock.sentinel.foo, mock.sentinel.bar])