def setUp(self):
        self.factory = test.RequestFactory()
        from django.contrib.sessions.backends.file import SessionStore

        store = SessionStore()
        store.save()
        self.session = store
Beispiel #2
0
class AddedToCartTestCase(TestCase):
    """
    """

    fixtures = ["lfs_shop.xml"]

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(
            name="Product 1", slug="product-1", price=10.0, active=True, manage_stock_amount=False
        )
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(response.find(u"Total: $10.00") == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, "en_US.UTF-8")

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $40.00") == -1)
    def setUp(self):
        self.factory = test.RequestFactory()
        from django.contrib.sessions.backends.file import SessionStore

        store = SessionStore()
        store.save()
        self.session = store
Beispiel #4
0
 def setUp(self):
     """
     """
     self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True)
     self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
     self.user = User.objects.create(username="******")
     self.session = SessionStore()
     self.session.save()
Beispiel #5
0
    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()
Beispiel #6
0
    def test_standard_product(self):
        session = SessionStore()
        rf = RequestFactory()

        request = rf.post("/", {"product_id": self.p0.id, "quantity": 1})
        request.session = session
        request.user = AnonymousUser()

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        # 1l login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(cart, None)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        # logout
        session = SessionStore()
        request = rf.post("/", {"product_id": self.p0.id, "quantity": 2})
        request.session = session
        request.user = AnonymousUser()

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 2)

        # 2. login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 3)
Beispiel #7
0
    def test_has_rated(self):
        """
        """
        self.factory = RequestFactory()
        request = self.factory.get('/')
        request.user = AnonymousUser()
        request.session = SessionStore()
        request.session.create()

        # Create some dummy pages
        self.page_1 = FlatPage.objects.create(url="/test-1/", title="Test 1")
        self.page_2 = FlatPage.objects.create(url="/test-2/", title="Test 2")

        # At first nobody has rated
        self.assertEqual(reviews.utils.has_rated(request, self.page_1), False)
        self.assertEqual(reviews.utils.has_rated(request, self.page_2), False)

        # Rate for page 1
        Review.objects.create(content=self.page_1,
                              score=6.0,
                              active=True,
                              session_id=request.session.session_key)
        self.assertEqual(reviews.utils.has_rated(request, self.page_1), True)
        self.assertEqual(reviews.utils.has_rated(request, self.page_2), False)

        # Rate for page 2
        Review.objects.create(content=self.page_2,
                              score=6.0,
                              active=True,
                              session_id=request.session.session_key)
        self.assertEqual(reviews.utils.has_rated(request, self.page_1), True)
        self.assertEqual(reviews.utils.has_rated(request, self.page_2), True)
Beispiel #8
0
    def setUp(self):
        """
        """
        self.request = RequestFactory().get("/")
        self.request.session = SessionStore()
        self.request.user = User(id=1)

        self.vg = VoucherGroup.objects.create(
            name="xmas",
            creator=self.request.user,
        )

        self.v1 = Voucher.objects.create(
            number="AAAA",
            group=self.vg,
            creator=self.request.user,
            start_date=datetime.date(2009, 12, 1),
            end_date=datetime.date(2009, 12, 31),
            effective_from=0,
            kind_of=ABSOLUTE,
            value=10.0,
            limit=2,
        )

        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True)
        self.p2 = Product.objects.create(name="Product 2", slug="product-2", price=100.0, active=True)

        self.cart = Cart.objects.create()
        CartItem.objects.create(cart=self.cart, product=self.p1, amount=1)
        CartItem.objects.create(cart=self.cart, product=self.p2, amount=1)
Beispiel #9
0
    def setUp(self):
        """
        """
        self.request = RequestFactory().get("/")
        self.request.session = SessionStore()
        self.request.user = User(id=1)

        self.tax = Tax.objects.create(rate=19.0)

        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0,
                                         tax=self.tax,
                                         active=True)
        self.p2 = Product.objects.create(name="Product 2",
                                         slug="product-2",
                                         price=100.0,
                                         tax=self.tax,
                                         active=True)
        # This product is not considered as it is not active
        self.p3 = Product.objects.create(name="Product 3",
                                         slug="product-3",
                                         price=1000.0,
                                         tax=self.tax,
                                         active=False)

        self.cart = Cart.objects.create()
        CartItem.objects.create(cart=self.cart, product=self.p1, amount=1)
        CartItem.objects.create(cart=self.cart, product=self.p2, amount=1)
        CartItem.objects.create(cart=self.cart, product=self.p3, amount=1)
Beispiel #10
0
    def factory(name, **content):
        channel_layer = ChannelLayer()
        message = Message(content, name, channel_layer)
        settings.SESSION_FILE_PATH = str(tmpdir)
        message.channel_session = SessionStore()

        return message
Beispiel #11
0
def create_request():
    """
    """
    rf = RequestFactory()
    request = rf.get('/')
    request.session = SessionStore()

    return request
