Beispiel #1
0
class OrderConversionTestCase(TestCase):
    
    PRODUCT_PRICE = Decimal('100')
    TEN_PERCENT = Decimal(10) / Decimal(100)
    
    def create_fixtures(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 = Client()
        self.client.user = self.user
        self.client.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 = True
        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()
    
    def test_01_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.create_fixtures()
        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(o.order_subtotal, self.cart.subtotal_price)
        self.assertEqual(o.order_total, self.cart.total_price)

    def test_02_create_order_from_taxed_cart(self):
        '''
        This time assert that everything is consistent with a tax cart modifier
        '''
        self.create_fixtures()
        MODIFIERS = ['shop.cart.modifiers.tax_modifiers.TenPercentTaxModifier']
        
        with SettingsOverride(SHOP_PRICE_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))
            
            # 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)
            
    def test_03_order_addresses_match_user_preferences(self):
        self.create_fixtures()
        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)
        # 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_04_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...)
        '''
        self.create_fixtures()
        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)
        
        # take the first item from the order:
        oi = OrderItem.objects.filter(order=o)[0]
        self.assertEqual(oi.product_reference, str(self.product.id))
        
        # Lookup works?
        prod = oi.product
        self.assertEqual(prod,self.product)
Beispiel #2
0
class PayOnDeliveryTestCase(TestCase):
    
    def create_fixtures(self):
        self.user = User.objects.create(username="******", 
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name = "Toto")
        self.user.save()
        
        self.client = Client()
        self.client.user = self.user
        self.client.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.address.client.user.first_name, 
                                              self.address.client.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.address.client.user.first_name, 
                                              self.address.client.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()
    
    def test_01_backend_returns_urls(self):
        self.create_fixtures()
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls,None)
        self.assertEqual(len(urls), 1)
Beispiel #3
0
class ClientTestCase(TestCase):
    
    def setUp(self):
        self.user = User.objects.create(username="******", 
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name = "Toto")
        
        self.client = Client()
        self.client.user = self.user
        self.client.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()
    
    def tearDown(self):
        self.user.delete()
    
    def test_01_shipping_address_shortcut_works(self):
        add = self.client.shipping_address()
        self.assertEqual(add, self.address)
    
    def test_02_billing_address_shortcut_works(self):
        add = self.client.billing_address()
        self.assertEqual(add, self.address2)
        
    def test_03_unicode_method_works(self):
        expected = "ClientProfile for Test Toto"
        text = self.client.__unicode__()
        self.assertEqual(expected, text)
        
    def test_04_unicode_method_works_for_null_user_info(self):
        u = User.objects.create(username="******", 
                                        email="*****@*****.**")
        
        expected = "test2"
        text = u.__unicode__()
        self.assertEqual(expected, text)
        
        u.delete()
Beispiel #4
0
class PayOnDeliveryTestCase(TestCase):
    def create_fixtures(self):
        self.user = User.objects.create(username="******",
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name="Toto")
        self.user.save()

        self.client = Client()
        self.client.user = self.user
        self.client.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.address.client.user.first_name,
            self.address.client.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.address.client.user.first_name,
            self.address.client.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()

    def test_01_backend_returns_urls(self):
        self.create_fixtures()
        be = PayOnDeliveryBackend(shop=PaymentAPI())
        urls = be.get_urls()
        self.assertNotEqual(urls, None)
        self.assertEqual(len(urls), 1)
Beispiel #5
0
class ClientTestCase(TestCase):
    
    def create_fixtures(self):
        self.user = User.objects.create(username="******", 
                                        email="*****@*****.**",
                                        first_name="Test",
                                        last_name = "Toto")
        
        self.client = Client()
        self.client.user = self.user
        self.client.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()
    
    def test_01_shipping_address_shortcut_works(self):
        self.create_fixtures()
        add = self.client.shipping_address()
        self.assertEqual(add, self.address)
    
    def test_02_billing_address_shortcut_works(self):
        self.create_fixtures()
        add = self.client.billing_address()
        self.assertEqual(add, self.address2)
        
    def test_03_unicode_method_works(self):
        self.create_fixtures()
        expected = "ClientProfile for Test Toto"
        text = self.client.__unicode__()
        self.assertEqual(expected, text)
        
    def test_04_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()