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_replace(self):
        sellable = self.create_sellable()
        sellable.description = u'foo bar foo Foo'

        field = AccessorField('Test', None, 'description', Decimal)
        operation = ReplaceOperation(self.store, field, [])
        operation.one_entry.set_text('foo')
        operation.other_entry.set_text('XXX')

        self.assertEqual(field.get_new_value(sellable), u'foo bar foo Foo')
        operation.apply_operation(sellable)
        self.assertEqual(field.get_new_value(sellable), u'XXX bar XXX Foo')
Ejemplo n.º 4
0
    def test_replace(self):
        sellable = self.create_sellable()
        sellable.description = u'foo bar foo Foo'

        field = AccessorField('Test', None, 'description', Decimal)
        operation = ReplaceOperation(self.store, field, [])
        operation.one_entry.set_text('foo')
        operation.other_entry.set_text('XXX')

        self.assertEqual(field.get_new_value(sellable), u'foo bar foo Foo')
        operation.apply_operation(sellable)
        self.assertEqual(field.get_new_value(sellable), u'XXX bar XXX Foo')
Ejemplo n.º 5
0
    def test_set_date(self):
        sellable = self.create_sellable()
        old_date = datetime.date(2016, 1, 1)
        new_date = datetime.date(2015, 2, 2)
        sellable.on_sale_start_date = old_date

        field = AccessorField('Test', None, 'on_sale_start_date', datetime.date)
        operation = SetDateValueOperation(self.store, field, [])
        operation.entry.update(new_date)

        self.assertEqual(field.get_new_value(sellable).date(), old_date)
        operation.apply_operation(sellable)
        self.assertEqual(field.get_new_value(sellable), new_date)
Ejemplo n.º 6
0
    def test_set_date(self):
        sellable = self.create_sellable()
        old_date = datetime.date(2016, 1, 1)
        new_date = datetime.date(2015, 2, 2)
        sellable.on_sale_start_date = old_date

        field = AccessorField('Test', None, 'on_sale_start_date',
                              datetime.date)
        operation = SetDateValueOperation(self.store, field, [])
        operation.entry.update(new_date)

        self.assertEqual(field.get_new_value(sellable).date(), old_date)
        operation.apply_operation(sellable)
        self.assertEqual(field.get_new_value(sellable), new_date)
Ejemplo n.º 7
0
    def test_set(self):
        sellable = self.create_sellable()
        sellable.cost = 100
        sellable.base_price = 1

        price_field = AccessorField('Test', None, 'base_price', Decimal)
        operation = SetValueOperation(self.store, price_field, [])
        operation.entry.set_text('4')

        self.assertEqual(price_field.get_new_value(sellable), 1)
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 4)

        # An invalid value should not change the object
        operation.entry.set_text('foo')
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 4)
Ejemplo n.º 8
0
    def test_set(self):
        sellable = self.create_sellable()
        sellable.cost = 100
        sellable.base_price = 1

        price_field = AccessorField('Test', None, 'base_price', Decimal)
        operation = SetValueOperation(self.store, price_field, [])
        operation.entry.set_text('4')

        self.assertEqual(price_field.get_new_value(sellable), 1)
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 4)

        # An invalid value should not change the object
        operation.entry.set_text('foo')
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 4)
Ejemplo n.º 9
0
    def test_add(self):
        sellable = self.create_sellable()
        sellable.cost = 100
        sellable.base_price = 1

        price_field = AccessorField('Test', None, 'base_price', Decimal)
        cost_field = AccessorField('Test', None, 'cost', Decimal)
        operation = AddOperation(self.store, price_field, [cost_field])
        operation.combo.select(cost_field)
        operation.entry.set_text('3')

        self.assertEqual(price_field.get_new_value(sellable), 1)
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 103)

        # An invalid value should not change the object
        operation.entry.set_text('foo')
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 103)
Ejemplo n.º 10
0
    def test_add(self):
        sellable = self.create_sellable()
        sellable.cost = 100
        sellable.base_price = 1

        price_field = AccessorField('Test', None, 'base_price', Decimal)
        cost_field = AccessorField('Test', None, 'cost', Decimal)
        operation = AddOperation(self.store, price_field, [cost_field])
        operation.combo.select(cost_field)
        operation.entry.set_text('3')

        self.assertEqual(price_field.get_new_value(sellable), 1)
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 103)

        # An invalid value should not change the object
        operation.entry.set_text('foo')
        operation.apply_operation(sellable)
        self.assertEqual(price_field.get_new_value(sellable), 103)