Esempio n. 1
0
    def setUp(self):
        super(VoucherAddViewTests, self).setUp()
        self.user = self.create_user()
        self.client.login(username=self.user.username, password=self.password)
        self.basket = factories.BasketFactory(owner=self.user, site=self.site)

        # Fallback storage is needed in tests with messages
        self.request.user = self.user
        self.request.basket = self.basket

        self.view = VoucherAddView()
        self.view.request = self.request

        self.form = BasketVoucherForm()
        self.form.cleaned_data = {'code': COUPON_CODE}
Esempio n. 2
0
    def setUp(self):
        super(VoucherAddMessagesViewTests, self).setUp()
        self.user = self.create_user()
        self.client.login(username=self.user.username, password=self.password)
        self.basket = factories.BasketFactory(owner=self.user, site=self.site)

        self.request = RequestFactory().request()
        # Fallback storage is needed in tests with messages
        setattr(self.request, 'session', 'session')
        messages = FallbackStorage(self.request)
        setattr(self.request, '_messages', messages)
        self.request.user = self.user

        self.voucher_add_view = VoucherAddMessagesView()
        self.form = BasketVoucherForm()
        self.form.cleaned_data = {'code': COUPON_CODE}
Esempio n. 3
0
    def get_context_data(self, **kwargs):
        context = super(BasketView, self).get_context_data(**kwargs)
        context['voucher_form'] = BasketVoucherForm()

        if self.request.user.is_authenticated():
            try:
                saved_basket = self.basket_model.saved.get(
                    owner=self.request.user)
                saved_queryset = saved_basket.lines.all().select_related(
                    'product', 'product__stockrecord')
                SavedFormset = modelformset_factory(self.model,
                                                    form=SavedLineForm,
                                                    extra=0,
                                                    can_delete=True)
                formset = SavedFormset(queryset=saved_queryset)
                context['saved_formset'] = formset
            except self.basket_model.DoesNotExist:
                pass
        return context