Beispiel #12
0
 def setUp(self):
     """
     """
     self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True)
     self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
     self.user = User.objects.create(username="******")
     self.session = SessionStore()
     self.session.save()
Beispiel #13
0
    def setUp(self):
        """
        """
        shop = lfs.core.utils.get_default_shop()
        shop.price_calculator = "lfs.net_price.NetPriceCalculator"
        shop.save()

        self.request = RequestFactory().get("/")
        self.request.session = SessionStore()

        # set up our price calculator
        self.orig_price_calculator = lfs_settings.LFS_DEFAULT_PRICE_CALCULATOR
        lfs_settings.LFS_DEFAULT_PRICE_CALCULATOR = "lfs.net_price.NetPriceCalculator"

        # Create a tax
        self.t1 = Tax.objects.create(rate=19.0)

        # A product with properties and variants
        self.p1 = Product.objects.create(
            name=u"Product 1",
            slug=u"product-1",
            sku=u"SKU P1",
            description=u"Description",
            short_description=u"Short description product 1",
            meta_description=u"Meta description product 1",
            meta_keywords=u"Meta keywords product 1",
            sub_type=PRODUCT_WITH_VARIANTS,
            tax=self.t1,
            price=1.0,
            for_sale_price=0.5,
            stock_amount=2,
            width=1.0,
            height=2.0,
            length=3.0,
            weight=4.0,
            active=True)

        # Products without properties and variants
        self.p2 = Product.objects.create(name=u"Product 2", slug=u"product-2", active=True)

        # Add a variant with color = red, size = m
        self.v1 = Product.objects.create(
            name=u"Variant 1",
            slug=u"variant-1",
            sku=u"SKU V1",
            description=u"This is the description of variant 1",
            meta_description=u"Meta description of variant 1",
            meta_keywords=u"Meta keywords variant 1",
            sub_type=VARIANT,
            price=2.0,
            for_sale_price=1.5,
            parent=self.p1,
            width=11.0,
            height=12.0,
            length=13.0,
            weight=14.0,
            active=True,
        )
Beispiel #14
0
def init_request():
    request = HttpRequest()
    request.method = 'GET'
    request.session = SessionStore()
    request.session.create()
    request._messages = BaseStorage(request)
    request.user = AnonymousUser()

    return request
Beispiel #15
0
    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()
Beispiel #16
0
    def test_request_has_processing_done_attribute(self):
        """
        Test that the request has a 'csrf processing done' attribute.
        """
        request = self.factory.get('/')
        csrf_mw = CsrfViewMiddleware()

        request.session = SessionStore(session_key='abc')
        result = csrf_mw.process_view(request, our_text_plain_view, [], {})
        self.assertEqual(request.csrf_processing_done, True)
        self.assertEqual(result, None)
Beispiel #17
0
    def setUp(self):
        """
        """
        self.request = RequestFactory().get("/")
        self.request.session = SessionStore()
        self.request.user = AnonymousUser()

        # Create a tax
        self.t1 = Tax.objects.create(rate=19.0)

        # A product with properties and variants
        self.p1 = Product.objects.create(
            name=u"Product 1",
            slug=u"product-1",
            sku=u"SKU P1",
            description=u"Description",
            short_description=u"Short description product 1",
            meta_description=u"Meta description product 1",
            meta_keywords=u"Meta keywords product 1",
            sub_type=PRODUCT_WITH_VARIANTS,
            tax=self.t1,
            price=1.0,
            for_sale_price=0.5,
            stock_amount=2,
            width=1.0,
            height=2.0,
            length=3.0,
            weight=4.0,
            active=True)

        # Products without properties and variants
        self.p2 = Product.objects.create(name=u"Product 2",
                                         slug=u"product-2",
                                         active=True)

        # Add a variant with color = red, size = m
        self.v1 = Product.objects.create(
            name=u"Variant 1",
            slug=u"variant-1",
            sku=u"SKU V1",
            description=u"This is the description of variant 1",
            meta_description=u"Meta description of variant 1",
            meta_keywords=u"Meta keywords variant 1",
            sub_type=VARIANT,
            price=2.0,
            for_sale_price=1.5,
            parent=self.p1,
            width=11.0,
            height=12.0,
            length=13.0,
            weight=14.0,
            active=True,
        )
