Ejemplo n.º 1
0
    def create_fixtures(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")

        self.country = Country.objects.create(name='CH')

        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.save()
Ejemplo n.º 2
0
 def setUp(self):
     
     cart_modifiers_pool.USE_CACHE=False
     
     self.user = User.objects.create(username="******", 
                                     email="*****@*****.**",
                                     first_name="Test",
                                     last_name = "Toto")
     
     self.product = Product()
     self.product.name = "TestPrduct"
     self.product.slug = "TestPrduct"
     self.product.short_description = "TestPrduct"
     self.product.long_description = "TestPrduct"
     self.product.active = True
     self.product.unit_price = self.PRODUCT_PRICE
     self.product.save()
     
     self.cart = Cart()
     self.cart.user = self.user
     self.cart.save()
     
     #self.client.user = self.user
     #self.client.save()
     
     self.country = Country.objects.create(name='CH')
     
     self.address = Address()
     self.address.name = 'Test Toto'
     self.address.address = 'address'
     self.address.address2 = 'address2'
     self.address.zip_code = '1234'
     self.address.state = 'ZH'
     self.address.country = self.country
     self.address.is_billing = True
     self.address.is_shipping = True
     self.address.save()
     
     self.address2 = Address()
     self.address2.name = 'Test Toto'
     self.address2.address = '2address'
     self.address2.address2 = '2address2'
     self.address2.zip_code = '21234'
     self.address2.state = '2ZH'
     self.address2.country = self.country
     self.address2.is_billing = True
     self.address2.is_shipping = False
     self.address2.save()
Ejemplo n.º 3
0
class ClientTestCase(TestCase):
    
    def create_fixtures(self):
        self.user = User.objects.create(username="******", 
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name = "Toto")
        
        self.country = Country.objects.create(name='CH')
        
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.save()
        
        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.save()

        
#    def test_unicode_method_works(self):
#        self.create_fixtures()
#        expected = "ClientProfile for Test Toto"
#        text = self.client.__unicode__()
#        self.assertEqual(expected, text)
        
    def test_unicode_method_works_for_null_user_info(self):
        self.create_fixtures()
        u = User.objects.create(username="******", 
                                        email="*****@*****.**")
        
        expected = "test2"
        text = u.__unicode__()
        self.assertEqual(expected, text)
        
        u.delete()
Ejemplo n.º 4
0
 def setUp(self):
     self.user = User.objects.create(username="******", 
                                     email="*****@*****.**",
                                     first_name="Test",
                                     last_name = "Toto")
     self.user.save()
     
     self.country = Country.objects.create(name='CH')
     
     self.address = Address()
     self.address.client = self.client
     self.address.address = 'address'
     self.address.address2 = 'address2'
     self.address.zip_code = '1234'
     self.address.state = 'ZH'
     self.address.country = self.country
     self.address.is_billing = False
     self.address.is_shipping = True
     self.address.save()
     
     self.address2 = Address()
     self.address2.client = self.client
     self.address2.address = '2address'
     self.address2.address2 = '2address2'
     self.address2.zip_code = '21234'
     self.address2.state = '2ZH'
     self.address2.country = self.country
     self.address2.is_billing = True
     self.address2.is_shipping = False
     self.address2.save()
     
     # The order fixture
     
     self.order = Order()
     self.order.user = self.user
     self.order.order_subtotal = Decimal('100') # One item worth 100
     self.order.order_total = Decimal('120') # plus a test field worth 10
     self.order.status = Order.PROCESSING
     ship_address = self.address
     bill_address = self.address2
     
     self.order.shipping_name = "%s %s" %(self.user.first_name, 
                                           self.user.last_name)
     
     self.order.shipping_address = ship_address.address
     self.order.shipping_address2 = ship_address.address2
     self.order.shipping_zip_code = ship_address.zip_code
     self.order.shipping_state = ship_address.state
     self.order.shipping_country = ship_address.country.name
     
     self.order.shipping_name = "%s %s" %(self.user.first_name, 
                                           self.user.last_name)
     self.order.billing_address = bill_address.address
     self.order.billing_address2 = bill_address.address2
     self.order.billing_zip_code = bill_address.zip_code
     self.order.billing_state = bill_address.state
     self.order.billing_country = bill_address.country.name
     
     self.order.save()
     
     # Orderitems
     self.orderitem = OrderItem()
     self.orderitem.order = self.order
 
     self.orderitem.product_reference = 'fakeref'
     self.orderitem.product_name = 'Test item'
     self.orderitem.unit_price = Decimal("100")
     self.orderitem.quantity = 1
 
     self.orderitem.line_subtotal = Decimal('100')
     self.orderitem.line_total = Decimal('110')
     self.orderitem.save()
     
     eoif = ExtraOrderItemPriceField()
     eoif.order_item = self.orderitem
     eoif.label = 'Fake extra field'
     eoif.value = Decimal("10")
     eoif.save()
     
     eof = ExtraOrderPriceField()
     eof.order = self.order
     eof.label = "Fake Taxes"
     eof.value = Decimal("10")
     eof.save()
Ejemplo n.º 5
0
class PayOnDeliveryTestCase(TestCase):

    def setUp(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()
        self.country = Country.objects.create(name='CH')
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal('100')  # One item worth 100
        self.order.order_total = Decimal('120')  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = 'Test item'
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal('100')
        self.orderitem.line_total = Decimal('110')
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = 'Fake extra field'
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()

    def test01_backend_returns_urls(self):
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls, None)
        self.assertEqual(len(urls), 1)

    def test02_must_be_logged_in_if_setting_is_true(self):
        with SettingsOverride(SHOP_FORCE_LOGIN=True):
            resp = self.client.get(reverse('shop:pay-on-delivery'))
            self.assertEqual(resp.status_code, 302)
            self.assertTrue('accounts/login/' in resp._headers['location'][1])

    def test_order_required_before_payment(self):
        """ See issue #84 """
        # Session only (no order)
        response = self.client.get(reverse('shop:pay-on-delivery'))
        self.assertEqual(302, response.status_code)
        self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1])

        # User logged in (no order)
        username = '******'
        pw = 'pass'
        User.objects.create_user(username=username, password=pw, email='*****@*****.**')
        logged_in = self.client.login(username=username, password=pw)
        self.assertTrue(logged_in)
        response = self.client.get(reverse('shop:pay-on-delivery'))
        self.assertEqual(302, response.status_code)
        self.assertEqual('http://testserver/shop/cart/', response._headers['location'][1])
        self.client.logout()

        # User logged in and has order
        self.user.set_password('blah')
        self.user.save()
        logged_in = self.client.login(username=self.user.username, password='******')
        self.assertTrue(logged_in)
        response = self.client.get(reverse('shop:pay-on-delivery'))
        self.assertTrue(reverse('shop:thank_you_for_your_order') in response._headers['location'][1])
