Browse Source

Pass login object to EmailAuthenticationForm

Add request object to login form kwargs
master
Leandro Gomez 6 years ago
parent
commit
38e6bd2fbb
2 changed files with 29 additions and 0 deletions
  1. 1
    0
      src/oscar/apps/customer/views.py
  2. 28
    0
      tests/unit/customer/test_views.py

+ 1
- 0
src/oscar/apps/customer/views.py View File

@@ -135,6 +135,7 @@ class AccountAuthView(RegisterUserMixin, generic.TemplateView):
135 135
 
136 136
     def get_login_form_kwargs(self, bind_data=False):
137 137
         kwargs = {}
138
+        kwargs['request'] = self.request
138 139
         kwargs['host'] = self.request.get_host()
139 140
         kwargs['prefix'] = self.login_prefix
140 141
         kwargs['initial'] = {

+ 28
- 0
tests/unit/customer/test_views.py View File

@@ -0,0 +1,28 @@
1
+from unittest.mock import patch, Mock
2
+
3
+from django.test import TestCase, Client
4
+from django.urls import reverse
5
+
6
+from oscar.apps.customer.forms import EmailAuthenticationForm
7
+
8
+
9
+class TestAccountAuthView(TestCase):
10
+
11
+    def setUp(self):
12
+        self.client = Client()
13
+
14
+    def test_request_is_passed_to_form(self):
15
+        form_class = Mock(wraps=EmailAuthenticationForm)
16
+        data = {"login_submit": ["1"]}
17
+        initial = {'redirect_url': ''}
18
+        with patch("oscar.apps.customer.views.AccountAuthView.login_form_class", new=form_class):
19
+            response = self.client.post(reverse("customer:login"), data=data)
20
+            assert form_class.called
21
+            form_class.assert_called_with(
22
+                data=data,
23
+                files={},
24
+                host="testserver",
25
+                initial=initial,
26
+                prefix='login',
27
+                request=response.wsgi_request,
28
+            )

Loading…
Cancel
Save