Beispiel #18
0
    def test_ga_ecommerce_tracking(self):
        """
        """
        shop = lfs.core.utils.get_default_shop()
        shop.google_analytics_id = ""
        shop.ga_site_tracking = False
        shop.ga_ecommerce_tracking = False
        shop.save()

        session = SessionStore()

        rf = RequestFactory()
        request = rf.get('/')
        request.session = session

        template = get_template_from_string(
            """{% load lfs_tags %}{% google_analytics_ecommerce %}""")

        content = template.render(Context({"request": request}))
        self.failIf(content.find("pageTracker") != -1)

        # Enter a google_analytics_id
        shop.google_analytics_id = "UA-XXXXXXXXXX"
        shop.save()

        # Simulating a new request
        rf = RequestFactory()
        request = rf.get('/')
        request.session = session

        # But this is not enough
        content = template.render(Context({"request": request}))
        self.failIf(content.find("pageTracker") != -1)

        # It has to be activated first
        shop.ga_ecommerce_tracking = True
        shop.save()

        # Simulating a new request
        rf = RequestFactory()
        request = rf.get('/')
        request.session = session

        # But this is still not enough
        content = template.render(Context({"request": request}))
        self.failIf(content.find("pageTracker") != -1)

        # There has to be an order within the session
        session["order"] = Order()

        # Now it works and "pageTracker" is found
        content = template.render(Context({"request": request}))
        self.failIf(content.find("_trackPageview") == -1)
Beispiel #19
0
def create_request(user=None):
    """
    """
    rf = RequestFactory()
    request = rf.get('/')
    request.session = SessionStore()
    if user:
        request.user = user
    else:
        request.user = User(first_name="John Doe", email="*****@*****.**")

    return request
Beispiel #20
0
def create_request():
    """
    """
    rf = RequestFactory()
    request = rf.get('/')
    request.session = SessionStore()

    user = User()
    user.is_superuser = True
    user.save()
    request.user = user

    return request
Beispiel #21
0
def create_request():
    """
    """
    rf = RequestFactory()
    request = rf.get('/')
    request.session = SessionStore()

    actor = Actor()
    #actor.is_supeactor = True
    actor.save()
    request.actor = actor

    return request
Beispiel #22
0
    def test_copy(self):
        """
        Tests the history after an object has been copied.
        """
        request = RequestFactory().get("/", {"transition": 1})
        request.user = self.user
        request.session = SessionStore()

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 1)

        lfc_copy(request, self.p1.id)

        self.assertEqual(History.objects.count(), 1)
Beispiel #23
0
    def setUp(self):
        """
        """
        self.request = RequestFactory().get("/")
        self.request.session = SessionStore()
        self.request.user = User(id=1)

        self.tax = Tax.objects.create(rate=19.0)

        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, tax=self.tax)
        self.p2 = Product.objects.create(name="Product 2", slug="product-2", price=100.0, tax=self.tax)

        self.cart = Cart.objects.create()
        CartItem.objects.create(cart=self.cart, product=self.p1, amount=1)
        CartItem.objects.create(cart=self.cart, product=self.p2, amount=1)
Beispiel #24
0
    def setUp(self):
        management.call_command('avocado', 'init', 'tests', quiet=True)

        f1 = DataField.objects.get(pk=1)
        f2 = DataField.objects.get(pk=2)

        c1 = DataConcept()
        c1.save()

        DataConceptField(concept=c1, field=f1).save()
        DataConceptField(concept=c1, field=f2).save()

        self.request = HttpRequest()
        self.request.session = SessionStore()
        self.request.session.save()
Beispiel #25
0
def create_request(path="/", params=None):
    """
    """
    if params is None:
        params = {}

    rf = RequestFactory()
    request = rf.get(path, params)
    request.session = SessionStore()

    user = User()
    user.is_superuser = True
    user.save()
    request.user = user

    return request
Beispiel #26
0
    def setUp(self):
        management.call_command('avocado', 'init', 'tests', quiet=True)

        f1 = DataField.objects.get_by_natural_key('tests', 'employee',
                                                  'first_name')
        f2 = DataField.objects.get_by_natural_key('tests', 'employee',
                                                  'last_name')

        self.c = DataConcept()
        self.c.save()

        DataConceptField(concept=self.c, field=f1).save()
        DataConceptField(concept=self.c, field=f2).save()

        self.request = HttpRequest()
        self.request.session = SessionStore()
        self.request.session.save()
Beispiel #27
0
    def test_change_workflow_state(self):
        """
        For each change a history object should be created.
        """
        request = RequestFactory().get("/", {"transition": 1})
        request.user = self.user
        request.session = SessionStore()

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 1)

        do_transition(request, self.p1.id)
        self.assertEqual(History.objects.count(), 2)

        # Delete content object
        self.p1.delete()

        self.assertEqual(History.objects.count(), 0)