Ejemplo n.º 6
0
class OrderConversionTestCase(TestCase):

    PRODUCT_PRICE = Decimal('100')
    TEN_PERCENT = Decimal(10) / Decimal(100)

    def setUp(self):
        cart_modifiers_pool.USE_CACHE = False
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()

        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()

        #self.client.user = self.user
        #self.client.save()

        self.country = Country.objects.create(name='CH')

        self.address = Address()
        self.address.name = 'Test Toto'
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = True
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.name = 'Test Toto'
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

    def test_create_order_from_simple_cart(self):
        """
        Let's make sure that all the info is copied over properly when using
        Order.objects.create_from_cart()
        """
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()

        o = Order.objects.create_from_cart(self.cart)

        self.assertNotEqual(o, None)

        ois = OrderItem.objects.filter(order=o)
        cis = CartItem.objects.filter(cart=self.cart)
        self.assertEqual(len(ois), len(cis))

        self.assertEqual(ois[0].line_subtotal, self.PRODUCT_PRICE)
        self.assertEqual(ois[0].line_total, self.PRODUCT_PRICE)

        self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
        self.assertEqual(o.order_total, self.cart.total_price)

    def test_create_order_order_items_proper_product_name(self):
        baseproduct = BaseProduct.objects.create(
                name="Table",
                unit_price=self.PRODUCT_PRICE
                )
        variation = ProductVariation.objects.create(
                baseproduct=baseproduct,
                name="white"
                )
        self.cart.add_product(variation)
        self.cart.update()
        self.cart.save()

        o = Order.objects.create_from_cart(self.cart)
        ois = OrderItem.objects.filter(order=o)
        self.assertEqual(ois[0].product_name, "Table - white")

    def test_create_order_from_taxed_cart(self):
        """
        This time assert that everything is consistent with a tax cart modifier
        """
        MODIFIERS = [
            'shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier']

        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):

            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()

            o = Order.objects.create_from_cart(self.cart,)

            # Must not return None, obviously
            self.assertNotEqual(o, None)

            # Compare all the OrderItems to all CartItems (length)
            ois = OrderItem.objects.filter(order=o)
            cis = CartItem.objects.filter(cart=self.cart)
            self.assertEqual(len(ois), len(cis))

            self.assertEqual(ois[0].line_subtotal, self.PRODUCT_PRICE)
            self.assertEqual(ois[0].line_total, self.PRODUCT_PRICE)

            # Assert that there are as many extra_cart_price_fields than there
            # are extra order price fields
            e_cart_fields = self.cart.extra_price_fields
            e_order_fields = ExtraOrderPriceField.objects.filter(order=o)
            self.assertEqual(len(e_cart_fields), len(e_order_fields))

            # Check that totals match
            self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
            self.assertEqual(o.order_total, self.cart.total_price)
            self.assertNotEqual(o.order_subtotal, Decimal("0"))
            self.assertNotEqual(o.order_total, Decimal("0"))

    def test_order_addresses_match_user_preferences(self):
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()

        self.address.is_billing = False
        self.address.save()

        o = Order.objects.create_from_cart(self.cart)
        # Must not return None, obviously
        self.assertNotEqual(o, None)

        o.set_shipping_address(self.address)
        o.set_billing_address(self.address2)

        self.assertEqual(o.shipping_address_text, self.address.as_text())
        self.assertEqual(o.billing_address_text, self.address2.as_text())

    def test_create_order_respects_product_specific_get_price_method(self):
        if SKIP_BASEPRODUCT_TEST:
            return
        baseproduct = BaseProduct.objects.create(unit_price=Decimal('10.0'))
        product = ProductVariation.objects.create(baseproduct=baseproduct)

        self.cart.add_product(product)
        self.cart.update()
        self.cart.save()
        o = Order.objects.create_from_cart(self.cart)
        oi = OrderItem.objects.filter(order=o)[0]
        self.assertEqual(oi.unit_price, baseproduct.unit_price)

    def test_create_from_cart_respects_get_product_reference(self):
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()

        o = Order.objects.create_from_cart(self.cart)
        oi = OrderItem.objects.filter(order=o)[0]
        self.assertEqual(oi.product_reference, self.product.get_product_reference())
