Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(7)  |  Call(6)  |  Derive(0)  |  Import(1)
For calculating the weight of a product or basket

src/d/j/django-oscar-HEAD/tests/integration/shipping/scales_tests.py   django-oscar(Download)
from nose.plugins.attrib import attr
 
from oscar.apps.shipping.scales import Scale
from oscar.apps.basket.models import Basket
from oscar.test import factories
    def test_weighs_uses_specified_attribute(self):
        scale = Scale(attribute_code='weight')
        p = factories.create_product(attributes={'weight': '1'})
        self.assertEqual(1, scale.weigh_product(p))
 
    def test_uses_default_weight_when_attribute_is_missing(self):
        scale = Scale(attribute_code='weight', default_weight=0.5)
    def test_raises_exception_when_attribute_is_missing(self):
        scale = Scale(attribute_code='weight')
        p = factories.create_product()
        with self.assertRaises(ValueError):
            scale.weigh_product(p)
 
    def test_returns_zero_for_empty_basket(self):
        basket = Basket()
 
        scale = Scale(attribute_code='weight')