当前位置: 首页>>代码示例>>Python>>正文


Python SessionStore.save方法代码示例

本文整理汇总了Python中django.contrib.sessions.backends.file.SessionStore.save方法的典型用法代码示例。如果您正苦于以下问题:Python SessionStore.save方法的具体用法?Python SessionStore.save怎么用?Python SessionStore.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.contrib.sessions.backends.file.SessionStore的用法示例。


在下文中一共展示了SessionStore.save方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: setUp

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
    def setUp(self):
        self.factory = test.RequestFactory()
        from django.contrib.sessions.backends.file import SessionStore

        store = SessionStore()
        store.save()
        self.session = store
开发者ID:AgentJay,项目名称:oauth2client,代码行数:9,代码来源:test_django_util.py

示例2: AddedToCartTestCase

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
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="doe")
        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)
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:62,代码来源:tests.py

示例3: setUp

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
    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="[email protected]",
        )

        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="[email protected]",
        )

        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="[email protected]",
        )

        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="[email protected]",
        )

        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",
#.........这里部分代码省略.........
开发者ID:DanielChu,项目名称:django-lfs,代码行数:103,代码来源:tests.py

示例4: RefreshCartTestCase

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
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="doe")
        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)
#.........这里部分代码省略.........
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:103,代码来源:tests.py

示例5: AddToCartTestCase

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
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="doe")
        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()

#.........这里部分代码省略.........
开发者ID:jgoodleaf,项目名称:django-lfs,代码行数:103,代码来源:tests.py

示例6: AddedToCartTestCase

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
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 = 'doe'
        self.password = 'bloggs'

        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="[email protected]",
        )

        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)
#.........这里部分代码省略.........
开发者ID:adulenzy,项目名称:django-lfs,代码行数:103,代码来源:tests.py

示例7: setUp

# 需要导入模块: from django.contrib.sessions.backends.file import SessionStore [as 别名]
# 或者: from django.contrib.sessions.backends.file.SessionStore import save [as 别名]
    def setUp(self):
        self.factory = test.RequestFactory()

        store = SessionStore()
        store.save()
        self.session = store
开发者ID:roofcat,项目名称:dtracking,代码行数:8,代码来源:__init__.py


注:本文中的django.contrib.sessions.backends.file.SessionStore.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。