Ejemplo n.º 7
0
class PayOnDeliveryTestCase(TestCase):

    def setUp(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()
        self.country = Country.objects.create(name='CH')
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal('100')  # One item worth 100
        self.order.order_total = Decimal('120')  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = 'Test item'
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal('100')
        self.orderitem.line_total = Decimal('110')
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = 'Fake extra field'
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()

    def test01_backend_returns_urls(self):
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls, None)
        self.assertEqual(len(urls), 1)

    def test02_must_be_logged_in_if_setting_is_true(self):
        with SettingsOverride(SHOP_FORCE_LOGIN=True):
            resp = self.client.get(reverse('pay-on-delivery'))
            self.assertEqual(resp.status_code, 302)
            self.assertTrue('accounts/login/' in resp._headers['location'][1])
Ejemplo n.º 8
0
class OrderConversionTestCase(TestCase):
    
    PRODUCT_PRICE = Decimal('100')
    TEN_PERCENT = Decimal(10) / Decimal(100)
    
    def setUp(self):
        
        cart_modifiers_pool.USE_CACHE=False
        
        self.user = User.objects.create(username="******", 
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name = "Toto")
        
        self.product = Product()
        self.product.name = "TestPrduct"
        self.product.slug = "TestPrduct"
        self.product.short_description = "TestPrduct"
        self.product.long_description = "TestPrduct"
        self.product.active = True
        self.product.unit_price = self.PRODUCT_PRICE
        self.product.save()
        
        self.cart = Cart()
        self.cart.user = self.user
        self.cart.save()
        
        #self.client.user = self.user
        #self.client.save()
        
        self.country = Country.objects.create(name='CH')
        
        self.address = Address()
        self.address.name = 'Test Toto'
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = True
        self.address.is_shipping = True
        self.address.save()
        
        self.address2 = Address()
        self.address2.name = 'Test Toto'
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()
    
    def test_create_order_from_simple_cart(self):
        """
        Let's make sure that all the info is copied over properly when using
        Order.objects.create_from_cart()
        """
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()
        
        o = Order.objects.create_from_cart(self.cart)
        
        self.assertNotEqual(o, None)
        
        ois = OrderItem.objects.filter(order=o)
        cis = CartItem.objects.filter(cart=self.cart)
        self.assertEqual(len(ois), len(cis))

        self.assertEqual(ois[0].line_subtotal, self.PRODUCT_PRICE)
        self.assertEqual(ois[0].line_total, self.PRODUCT_PRICE)
        
        self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
        self.assertEqual(o.order_total, self.cart.total_price)

    def test_create_order_from_taxed_cart(self):
        """
        This time assert that everything is consistent with a tax cart modifier
        """
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentGlobalTaxModifier']
        
        with SettingsOverride(SHOP_CART_MODIFIERS=MODIFIERS):

            self.cart.add_product(self.product)
            self.cart.update()
            self.cart.save()
            
            o = Order.objects.create_from_cart(self.cart,)
            
            # Must not return None, obviously
            self.assertNotEqual(o, None)
            
            # Compare all the OrderItems to all CartItems (length)
            ois = OrderItem.objects.filter(order=o)
            cis = CartItem.objects.filter(cart=self.cart)
            self.assertEqual(len(ois), len(cis))

            self.assertEqual(ois[0].line_subtotal, self.PRODUCT_PRICE)
            self.assertEqual(ois[0].line_total, self.PRODUCT_PRICE)
        
            # Assert that there are as many extra_cart_price_fields than there
            # are extra order price fields
            e_cart_fields = self.cart.extra_price_fields
            e_order_fields = ExtraOrderPriceField.objects.filter(order=o)
            self.assertEqual(len(e_cart_fields), len(e_order_fields))
            
            # Check that totals match
            self.assertEqual(o.order_subtotal, self.cart.subtotal_price)
            self.assertEqual(o.order_total, self.cart.total_price)
            self.assertNotEqual(o.order_subtotal, Decimal("0"))
            self.assertNotEqual(o.order_total, Decimal("0"))


    def test_order_addresses_match_user_preferences(self):
        self.cart.add_product(self.product)
        self.cart.update()
        self.cart.save()
        
        self.address.is_billing = False
        self.address.save()
        
        o = Order.objects.create_from_cart(self.cart)
        # Must not return None, obviously
        self.assertNotEqual(o, None)
        
        o.set_shipping_address(self.address.address, self.address.city,
            self.address.zip_code, self.address.state, self.address.country,
            self.address.name, self.address.address2)
        
        o.set_billing_address(self.address2.address, self.address2.city,
            self.address2.zip_code, self.address2.state, self.address2.country,
            self.address2.name, self.address2.address2)
        
        # Check that addresses are transfered properly
        self.assertEqual(o.shipping_name, "%s %s" % (self.user.first_name, self.user.last_name))
        self.assertEqual(o.shipping_address, self.address.address)
        self.assertEqual(o.shipping_address2, self.address.address2)
        self.assertEqual(o.shipping_zip_code, self.address.zip_code)
        self.assertEqual(o.shipping_state, self.address.state)    
        self.assertEqual(o.shipping_country, self.address.country.name)
        
        self.assertEqual(o.billing_name, "%s %s" % (self.user.first_name, self.user.last_name))
        self.assertEqual(o.billing_address, self.address2.address)
        self.assertEqual(o.billing_address2, self.address2.address2)
        self.assertEqual(o.billing_zip_code, self.address2.zip_code)
        self.assertEqual(o.billing_state, self.address2.state)    
        self.assertEqual(o.billing_country, self.address2.country.name)
        
    def test_order_saves_item_pk_as_a_string(self):
        """
        That's needed in case shipment or payment backends need to make fancy 
        calculations on products (i.e. shipping based on weight/size...)
        """
        # Add another product to the database, so it's ID isn't 1
        product2 = Product.objects.create(name="TestPrduct2",
        slug="TestPrduct2",
        active=True,
        unit_price=self.PRODUCT_PRICE)
        
        self.cart.add_product(product2)
        self.cart.update()
        self.cart.save()
        
        self.address.is_billing = False
        self.address.save()
        
        o = Order.objects.create_from_cart(self.cart)
        
        # Must not return None, obviously
        self.assertNotEqual(o, None)
        
        # take the first item from the order:
        oi = OrderItem.objects.filter(order=o)[0]
        
        self.assertEqual(oi.product_reference, str(product2.id))
        
        # Lookup works?
        prod = oi.product
        self.assertEqual(prod,product2)

    def test_create_order_respects_product_specific_get_price_method(self):
        baseproduct = BaseProduct.objects.create(unit_price=Decimal('10.0'))
        product = ProductVariation.objects.create(baseproduct=baseproduct)

        self.cart.add_product(product)
        self.cart.update()
        self.cart.save()
        o = Order.objects.create_from_cart(self.cart)
        oi = OrderItem.objects.filter(order=o)[0]
        self.assertEqual(oi.unit_price, baseproduct.unit_price)
