Ejemplo n.º 1
0
    def test_format_func(self):
        sellable = self.create_sellable(price=10)
        sellable.code = u'123'
        sellable.category = self.create_sellable_category(u'Categoria')

        field = AccessorField('Test', None, 'code', unicode)
        self.assertEqual(field.format_func(sellable), '123')
        sellable.code = None
        self.assertEqual(field.format_func(sellable), '')

        field = ReferenceField('Test', None, 'category', SellableCategory,
                               'description')
        self.assertEqual(field.format_func(sellable), 'Categoria')
        sellable.category = None
        self.assertEqual(field.format_func(sellable), '')
Ejemplo n.º 2
0
    def test_format_func(self):
        sellable = self.create_sellable(price=10)
        sellable.code = u'123'
        sellable.category = self.create_sellable_category(u'Categoria')

        field = AccessorField('Test', None, 'code', str)
        self.assertEqual(field.format_func(sellable), '123')
        sellable.code = None
        self.assertEqual(field.format_func(sellable), '')

        field = ReferenceField('Test', None, 'category', SellableCategory,
                               'description')
        self.assertEqual(field.format_func(sellable), 'Categoria')
        sellable.category = None
        self.assertEqual(field.format_func(sellable), '')

        # Accessor field with custom format func
        def format_func(data):
            return 'foobar'

        field = AccessorField('Test',
                              None,
                              'code',
                              str,
                              format_func=format_func)
        self.assertEqual(field.format_func(sellable), 'foobar')
        sellable.code = None
        self.assertEqual(field.format_func(sellable), 'foobar')
Ejemplo n.º 3
0
    def test_format_func(self):
        sellable = self.create_sellable(price=10)
        sellable.code = u'123'
        sellable.category = self.create_sellable_category(u'Categoria')

        field = AccessorField('Test', None, 'code', str)
        self.assertEqual(field.format_func(sellable), '123')
        sellable.code = None
        self.assertEqual(field.format_func(sellable), '')

        field = ReferenceField('Test', None, 'category', SellableCategory,
                               'description')
        self.assertEqual(field.format_func(sellable), 'Categoria')
        sellable.category = None
        self.assertEqual(field.format_func(sellable), '')

        # Accessor field with custom format func
        def format_func(data):
            return 'foobar'

        field = AccessorField('Test', None, 'code', str, format_func=format_func)
        self.assertEqual(field.format_func(sellable), 'foobar')
        sellable.code = None
        self.assertEqual(field.format_func(sellable), 'foobar')