Пример #1
0
    def test_get_value(self):
        ds = SimpleDemoModelSource.as_datasource()
        col = CalcColumn(['integer1'])

        self.assertEqual(col.get_value(SimpleDemoModel(integer1=5), ds), 5)

        col.initial = 10
        self.assertEqual(col.get_value(SimpleDemoModel(integer1=5), ds), 15)
Пример #2
0
 def test_get_value_model_attr_callable(self):
     o = SimpleDemoModel()
     ds = SimpleDemoModelSource.as_datasource()
     o.fake = F
     c = Column('fake')
     v = c.get_value(o, ds)
     self.assertIsInstance(v, RowValue)
     self.assertEqual(v, 'called without obj')
Пример #3
0
    def test_get_value(self):
        ds = SimpleDemoModelSource.as_datasource()

        col = OptionalColumn('nonexistant')
        v = col.get_value(SimpleDemoModel(), ds)
        self.assertEqual(v, "")

        col = OptionalColumn('integer1')
        v = col.get_value(SimpleDemoModel(integer1=5), ds)
        self.assertEqual(v, 5)
Пример #4
0
    def test_get_value_exception(self):
        o = SimpleDemoModel()
        ds = SimpleDemoModelSource.as_datasource()

        col = ColumnCallable(FakeCallable)
        with self.assertRaises(ValueError):
            col.get_value(o, ds)
Пример #5
0
    def test_get_value_attr_on_ds(self):
        """Test get value where attr not found on model, but on ds"""
        o = SimpleDemoModel()
        ds = SimpleDemoModelSource.as_datasource()

        ds.fake = 'Hello'
        c = Column('fake')
        v = c.get_value(o, ds)
        self.assertIsInstance(v, RowValue)
        self.assertEqual(v, 'Hello')
Пример #6
0
    def test_get_value_attr_callable_on_ds(self):
        """Test get value where attr is not found on model and is callable
        attr on ds
        """
        o = SimpleDemoModel()
        ds = SimpleDemoModelSource.as_datasource()

        ds.fake = F
        c = Column('fake')
        v = c.get_value(o, ds)
        self.assertIsInstance(v, RowValue)
        self.assertEqual(v, 'called with obj')
Пример #7
0
    def test_get_value(self):
        o = SimpleDemoModel()
        ds = SimpleDemoModelSource.as_datasource()

        # model found return attr
        c = Column('char')
        v = c.get_value(o, ds)
        self.assertIsInstance(v, RowValue)

        # raise last ValueError
        c = Column('nonexistant')
        with self.assertRaises(ValueError):
            c.get_value(o, ds)

        # Exception with raise ValueError
        c = Column(FakeCallable, name='fake')
        with self.assertRaises(ValueError):
            c.get_value(o, ds)
Пример #8
0
 def test_get_value(self):
     col = DecimalColumn('integer1')
     ds = SimpleDemoModelSource.as_datasource()
     v = col.get_value(SimpleDemoModel(integer1=5), ds)
     self.assertEqual(v, Decimal(5.00))