示例#1
0
文件: tests.py 项目: abingham/youblob
    def test_valid_shipping_methods_2(self):
        """Tests valid shipping methods. Test with a cart price criterion.
        """
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a cart price criterion and add it to the shipping method 1
        c = CartPriceCriterion.objects.create(price=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # Cart price is 0.0 sms1 is not valid
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Add some products to the cart
        cart = cart_utils.create_cart(request)

        # Cart price is still under 10 - sms1 is not valid
        CartItem.objects.create(cart=cart, product=self.p1, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Cart price is greater than 10.0 now - sms1 is valid
        CartItem.objects.create(cart=cart, product=self.p2, amount=1)
        update_cart_cache(cart)

        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 2)
示例#2
0
    def test_valid_shipping_methods_2(self):
        """Tests valid shipping methods. Test with a cart price criterion.
        """        
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)
        
        # Create a cart price criterion and add it to the shipping method 1
        c = CartPriceCriterion.objects.create(price=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()
        
        # Cart price is 0.0 sms1 is not valid    
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)
        
        # Add some products to the cart
        cart = cart_utils.create_cart(request)
        
        # Cart price is still under 10 - sms1 is not valid
        CartItem.objects.create(cart=cart, product=self.p1, amount=1)
        update_cart_cache(cart)
        
        sms = utils.get_valid_shipping_methods(request)
        self.assertEqual(len(sms), 1)

        # Cart price is greater than 10.0 now - sms1 is valid
        CartItem.objects.create(cart=cart, product=self.p2, amount=1)
        update_cart_cache(cart)
        
        sms = utils.get_valid_shipping_methods(request)        
        self.assertEqual(len(sms), 2)
示例#3
0
    def test_criteria(self):
        """
        """
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.d)
        co.save()

        self.assertEqual(self.d.is_valid(self.request), False)
        self.assertEqual(self.d.is_valid(self.request, self.p), True)
示例#4
0
    def test_criteria(self):
        """
        """
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.d)
        co.save()

        self.assertEqual(self.d.is_valid(self.request), False)
        self.assertEqual(self.d.is_valid(self.request, self.p), True)