Ejemplo n.º 9
0
    def setUp(self):
        self.user = User.objects.create(username="******", email="*****@*****.**", first_name="Test", last_name="Toto")
        self.user.save()

        self.country = Country.objects.create(name="CH")

        self.address = Address()
        self.address.client = self.client
        self.address.address = "address"
        self.address.address2 = "address2"
        self.address.zip_code = "1234"
        self.address.state = "ZH"
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = "2address"
        self.address2.address2 = "2address2"
        self.address2.zip_code = "21234"
        self.address2.state = "2ZH"
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal("100")  # One item worth 100
        self.order.order_total = Decimal("120")  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = "Test item"
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal("100")
        self.orderitem.line_total = Decimal("110")
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = "Fake extra field"
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()
Ejemplo n.º 10
0
class PayOnDeliveryTestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()
        self.country = Country.objects.create(name='CH')
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal('100')  # One item worth 100
        self.order.order_total = Decimal('120')  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = 'Test item'
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal('100')
        self.orderitem.line_total = Decimal('110')
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = 'Fake extra field'
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()

    def test01_backend_returns_urls(self):
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls, None)
        self.assertEqual(len(urls), 1)

    def test02_must_be_logged_in_if_setting_is_true(self):
        with SettingsOverride(SHOP_FORCE_LOGIN=True):
            resp = self.client.get(reverse('pay-on-delivery'))
            self.assertEqual(resp.status_code, 302)
            self.assertTrue('accounts/login/' in resp._headers['location'][1])