Beispiel #28
0
class AddedToCartTestCase(TestCase):
    """
    """
    fixtures = ['lfs_shop.xml']

    def setUp(self):
        """
        """
        from lfs.customer.models import Customer
        from lfs.addresses.models import Address
        from lfs.shipping.models import ShippingMethod
        from lfs.payment.models import PaymentMethod
        from lfs.core.models import Country

        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True, manage_stock_amount=False)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.session = SessionStore()
        self.session.save()

        self.username = '******'
        self.password = '******'

        self.user = User.objects.create(username=self.username)

        self.user.set_password(self.password)
        self.user.save()

        tax = Tax.objects.create(rate=19)
        de = Country.objects.get(code="de")

        shipping_method = ShippingMethod.objects.create(
            name="Standard",
            active=True,
            price=1.0,
            tax=tax
        )

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

        self.address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="23422",
            country=de,
            phone="555-111111",
            email="*****@*****.**",
        )

        address_1_id = self.address1.pk

        self.address1.pk = None
        self.address2 = self.address1.save()

        self.address1.pk = None
        self.address3 = self.address1.save()

        self.address1.pk = None
        self.address4 = self.address1.save()

        self.address1 = Address.objects.get(pk=address_1_id)

        self.customer = Customer.objects.create(
            user=self.user,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=self.address1,
            selected_invoice_address=self.address2,
            default_shipping_address=self.address3,
            default_invoice_address=self.address4,
        )

    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(response.find(u'Total: <span class="money">$10.00</span>') == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u'Total: <span class="money">$20.00</span>') == -1)

    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u'Total: <span class="money">$20.00</span>') == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u'Total: <span class="money">$40.00</span>') == -1)

    def test_discounts(self):
        """Add a product with explicit quantity to cart and use discounts/voucher
           Discount 'Summer' and Voucher are able to sum up while discount 'Special offer 1' cannot be summed up.
           Value of summed up 'Summer' and Voucher is bigger than 'Special offer 1' so these two should be used
        """
        from lfs.discounts.models import Discount
        from lfs.discounts.settings import DISCOUNT_TYPE_ABSOLUTE

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

        discount = Discount.objects.create(name="Summer",
                                           active=True,
                                           value=3.0,
                                           type=DISCOUNT_TYPE_ABSOLUTE,
                                           tax=tax,
                                           sums_up=True)

        discount_value = 2.0
        discount = Discount.objects.create(name="Special offer 1",
                                           active=True,
                                           value=discount_value,
                                           type=DISCOUNT_TYPE_ABSOLUTE,
                                           tax=tax,
                                           sums_up=False)

        # vouchers
        from lfs.voucher.models import VoucherGroup, Voucher
        from lfs.voucher.settings import ABSOLUTE

        user = User.objects.get(username=self.username)

        self.vg = VoucherGroup.objects.create(
            name="xmas",
            creator=user
        )
        voucher_value = 1.0

        self.v1 = Voucher.objects.create(
            number="AAAA",
            group=self.vg,
            creator=user,
            start_date=datetime.date.today() + datetime.timedelta(days=-10),
            end_date=datetime.date.today() + datetime.timedelta(days=10),
            effective_from=0,
            kind_of=ABSOLUTE,
            value=voucher_value,
            sums_up=True,
            limit=2,
            tax=tax
        )

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        add_to_cart(request)
        self.client.login(username=self.username, password=self.password)
        response = self.client.post(reverse('lfs_cart'), data={'voucher': self.v1.number})

        self.assertNotContains(response, 'Special offer 1')
        self.assertContains(response, 'Summer')
        self.assertContains(response, 'Voucher')
        self.assertContains(response, 'The voucher is valid')
Beispiel #29
0
class AddToCartTestCase(TestCase):
    """Test case for add_to_cart view.
    """

    fixtures = ["lfs_shop.xml"]

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_add_to_cart_non_active(self):
        """Try to add product to the cart which is not active.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        self.assertRaises(Http404, add_to_cart, request, self.p1.id)

    def test_add_to_cart_not_deliverable(self):
        """Try to add product to the cart which is not deliverable.
        """
        self.p1.active = True
        self.p1.deliverable = False
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Not deliverable
        self.assertRaises(Http404, add_to_cart, request, self.p1.id)

    def test_add_to_cart_not_in_stock(self):
        """Try to add product to the cart which is not in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 0
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        self.assertRaises(Http404, add_to_cart, request)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

    def test_add_to_cart_stock_1(self):
        """Try to add product two times to cart if only one is in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        # This need to result in a message to the customer
        result = add_to_cart(request)
        self.failIf(
            result.cookies.get("message")
            .__str__()
            .find("Sorry%2C%20but%20%27Product%201%27%20is%20only%20one%20time%20available.")
            == -1
        )

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

    def test_add_to_cart_stock_2(self):
        """Try to add product three times to cart if only two is in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 2
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 3})
        request.session = self.session
        request.user = self.user

        # This need to result in a message to the customer
        result = add_to_cart(request)
        self.failIf(
            result.cookies.get("message")
            .__str__()
            .find("Sorry%2C%20but%20%27Product%201%27%20is%20only%202.0%20times%20available.")
            == -1
        )

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)
Beispiel #30
0
class RefreshCartTestCase(TestCase):
    """Test case for refresh_cart view.
    """

    fixtures = ["lfs_shop.xml"]

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True)
        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Refresh item amount
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)

    def test_amount_2(self):
        """Manage stock amount; refresh to 2 only 1 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Try to increase item to two, but there is only one in stock
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        # This results into a message to the customer
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but 'Product 1' is only one time available.")

        # And the amount of the item is still 1.0
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

    def test_amount_3(self):
        """Manage stock amount; refresh to 3 only 2 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 2
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Increase items to two
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Try to increase item to 3, but there are only 2 in stock
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 3})
        request.session = self.session
        request.user = self.user

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but 'Product 1' is only 2.0 times available.")

        # And the amount of the item is still 2.0
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)

    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        self.p1.stock_amount = 0
        self.p1.save()

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post("/", {"product_id": self.p1.id, "amount-cart-item_%s" % cart.get_items()[0].id: 2})
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "Sorry, but 'Product 1' is not available anymore.")
        self.assertEqual(cart.get_amount_of_items(), 0.0)
