Ejemplo n.º 1
0
    def test_methods(self):
        sellable = self.create_sellable(price=10)
        field = AccessorField('Test', None, 'base_price', Decimal)

        # The value is still 10
        self.assertEqual(field.get_value(sellable), 10)
        self.assertEqual(field.get_new_value(sellable), 10)
        self.assertFalse(field.is_changed(sellable))

        # Setting it to 10 again should not change anything
        field.set_new_value(sellable, 10)
        self.assertFalse(field.is_changed(sellable))

        # Lets update it to 15
        field.set_new_value(sellable, 15)

        # The current value of the object is still 10, but the new value is 15
        self.assertEqual(sellable.price, 10)
        self.assertEqual(field.get_value(sellable), 10)
        self.assertEqual(field.get_new_value(sellable), 15)
        self.assertTrue(field.is_changed(sellable))

        # Now lest save the value.
        field.save_value(sellable)
        self.assertEqual(sellable.price, 15)
Ejemplo n.º 2
0
    def test_methods(self):
        sellable = self.create_sellable(price=10)
        field = AccessorField('Test', None, 'base_price', Decimal)

        # The value is still 10
        self.assertEqual(field.get_value(sellable), 10)
        self.assertEqual(field.get_new_value(sellable), 10)
        self.assertFalse(field.is_changed(sellable))

        # Setting it to 10 again should not change anything
        field.set_new_value(sellable, 10)
        self.assertFalse(field.is_changed(sellable))

        # Lets update it to 15
        field.set_new_value(sellable, 15)

        # The current value of the object is still 10, but the new value is 15
        self.assertEqual(sellable.price, 10)
        self.assertEqual(field.get_value(sellable), 10)
        self.assertEqual(field.get_new_value(sellable), 15)
        self.assertTrue(field.is_changed(sellable))

        # Now lest save the value.
        field.save_value(sellable)
        self.assertEqual(sellable.price, 15)
Ejemplo n.º 3
0
    def test_accessor(self):
        sellable = self.create_sellable(price=10)
        sellable.product.ncm = u'123'
        field = AccessorField('Test', 'product', 'ncm', unicode)

        self.assertEqual(field.get_value(sellable), '123')
        field.set_new_value(sellable, u'456')
        field.save_value(sellable)

        self.assertEqual(sellable.product.ncm, '456')
Ejemplo n.º 4
0
    def test_accessor(self):
        sellable = self.create_sellable(price=10)
        sellable.product.ncm = u'123'
        field = AccessorField('Test', 'product', 'ncm', str)

        self.assertEqual(field.get_value(sellable), '123')
        field.set_new_value(sellable, u'456')
        field.save_value(sellable)

        self.assertEqual(sellable.product.ncm, '456')