Ejemplo n.º 11
0
    def setUp(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()
        self.country = Country.objects.create(name='CH')
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal('100')  # One item worth 100
        self.order.order_total = Decimal('120')  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = 'Test item'
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal('100')
        self.orderitem.line_total = Decimal('110')
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = 'Fake extra field'
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()
Ejemplo n.º 12
0
class PayOnDeliveryTestCase(TestCase):
    def setUp(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()
        self.country = Country.objects.create(name='CH')
        self.address = Address()
        self.address.client = self.client
        self.address.address = 'address'
        self.address.address2 = 'address2'
        self.address.zip_code = '1234'
        self.address.state = 'ZH'
        self.address.country = self.country
        self.address.is_billing = False
        self.address.is_shipping = True
        self.address.save()

        self.address2 = Address()
        self.address2.client = self.client
        self.address2.address = '2address'
        self.address2.address2 = '2address2'
        self.address2.zip_code = '21234'
        self.address2.state = '2ZH'
        self.address2.country = self.country
        self.address2.is_billing = True
        self.address2.is_shipping = False
        self.address2.save()

        # The order fixture

        self.order = Order()
        self.order.user = self.user
        self.order.order_subtotal = Decimal('100')  # One item worth 100
        self.order.order_total = Decimal('120')  # plus a test field worth 10
        self.order.status = Order.PROCESSING
        ship_address = self.address
        bill_address = self.address2

        self.order.set_shipping_address(ship_address)
        self.order.set_billing_address(bill_address)
        self.order.save()

        # Orderitems
        self.orderitem = OrderItem()
        self.orderitem.order = self.order

        self.orderitem.product_name = 'Test item'
        self.orderitem.unit_price = Decimal("100")
        self.orderitem.quantity = 1

        self.orderitem.line_subtotal = Decimal('100')
        self.orderitem.line_total = Decimal('110')
        self.orderitem.save()

        eoif = ExtraOrderItemPriceField()
        eoif.order_item = self.orderitem
        eoif.label = 'Fake extra field'
        eoif.value = Decimal("10")
        eoif.save()

        eof = ExtraOrderPriceField()
        eof.order = self.order
        eof.label = "Fake Taxes"
        eof.value = Decimal("10")
        eof.save()

    def test01_backend_returns_urls(self):
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls, None)
        self.assertEqual(len(urls), 1)

    def test02_must_be_logged_in_if_setting_is_true(self):
        with SettingsOverride(SHOP_FORCE_LOGIN=True):
            resp = self.client.get(reverse('pay-on-delivery'))
            self.assertEqual(resp.status_code, 302)
            self.assertTrue('accounts/login/' in resp._headers['location'][1])

    def test_order_required_before_payment(self):
        """ See issue #84 """
        # Session only (no order)
        response = self.client.get(reverse('pay-on-delivery'))
        self.assertEqual(302, response.status_code)
        self.assertEqual('http://testserver/shop/cart/',
                         response._headers['location'][1])

        # User logged in (no order)
        username = '******'
        pw = 'pass'
        User.objects.create_user(username=username,
                                 password=pw,
                                 email='*****@*****.**')
        logged_in = self.client.login(username=username, password=pw)
        self.assertTrue(logged_in)
        response = self.client.get(reverse('pay-on-delivery'))
        self.assertEqual(302, response.status_code)
        self.assertEqual('http://testserver/shop/cart/',
                         response._headers['location'][1])
        self.client.logout()

        # User logged in and has order
        self.user.set_password('blah')
        self.user.save()
        logged_in = self.client.login(username=self.user.username,
                                      password='******')
        self.assertTrue(logged_in)
        response = self.client.get(reverse('pay-on-delivery'))
        self.assertTrue(
            reverse('thank_you_for_your_order') in
            response._headers['location'][1])