Beispiel #31
0
class AddedToCartTestCase(TestCase):
    """
    """
    fixtures = ['lfs_shop.xml']

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0,
                                         active=True,
                                         manage_stock_amount=False)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1,
                                              max=2,
                                              unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(response.find(u"Total: $10.00") == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $20.00") == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(response.find(u"Total: $40.00") == -1)
Beispiel #32
0
    def setUp(self):
        """
        """
        from lfs.customer.models import Customer
        from lfs.addresses.models import Address
        from lfs.shipping.models import ShippingMethod
        from lfs.payment.models import PaymentMethod
        from lfs.core.models import Country

        self.p1 = Product.objects.create(name="Product 1", slug="product-1", price=10.0, active=True, manage_stock_amount=False)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1, max=2, unit=DELIVERY_TIME_UNIT_DAYS)
        self.session = SessionStore()
        self.session.save()

        self.username = '******'
        self.password = '******'

        self.user = User.objects.create(username=self.username)

        self.user.set_password(self.password)
        self.user.save()

        tax = Tax.objects.create(rate=19)
        de = Country.objects.get(code="de")

        shipping_method = ShippingMethod.objects.create(
            name="Standard",
            active=True,
            price=1.0,
            tax=tax
        )

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

        self.address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="23422",
            country=de,
            phone="555-111111",
            email="*****@*****.**",
        )

        address_1_id = self.address1.pk

        self.address1.pk = None
        self.address2 = self.address1.save()

        self.address1.pk = None
        self.address3 = self.address1.save()

        self.address1.pk = None
        self.address4 = self.address1.save()

        self.address1 = Address.objects.get(pk=address_1_id)

        self.customer = Customer.objects.create(
            user=self.user,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=self.address1,
            selected_invoice_address=self.address2,
            default_shipping_address=self.address3,
            default_invoice_address=self.address4,
        )
