Beispiel #1
0
 def afterSetUp(self):
     PloneTestCase.PloneTestCase.afterSetUp(self)
     self.field = TALESLines('tales')
     self.folder.validate_field = lambda *args, **kw: None
Beispiel #2
0
class TALESLinesTest(PloneTestCase.PloneTestCase):

    def afterSetUp(self):
        PloneTestCase.PloneTestCase.afterSetUp(self)
        self.field = TALESLines('tales')
        self.folder.validate_field = lambda *args, **kw: None

    def validate(self, value):
        errors = {}
        res = self.field.validate(value, self.folder, errors)
        return res, errors

    def test_defaults(self):
        self.assertEquals(self.field.get(self.folder), [True])

    def test_getRaw(self):
        self.assertEquals(self.field.getRaw(self.folder), ['python: True'])

    def test_set(self):
        self.assertEquals(self.field.get(self.folder), [True])
        self.folder.setTitle('bar')
        self.field.set(
            self.folder,
            ["python: object.Title() == 'foo'",
             "python: object.Title() == 'bar'"])
        self.assertEquals(self.field.get(self.folder), [False, True])

    def test_set_expr(self):
        [default_expr] = self.field.getDefault(self.folder)
        self.field.set(self.folder, [default_expr])
        self.assertEquals(self.field.getRaw(self.folder), [default_expr.text])

    def test_validate(self):
        self.assertEquals(self.validate(['python: True']), (None, {}))
        self.assertEquals(
            self.validate(['python: True', 'python: 1 + (2 * 3']),
            ('TALES expression "python: 1 + (2 * 3" has errors.', {}))

    def test_valueIsEmptyStrings(self):
        self.field.set(self.folder, [""])
        self.assertEquals(self.field.get(self.folder), [None])