示例#5
0
文件: tests.py 项目: abingham/youblob
    def test_get_product_delivery_time_2(self):
        """Tests the product delivery time for the *cart view*.
        """
        request = create_request()
        request.user = AnonymousUser()

        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()

        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        customer.selected_shipping_method = self.sm2
        customer.save()

        # As the customer has now selected sm2 explicitely the delivery method
        # for the products is dt2 although the default shipping method is
        # sm1.
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid, hence we should get dt1
        dt = utils.get_product_delivery_time(request, self.p2, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # Create a weigth criterion and add it to the shipping method 1. That
        # means sm1 is not valid anymore for p1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # And even if the customer select sm1 explicitely ...
        customer.selected_shipping_method = self.sm1
        customer.save()

        # ... the shipping method for p1 is sm2 and hence the delivery time is
        # dt1
        dt = utils.get_product_delivery_time(request, self.p1, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)
示例#6
0
    def test_get_product_delivery_time_2(self):
        """Tests the product delivery time for the *cart view*.
        """        
        request = create_request()
        request.user = AnonymousUser()
        
        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()
        
        dt = utils.get_product_delivery_time(request, self.p1.slug, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        dt = utils.get_product_delivery_time(request, self.p2.slug, for_cart=True)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)

        customer.selected_shipping_method = self.sm2
        customer.save()
        
        # As the customer has now selected sm2 explicitely the delivery method 
        # for the products is dt2 although the default shipping method is 
        # sm1.
        dt = utils.get_product_delivery_time(request, self.p1.slug, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid, hence we should get dt1
        dt = utils.get_product_delivery_time(request, self.p2.slug, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)
        
        # Create a weigth criterion and add it to the shipping method 1. That 
        # means sm1 is not valid anymore for p1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()
        
        # And even if the customer select sm1 explicitely ...
        customer.selected_shipping_method = self.sm1
        customer.save()
        
        # ... the shipping method for p1 is sm2 and hence the delivery time is
        # dt1
        dt = utils.get_product_delivery_time(request, self.p1.slug, for_cart=True)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)
示例#7
0
    def test_get_first_valid_shipping_method(self):
        """Test utils.get_first_valid_shipping_method
        """
        # Prepare request
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a weigth criterion and add it to the shipping method 1.        
        c = WeightCriterion.objects.create(weight=5.0, operator=GREATER_THAN)
        c = WeightCriterion.objects.create(weight=10.0, operator=LESS_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # Create a weigth criterion and add it to the shipping method 2.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm2)
        co.save()
        
        # For product 1 (weight: 6.0) the sm1 is the first valid (weight: 5.0 - 10.0)
        result = utils.get_first_valid_shipping_method(request, product=self.p1)
        self.assertEqual(result, self.sm1)

        # For product 1 (weight: 12.0) the sm1 is the first valid (weigth: > 10.0)        
        result = utils.get_first_valid_shipping_method(request, product=self.p2)
        self.assertEqual(result, self.sm2)
示例#8
0
    def test_get_product_delivery_time_1(self):
        """Tests the product delivery time for the *product view*.
        """
        request = create_request()
        request.user = AnonymousUser()
        
        customer = customer_utils.get_or_create_customer(request)
        customer.selected_shipping_method = self.sm1
        customer.save()
        
        # We select a explicitely shipping method for the customer. For the
        # product view this shouldn't make a difference. It should always the 
        # first valid shipping method be taken to display the delivery time.
        customer.selected_shipping_method = self.sm2
        customer.save()
        
        # Create a weigth criterion and add it to the shipping method 1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()
        
        # Now we ask for the delivery time for product 1. As sm1 is not valid 
        # (p1 has an weight of 6.0) we should get the delivery time from sm2, 
        # which is dt2
        dt = utils.get_product_delivery_time(request, self.p1.slug)
        self.assertEqual(dt.min, self.dt2.min)
        self.assertEqual(dt.max, self.dt2.max)
        self.assertEqual(dt.unit, self.dt2.unit)

        # For product 2 sm1 is valid (p2 has an weight of 11.0), hence we should 
        # get dt1.
        dt = utils.get_product_delivery_time(request, self.p2.slug)
        self.assertEqual(dt.min, self.dt1.min)
        self.assertEqual(dt.max, self.dt1.max)
        self.assertEqual(dt.unit, self.dt1.unit)
        
        # Now we switch to manual delivery time
        self.p1.manual_delivery_time = True
        self.p1.delivery_time = self.dt3
        self.p1.save()
        
        dt = utils.get_product_delivery_time(request, self.p1.slug)
        self.assertEqual(dt.min, self.dt3.min)
        self.assertEqual(dt.max, self.dt3.max)
        self.assertEqual(dt.unit, self.dt3.unit)
示例#9
0
文件: tests.py 项目: abingham/youblob
    def test_valid_shipping_methods_3(self):
        """Test with a given product.
        """
        # Prepare request
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a weigth criterion and add it to the shipping method 1.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # As the product has a weigth of 6.0 the shipping method is not valid
        result = c.is_valid(request, product=self.p1)
        self.assertEqual(result, False)

        # As product 2 has a weigth of 12.0 the shipping method is valid
        result = c.is_valid(request, product=self.p1)
        self.assertEqual(result, False)
示例#10
0
 def test_valid_shipping_methods_3(self):
     """Test with a given product.
     """
     # Prepare request
     user = User.objects.get(username="******")
     request = DummyRequest(user=user)
     
     # Create a weigth criterion and add it to the shipping method 1.
     c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
     co = CriteriaObjects(criterion=c, content=self.sm1)
     co.save()
     
     # As the product has a weigth of 6.0 the shipping method is not valid
     result = c.is_valid(request, product=self.p1)
     self.assertEqual(result, False)
     
     # As product 2 has a weigth of 12.0 the shipping method is valid
     result = c.is_valid(request, product=self.p1)
     self.assertEqual(result, False)
示例#11
0
文件: tests.py 项目: abingham/youblob
    def test_get_first_valid_shipping_method(self):
        """Test utils.get_first_valid_shipping_method
        """
        # Prepare request
        user = User.objects.get(username="******")
        request = DummyRequest(user=user)

        # Create a weigth criterion and add it to the shipping method 1.
        c = WeightCriterion.objects.create(weight=5.0, operator=GREATER_THAN)
        c = WeightCriterion.objects.create(weight=10.0, operator=LESS_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm1)
        co.save()

        # Create a weigth criterion and add it to the shipping method 2.
        c = WeightCriterion.objects.create(weight=10.0, operator=GREATER_THAN)
        co = CriteriaObjects(criterion=c, content=self.sm2)
        co.save()

        # For product 1 (weight: 6.0) the sm1 is the first valid (weight: 5.0 - 10.0)
        result = utils.get_first_valid_shipping_method(request, product=self.p1)
        self.assertEqual(result, self.sm1)

        # For product 1 (weight: 12.0) the sm1 is the first valid (weigth: > 10.0)
        result = utils.get_first_valid_shipping_method(request, product=self.p2)
        self.assertEqual(result, self.sm2)
def load_data():
    print 'Starting load data'
    management.call_command('loaddata', 'lfs_all_countries.xml', verbosity=0)

    site = Site.objects.all()[0]
    site.name = site.domain = "www.example.com"
    site.save()

    ie = Country.objects.get(code="ie")
    gb = Country.objects.get(code="gb")
    de = Country.objects.get(code="de")
    us = Country.objects.get(code="us")
    fr = Country.objects.get(code="fr")
    nl = Country.objects.get(code="nl")

    shop, created = Shop.objects.get_or_create(name="lfs test",
                                               shop_owner="John Doe",
                                               description="Test Shop",
                                               default_country=ie)
    shop.save()

    # Tax
    thirteen_percent, created = Tax.objects.get_or_create(
        rate=13.5, description="13.5% rate")
    twentyone_percent, created = Tax.objects.get_or_create(
        rate=21, description="21% rate")

    for ic in Country.objects.all():
        shop.invoice_countries.add(ic)

    shop.shipping_countries.add(ie)
    shop.shipping_countries.add(gb)
    shop.shipping_countries.add(de)
    shop.shipping_countries.add(us)
    shop.shipping_countries.add(fr)
    shop.shipping_countries.add(nl)

    shop.save()

    tax = Tax.objects.create(rate=21)

    direct_debit = PaymentMethod.objects.create(
        name="Direct Debit",
        active=True,
        tax=tax,
    )

    cod = PaymentMethod.objects.create(
        name="Cash on delivery",
        active=True,
        tax=tax,
    )

    paypal = PaymentMethod.objects.create(
        name="PayPal",
        active=True,
        tax=tax,
    )

    prepayment = PaymentMethod.objects.create(
        name="Prepayment",
        active=True,
        tax=tax,
    )

    by_invoice = PaymentMethod.objects.create(
        name="By invoice",
        active=True,
        tax=tax,
    )

    categories = ['animals', 'transport', 'food']
    for cat in categories:
        category, created = Category.objects.get_or_create(name=cat,
                                                           slug=slugify(cat))

    products = [
        "Cat", "Dog", "Mouse", "Surfboard", "Car", "Ship", "Chocolate",
        "Apple", "Orange"
    ]
    i = 0
    for p in products:
        product, created = Product.objects.get_or_create(
            name=p,
            slug=slugify(p),
            price=(i + 1) * 10.0,
            sku=i,
            active=True,
            manage_stock_amount=False)
        product.description = paragraph()

        # set every second product to a different tax rate
        if i % 2 == 0:
            product.tax = thirteen_percent
        else:
            product.tax = twentyone_percent

        if i % 3 == 0:
            product.price_calculator = "lfs.gross_price.GrossPriceCalculator"
        else:
            product.price_calculator = "lfs.net_price.NetPriceCalculator"
        product.save()

        category = Category.objects.all()[i / 3]
        category.products.add(product)
        category.save()
        ts, created = Topseller.objects.get_or_create(product=product,
                                                      position=i)
        fp, created = FeaturedProduct.objects.get_or_create(product=product,
                                                            position=i)
        i = i + 1

    # shipping prices setup
    delivery_time, created = DeliveryTime.objects.get_or_create(
        min=2,
        max=7,
        unit=DELIVERY_TIME_UNIT_DAYS,
        description="2 to 7 for delivery")

    # criterion for geo-specific delivery charges
    cc_ie_uk = CountryCriterion.objects.create(operator=IS)
    cc_ie_uk.countries.add(ie)
    cc_ie_uk.countries.add(gb)
    cc_ie_uk.save()

    cc_not_ie_uk = CountryCriterion.objects.create(operator=IS_NOT)
    cc_not_ie_uk.countries.add(ie)
    cc_not_ie_uk.countries.add(gb)
    cc_not_ie_uk.save()

    #Rest of World >1kg ?16.95
    smp_1095, created = ShippingMethod.objects.get_or_create(
        name="Ireland & UK",
        price=10.95,
        active=True,
        delivery_time=delivery_time,
        priority=1)
    smp_1500, created = ShippingMethod.objects.get_or_create(
        name="International",
        price=15.00,
        active=True,
        delivery_time=delivery_time,
        priority=1)

    co = CriteriaObjects(criterion=cc_ie_uk, content=smp_1095)
    co.save()

    co = CriteriaObjects(criterion=cc_not_ie_uk, content=smp_1500)
    co.save()

    left_slot, created = Slot.objects.get_or_create(name="Left")
    right_slot, created = Slot.objects.get_or_create(name="Right")

    cart_portlet, created = CartPortlet.objects.get_or_create(title="Cart")
    pages_portlet, created = PagesPortlet.objects.get_or_create(
        title="Information")
    categories_portlet, created = CategoriesPortlet.objects.get_or_create(
        title="Products")
    relatedproducts_portlet, created = RelatedProductsPortlet.objects.get_or_create(
        title="Related Products")
    recentproducts_portlet, created = RecentProductsPortlet.objects.get_or_create(
        title="Recent Products")

    PortletAssignment.objects.create(slot_id=left_slot.id,
                                     content=shop,
                                     portlet=categories_portlet,
                                     position=10)
    PortletAssignment.objects.create(slot_id=left_slot.id,
                                     content=shop,
                                     portlet=pages_portlet,
                                     position=15)
    PortletAssignment.objects.create(slot_id=right_slot.id,
                                     content=shop,
                                     portlet=cart_portlet,
                                     position=10)
    PortletAssignment.objects.create(slot_id=right_slot.id,
                                     content=shop,
                                     portlet=recentproducts_portlet,
                                     position=20)
    PortletAssignment.objects.create(slot_id=right_slot.id,
                                     content=shop,
                                     portlet=relatedproducts_portlet,
                                     position=30)
    print 'Finishing load data'
def load_data():
    print 'Starting load data'
    management.call_command('loaddata', 'lfs_all_countries.xml', verbosity=0)

    site = Site.objects.all()[0]
    site.name = site.domain = "www.example.com"
    site.save()

    ie = Country.objects.get(code="ie")
    gb = Country.objects.get(code="gb")
    de = Country.objects.get(code="de")
    us = Country.objects.get(code="us")
    fr = Country.objects.get(code="fr")
    nl = Country.objects.get(code="nl")

    shop, created = Shop.objects.get_or_create(name="lfs test", shop_owner="John Doe", description="Test Shop",
                                               default_country=ie)
    shop.save()

    # Tax
    thirteen_percent, created = Tax.objects.get_or_create(rate=13.5, description="13.5% rate")
    twentyone_percent, created = Tax.objects.get_or_create(rate=21, description="21% rate")

    for ic in Country.objects.all():
        shop.invoice_countries.add(ic)

    shop.shipping_countries.add(ie)
    shop.shipping_countries.add(gb)
    shop.shipping_countries.add(de)
    shop.shipping_countries.add(us)
    shop.shipping_countries.add(fr)
    shop.shipping_countries.add(nl)

    shop.save()

    tax = Tax.objects.create(rate=21)

    direct_debit = PaymentMethod.objects.create(
        name="Direct Debit",
        active=True,
        tax=tax,
        )

    cod = PaymentMethod.objects.create(
        name="Cash on delivery",
        active=True,
        tax=tax,
        )

    paypal = PaymentMethod.objects.create(
        name="PayPal",
        active=True,
        tax=tax,
        )

    prepayment = PaymentMethod.objects.create(
        name="Prepayment",
        active=True,
        tax=tax,
        )

    by_invoice = PaymentMethod.objects.create(
        name="By invoice",
        active=True,
        tax=tax,
        )

    categories = ['animals', 'transport', 'food']
    for cat in categories:
        category, created = Category.objects.get_or_create(name=cat, slug=slugify(cat))

    products = ["Cat", "Dog", "Mouse", "Surfboard", "Car", "Ship",
                "Chocolate", "Apple", "Orange"]
    i = 0
    for p in products:
        product, created = Product.objects.get_or_create(name=p, slug=slugify(p), price=(i + 1) * 10.0,
                                                         sku=i, active=True, manage_stock_amount=False)
        product.description = paragraph()

        # set every second product to a different tax rate
        if i % 2 == 0:
            product.tax = thirteen_percent
        else:
            product.tax = twentyone_percent

        if i % 3 == 0:
            product.price_calculator = "lfs.gross_price.GrossPriceCalculator"
        else:
            product.price_calculator = "lfs.net_price.NetPriceCalculator"
        product.save()

        category = Category.objects.all()[i / 3]
        category.products.add(product)
        category.save()
        ts, created = Topseller.objects.get_or_create(product=product, position=i)
        fp, created = FeaturedProduct.objects.get_or_create(product=product, position=i)
        i = i + 1


    # shipping prices setup
    delivery_time, created = DeliveryTime.objects.get_or_create(min=2, max=7, unit=DELIVERY_TIME_UNIT_DAYS,
                                                                description="2 to 7 for delivery")

    # criterion for geo-specific delivery charges    
    cc_ie_uk = CountryCriterion.objects.create(operator=IS)
    cc_ie_uk.countries.add(ie)
    cc_ie_uk.countries.add(gb)
    cc_ie_uk.save()

    cc_not_ie_uk = CountryCriterion.objects.create(operator=IS_NOT)
    cc_not_ie_uk.countries.add(ie)
    cc_not_ie_uk.countries.add(gb)
    cc_not_ie_uk.save()

    #Rest of World >1kg ?16.95    
    smp_1095, created = ShippingMethod.objects.get_or_create(name="Ireland & UK", price=10.95, active=True,
                                                             delivery_time=delivery_time, priority=1)
    smp_1500, created = ShippingMethod.objects.get_or_create(name="International", price=15.00, active=True,
                                                             delivery_time=delivery_time, priority=1)

    co = CriteriaObjects(criterion=cc_ie_uk, content=smp_1095)
    co.save()

    co = CriteriaObjects(criterion=cc_not_ie_uk, content=smp_1500)
    co.save()

    left_slot, created = Slot.objects.get_or_create(name="Left")
    right_slot, created = Slot.objects.get_or_create(name="Right")

    cart_portlet, created = CartPortlet.objects.get_or_create(title="Cart")
    pages_portlet, created = PagesPortlet.objects.get_or_create(title="Information")
    categories_portlet, created = CategoriesPortlet.objects.get_or_create(title="Products")
    relatedproducts_portlet, created = RelatedProductsPortlet.objects.get_or_create(title="Related Products")
    recentproducts_portlet, created = RecentProductsPortlet.objects.get_or_create(title="Recent Products")

    PortletAssignment.objects.create(slot_id=left_slot.id, content=shop, portlet=categories_portlet, position=10)
    PortletAssignment.objects.create(slot_id=left_slot.id, content=shop, portlet=pages_portlet, position=15)
    PortletAssignment.objects.create(slot_id=right_slot.id, content=shop, portlet=cart_portlet, position=10)
    PortletAssignment.objects.create(slot_id=right_slot.id, content=shop, portlet=recentproducts_portlet, position=20)
    PortletAssignment.objects.create(slot_id=right_slot.id, content=shop, portlet=relatedproducts_portlet, position=30)
    print 'Finishing load data'