Beispiel #33
0
class RefreshCartTestCase(TestCase):
    """Test case for refresh_cart view.
    """
    fixtures = ['lfs_shop.xml']

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0,
                                         active=True)
        self.dt = DeliveryTime.objects.create(min=1,
                                              max=2,
                                              unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_amount_1(self):
        """Don't manage stock amount.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Refresh item amount
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        refresh_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 2.0)

    def test_amount_2(self):
        """Manage stock amount; refresh to 2 only 1 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Try to increase item to two, but there is only one in stock
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        # This results into a message to the customer
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(
            result.get("message"),
            "Sorry, but \'Product 1\' is only one time available.")

        # And the amount of the item is still 1.0
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

    def test_amount_3(self):
        """Manage stock amount; refresh to 3 only 2 products there.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 2
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        # Increase items to two
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # Try to increase item to 3, but there are only 2 in stock
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 3
            })
        request.session = self.session
        request.user = self.user

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(
            result.get("message"),
            "Sorry, but \'Product 1\' is only 2.0 times available.")

        # And the amount of the item is still 2.0
        self.assertEqual(cart.get_amount_of_items(), 2.0)

        # If the product is ordered the customer can add it into cart again
        self.p1.order_time = self.dt
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)

        # Or if LFS not managing stock amount the product can be added to the cart
        self.p1.order_time = None
        self.p1.manage_stock_amount = False
        self.p1.save()

        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"), "")
        self.assertEqual(cart.get_amount_of_items(), 3.0)

    def test_amount_4(self):
        """Manage stock amount; refresh to 2 but no product is there anymore.
        """
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Add product to cart
        result = add_to_cart(request)

        cart = lfs.cart.utils.get_cart(request)
        self.assertEqual(cart.get_amount_of_items(), 1.0)

        self.p1.stock_amount = 0
        self.p1.save()

        # Try to increase item to two, but there is no product in stock anymore
        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "amount-cart-item_%s" % cart.get_items()[0].id: 2
            })
        request.session = self.session
        request.user = self.user

        # Refresh to amount of two is not possible
        result = simplejson.loads(refresh_cart(request).content)
        self.assertEqual(result.get("message"),
                         "Sorry, but 'Product 1' is not available anymore.")
        self.assertEqual(cart.get_amount_of_items(), 0.0)
Beispiel #34
0
class AddToCartTestCase(TestCase):
    """Test case for add_to_cart view.
    """
    fixtures = ['lfs_shop.xml']

    def setUp(self):
        """
        """
        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1,
                                              max=2,
                                              unit=DELIVERY_TIME_UNIT_DAYS)
        self.user = User.objects.create(username="******")
        self.session = SessionStore()
        self.session.save()

    def test_add_to_cart_non_active(self):
        """Try to add product to the cart which is not active.
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        self.assertRaises(Http404, add_to_cart, request, self.p1.id)

    def test_add_to_cart_not_deliverable(self):
        """Try to add product to the cart which is not deliverable.
        """
        self.p1.active = True
        self.p1.deliverable = False
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 1})
        request.session = self.session
        request.user = self.user

        # Not deliverable
        self.assertRaises(Http404, add_to_cart, request, self.p1.id)

    def test_add_to_cart_not_in_stock(self):
        """Try to add product to the cart which is not in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 0
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        self.assertRaises(Http404, add_to_cart, request)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

    def test_add_to_cart_stock_1(self):
        """Try to add product two times to cart if only one is in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 1
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        # This need to result in a message to the customer
        result = add_to_cart(request)
        self.failIf(
            result.cookies.get("message").__str__().find(
                "Sorry%2C%20but%20%27Product%201%27%20is%20only%20one%20time%20available."
            ) == -1)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

    def test_add_to_cart_stock_2(self):
        """Try to add product three times to cart if only two is in stock.
        """
        self.p1.active = True
        self.p1.deliverable = True
        self.p1.manage_stock_amount = True
        self.p1.stock_amount = 2
        self.p1.save()

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 3})
        request.session = self.session
        request.user = self.user

        # This need to result in a message to the customer
        result = add_to_cart(request)
        self.failIf(
            result.cookies.get("message").__str__().find(
                "Sorry%2C%20but%20%27Product%201%27%20is%20only%202.0%20times%20available."
            ) == -1)

        # But no message if product is ordered ...
        self.p1.order_time = self.dt
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)

        # ... or LFS doesn't manage stock amount
        self.p1.manage_stock_amount = False
        self.p1.order_time = None
        self.p1.save()

        result = add_to_cart(request)
        self.failIf("message" in result.cookies)
Beispiel #35
0
    def test_configurable_product(self):
        rf = RequestFactory()
        session = SessionStore()

        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "quantity": 1,
                "property-%s" % self.pp1.id: "A"
            })
        request.session = session
        request.user = AnonymousUser()

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)

        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "quantity": 10,
                "property-%s" % self.pp1.id: "B"
            })
        request.session = session
        request.user = AnonymousUser()
        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)
        self.assertEqual(int(cart.get_items()[1].amount), 10)

        # 1. login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(cart, None)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)
        self.assertEqual(int(cart.get_items()[1].amount), 10)

        # logout
        session = SessionStore()

        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "quantity": 2,
                "property-%s" % self.pp1.id: "A"
            })
        request.session = session
        request.user = AnonymousUser()

        cart = get_cart(request)
        self.assertEqual(cart, None)

        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 2)

        request = rf.post(
            "/", {
                "product_id": self.p1.id,
                "quantity": 20,
                "property-%s" % self.pp1.id: "B"
            })
        request.session = session
        request.user = AnonymousUser()
        add_to_cart(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 2)
        self.assertEqual(int(cart.get_items()[1].amount), 20)

        # 2. login admin
        request = rf.get("/")
        request.session = session
        request.user = self.admin

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 1)
        self.assertEqual(int(cart.get_items()[1].amount), 10)

        update_cart_after_login(request)

        cart = get_cart(request)
        self.assertEqual(int(cart.get_items()[0].amount), 3)
        self.assertEqual(int(cart.get_items()[1].amount), 30)
Beispiel #36
0
    def setUp(self):
        self.factory = test.RequestFactory()

        store = SessionStore()
        store.save()
        self.session = store
