Exemple #1
0
    def test_set_enterprise_cookie_no_enterprise_customer(self):
        """
        Validate that no cookie is set if no enterprise customer is
        associated with the voucher of given code.
        """
        voucher = VoucherFactory()
        request = RequestFactory().get('/', data={'code': voucher.code})
        request.site = self.site
        response = decorators.set_enterprise_cookie(self._mock_view)(request)

        self.assertNotIn(settings.ENTERPRISE_CUSTOMER_COOKIE_NAME,
                         response.cookies)
    def test_set_enterprise_cookie(self):
        """
        Validate that a cookie is set with UUID of the enterprise customer
        associated with the voucher of given code.
        """
        enterprise_customer_uuid = uuid.uuid4()
        voucher, __ = prepare_voucher(enterprise_customer=enterprise_customer_uuid)
        request = RequestFactory().get('/', data={'code': voucher.code})
        request.site = self.site
        response = decorators.set_enterprise_cookie(self._mock_view)(request)

        cookie = response.cookies[settings.ENTERPRISE_CUSTOMER_COOKIE_NAME]
        self.assertEqual(str(enterprise_customer_uuid), cookie.value)
        self.assertEqual(60, cookie.get('max-age'))