Beispiel #37
0
    def setUp(self):
        """
        """
        session = SessionStore()
        session.save()

        rf = RequestFactory()
        self.request = rf.get('/')
        self.request.session = session
        self.request.user = AnonymousUser()

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

        delivery_time = DeliveryTime.objects.create(min=3, max=10)

        shipping_method = ShippingMethod.objects.create(
            name="Standard",
            active=True,
            price=1.0,
            tax=tax,
            delivery_time=delivery_time)

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

        us = Country.objects.get(code="us")
        ie = Country.objects.get(code="ie")

        address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="2342",
            country=ie,
            phone="555-111111",
            email="*****@*****.**",
        )

        address2 = Address.objects.create(
            firstname="Jane",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 43",
            city="Smallville",
            zip_code="2443",
            country=us,
            phone="666-111111",
            email="*****@*****.**",
        )

        Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="2342",
            country=ie,
            phone="555-111111",
            email="*****@*****.**",
        )

        Address.objects.create(
            firstname="Jane",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 43",
            city="Smallville",
            zip_code="2443",
            country=us,
            phone="666-111111",
            email="*****@*****.**",
        )

        self.customer = Customer.objects.create(
            session=session.session_key,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=address1,
            selected_invoice_address=address2,
            default_shipping_address=address1,
            default_invoice_address=address2,
        )

        self.p1 = Product.objects.create(
            name="Product 1",
            slug="product-1",
            sku="sku-1",
            price=1.1,
            tax=tax,
            active=True,
        )

        self.p2 = Product.objects.create(
            name="Product 2",
            slug="product-2",
            sku="sku-2",
            price=2.2,
            tax=tax,
            active=True,
        )

        cart = Cart.objects.create(session=session.session_key)

        CartItem.objects.create(
            cart=cart,
            product=self.p1,
            amount=2,
        )

        CartItem.objects.create(
            cart=cart,
            product=self.p2,
            amount=3,
        )
Beispiel #38
0
class AddedToCartTestCase(TestCase):
    """
    """
    fixtures = ['lfs_shop.xml']

    def setUp(self):
        """
        """
        from lfs.customer.models import Customer
        from lfs.addresses.models import Address
        from lfs.shipping.models import ShippingMethod
        from lfs.payment.models import PaymentMethod
        from lfs.core.models import Country

        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0,
                                         active=True,
                                         manage_stock_amount=False)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1,
                                              max=2,
                                              unit=DELIVERY_TIME_UNIT_DAYS)
        self.session = SessionStore()
        self.session.save()

        self.username = '******'
        self.password = '******'

        self.user = User.objects.create(username=self.username)

        self.user.set_password(self.password)
        self.user.save()

        tax = Tax.objects.create(rate=19)
        de = Country.objects.get(code="de")

        shipping_method = ShippingMethod.objects.create(name="Standard",
                                                        active=True,
                                                        price=1.0,
                                                        tax=tax)

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

        self.address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="23422",
            country=de,
            phone="555-111111",
            email="*****@*****.**",
        )

        address_1_id = self.address1.pk

        self.address1.pk = None
        self.address2 = self.address1.save()

        self.address1.pk = None
        self.address3 = self.address1.save()

        self.address1.pk = None
        self.address4 = self.address1.save()

        self.address1 = Address.objects.get(pk=address_1_id)

        self.customer = Customer.objects.create(
            user=self.user,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=self.address1,
            selected_invoice_address=self.address2,
            default_shipping_address=self.address3,
            default_invoice_address=self.address4,
        )

    def test_totals_1(self):
        """Add a product without quantity to cart (implicit 1)
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 to cart
        add_to_cart(request)
        response = added_to_cart_items(request)

        # need to test for two versions of currency output (Mac and Ubuntu differ)
        self.failIf(
            response.find(u'Total: <span class="money">$10.00</span>') == -1)

        # Added product_1 to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(
            response.find(u'Total: <span class="money">$20.00</span>') == -1)

    def test_totals_2(self):
        """Add a product with explicit quantity to cart
        """
        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        # Added product_1 two times to cart
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(
            response.find(u'Total: <span class="money">$20.00</span>') == -1)

        # Added product_1 two times to cart again
        add_to_cart(request)
        response = added_to_cart_items(request)
        self.failIf(
            response.find(u'Total: <span class="money">$40.00</span>') == -1)

    def test_discounts(self):
        """Add a product with explicit quantity to cart and use discounts/voucher
           Discount 'Summer' and Voucher are able to sum up while discount 'Special offer 1' cannot be summed up.
           Value of summed up 'Summer' and Voucher is bigger than 'Special offer 1' so these two should be used
        """
        from lfs.discounts.models import Discount
        from lfs.discounts.settings import DISCOUNT_TYPE_ABSOLUTE

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

        Discount.objects.create(name="Summer",
                                active=True,
                                value=3.0,
                                type=DISCOUNT_TYPE_ABSOLUTE,
                                tax=tax,
                                sums_up=True)

        discount_value = 2.0
        Discount.objects.create(name="Special offer 1",
                                active=True,
                                value=discount_value,
                                type=DISCOUNT_TYPE_ABSOLUTE,
                                tax=tax,
                                sums_up=False)

        # vouchers
        from lfs.voucher.models import VoucherGroup, Voucher
        from lfs.voucher.settings import ABSOLUTE

        user = User.objects.get(username=self.username)

        self.vg = VoucherGroup.objects.create(name="xmas", creator=user)
        voucher_value = 1.0

        self.v1 = Voucher.objects.create(
            number="AAAA",
            group=self.vg,
            creator=user,
            start_date=datetime.date.today() + datetime.timedelta(days=-10),
            end_date=datetime.date.today() + datetime.timedelta(days=10),
            effective_from=0,
            kind_of=ABSOLUTE,
            value=voucher_value,
            sums_up=True,
            limit=2,
            tax=tax)

        rf = RequestFactory()
        request = rf.post("/", {"product_id": self.p1.id, "quantity": 2})
        request.session = self.session
        request.user = self.user

        locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')

        add_to_cart(request)
        self.client.login(username=self.username, password=self.password)
        response = self.client.post(reverse('lfs_cart'),
                                    data={'voucher': self.v1.number})

        self.assertNotContains(response, 'Special offer 1')
        self.assertContains(response, 'Summer')
        self.assertContains(response, 'Voucher')
        self.assertContains(response, 'The voucher is valid')
Beispiel #39
0
    def setUp(self):
        """
        """
        session = SessionStore()
        session.save()

        rf = RequestFactory()
        self.request = rf.get('/')
        self.request.session = session
        self.request.user = AnonymousUser()

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

        shipping_method = ShippingMethod.objects.create(
            name="Standard",
            active=True,
            price=1.0,
            tax=tax
        )

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

        us = Country.objects.get(code="us")
        ie = Country.objects.get(code="ie")

        address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="2342",
            country=ie,
            phone="555-111111",
            email="*****@*****.**",
        )

        address2 = Address.objects.create(
            firstname="Jane",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 43",
            city="Smallville",
            zip_code="2443",
            country=us,
            phone="666-111111",
            email="*****@*****.**",
        )

        address3 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="2342",
            country=ie,
            phone="555-111111",
            email="*****@*****.**",
        )

        address4 = Address.objects.create(
            firstname="Jane",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 43",
            city="Smallville",
            zip_code="2443",
            country=us,
            phone="666-111111",
            email="*****@*****.**",
        )

        self.customer = Customer.objects.create(
            session=session.session_key,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=address1,
            selected_invoice_address=address2,
            default_shipping_address=address1,
            default_invoice_address=address2,
        )

        self.p1 = Product.objects.create(
            name="Product 1",
            slug="product-1",
            sku="sku-1",
            price=1.1,
            tax=tax,
            active=True,
        )

        self.p2 = Product.objects.create(
            name="Product 2",
            slug="product-2",
            sku="sku-2",
            price=2.2,
            tax=tax,
            active=True,
        )

        cart = Cart.objects.create(
            session=session.session_key
        )

        item = CartItem.objects.create(
            cart=cart,
            product=self.p1,
            amount=2,
        )

        item = CartItem.objects.create(
            cart=cart,
            product=self.p2,
            amount=3,
        )
Beispiel #40
0
    def setUp(self):
        """
        """
        from lfs.customer.models import Customer
        from lfs.addresses.models import Address
        from lfs.shipping.models import ShippingMethod
        from lfs.payment.models import PaymentMethod
        from lfs.core.models import Country

        self.p1 = Product.objects.create(name="Product 1",
                                         slug="product-1",
                                         price=10.0,
                                         active=True,
                                         manage_stock_amount=False)
        from django.contrib.auth.models import User

        self.dt = DeliveryTime.objects.create(min=1,
                                              max=2,
                                              unit=DELIVERY_TIME_UNIT_DAYS)
        self.session = SessionStore()
        self.session.save()

        self.username = '******'
        self.password = '******'

        self.user = User.objects.create(username=self.username)

        self.user.set_password(self.password)
        self.user.save()

        tax = Tax.objects.create(rate=19)
        de = Country.objects.get(code="de")

        shipping_method = ShippingMethod.objects.create(name="Standard",
                                                        active=True,
                                                        price=1.0,
                                                        tax=tax)

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

        self.address1 = Address.objects.create(
            firstname="John",
            lastname="Doe",
            company_name="Doe Ltd.",
            line1="Street 42",
            city="Gotham City",
            zip_code="23422",
            country=de,
            phone="555-111111",
            email="*****@*****.**",
        )

        address_1_id = self.address1.pk

        self.address1.pk = None
        self.address2 = self.address1.save()

        self.address1.pk = None
        self.address3 = self.address1.save()

        self.address1.pk = None
        self.address4 = self.address1.save()

        self.address1 = Address.objects.get(pk=address_1_id)

        self.customer = Customer.objects.create(
            user=self.user,
            selected_shipping_method=shipping_method,
            selected_payment_method=payment_method,
            selected_shipping_address=self.address1,
            selected_invoice_address=self.address2,
            default_shipping_address=self.address3,
            default_invoice_address=self.address4,
        )