17
17
from open_inwoner .openklant .tests .factories import ContactFormSubjectFactory
18
18
from open_inwoner .openklant .views .contactform import ContactFormView
19
19
from open_inwoner .openzaak .tests .factories import ServiceFactory
20
- from open_inwoner .utils .forms import MathCaptchaField
21
20
from open_inwoner .utils .test import ClearCachesMixin , DisableRequestLogMixin
22
21
from open_inwoner .utils .tests .helpers import AssertFormMixin , AssertTimelineLogMixin
23
22
26
25
@modify_settings (
27
26
MIDDLEWARE = {"remove" : ["open_inwoner.kvk.middleware.KvKLoginMiddleware" ]}
28
27
)
29
- @patch .object (MathCaptchaField , "clean" , autospec = True )
30
28
@patch (
31
29
"open_inwoner.openklant.views.contactform.send_contact_confirmation_mail" ,
32
30
autospec = True ,
33
31
)
32
+ @patch (
33
+ "open_inwoner.openklant.views.contactform.generate_question_answer_pair" ,
34
+ autospec = True ,
35
+ return_value = ("" , 42 ),
36
+ )
34
37
class ContactFormIntegrationTest (
35
38
ClearCachesMixin ,
36
39
AssertTimelineLogMixin ,
@@ -64,7 +67,7 @@ def setUp(self):
64
67
ContactFormView .template_name = "pages/contactform/form.html"
65
68
66
69
def test_singleton_has_configuration_method (
67
- self , m , mock_send_confirm , mock_captcha
70
+ self , m , mock_captcha , mock_send_confirm
68
71
):
69
72
# use cleared (from setUp()
70
73
config = OpenKlantConfig .get_solo ()
@@ -92,7 +95,7 @@ def test_singleton_has_configuration_method(
92
95
mock_send_confirm .assert_not_called ()
93
96
94
97
def test_no_form_shown_if_not_has_configuration (
95
- self , m , mock_send_confirm , mock_captcha
98
+ self , m , mock_captcha , mock_send_confirm
96
99
):
97
100
# set nothing
98
101
config = OpenKlantConfig .get_solo ()
@@ -103,7 +106,7 @@ def test_no_form_shown_if_not_has_configuration(
103
106
self .assertEqual (0 , len (response .pyquery ("#contactmoment-form" )))
104
107
105
108
def test_anon_form_requires_either_email_or_phonenumber (
106
- self , m , mock_send_confirm , mock_captcha
109
+ self , m , mock_captcha , mock_send_confirm
107
110
):
108
111
config = OpenKlantConfig .get_solo ()
109
112
config .
register_email = "[email protected] "
@@ -132,6 +135,7 @@ def test_anon_form_requires_either_email_or_phonenumber(
132
135
form ["email" ] = ""
133
136
form ["phonenumber" ] = ""
134
137
form ["question" ] = "hey!\n \n waddup?"
138
+ form ["captcha" ] = 42
135
139
136
140
response = form .submit (status = 200 )
137
141
self .assertEqual (
@@ -140,7 +144,7 @@ def test_anon_form_requires_either_email_or_phonenumber(
140
144
mock_send_confirm .assert_not_called ()
141
145
142
146
def test_regular_auth_form_fills_email_and_phonenumber (
143
- self , m , mock_send_confirm , mock_captcha
147
+ self , m , mock_captcha , mock_send_confirm
144
148
):
145
149
config = OpenKlantConfig .get_solo ()
146
150
config .
register_email = "[email protected] "
@@ -165,7 +169,7 @@ def test_regular_auth_form_fills_email_and_phonenumber(
165
169
mock_send_confirm .assert_called_once_with (user .email , subject .subject )
166
170
167
171
def test_expected_ordered_subjects_are_shown (
168
- self , m , mock_send_confirm , mock_captcha
172
+ self , m , mock_captcha , mock_send_confirm
169
173
):
170
174
config = OpenKlantConfig .get_solo ()
171
175
config .
register_email = "[email protected] "
@@ -203,7 +207,7 @@ def test_expected_ordered_subjects_are_shown(
203
207
)
204
208
mock_send_confirm .assert_not_called ()
205
209
206
- def test_submit_and_register_via_email (self , m , mock_send_confirm , mock_captcha ):
210
+ def test_submit_and_register_via_email (self , m , mock_captcha , mock_send_confirm ):
207
211
config = OpenKlantConfig .get_solo ()
208
212
config .
register_email = "[email protected] "
209
213
config .has_form_configuration = True
@@ -219,6 +223,7 @@ def test_submit_and_register_via_email(self, m, mock_send_confirm, mock_captcha)
219
223
form [
"email" ]
= "[email protected] "
220
224
form ["phonenumber" ] = "+31612345678"
221
225
form ["question" ] = "hey!\n \n waddup?"
226
+ form ["captcha" ] = 42
222
227
223
228
response = form .submit ().follow ()
224
229
@@ -244,7 +249,7 @@ def test_submit_and_register_via_email(self, m, mock_send_confirm, mock_captcha)
244
249
mock_send_confirm .
assert_called_once_with (
"[email protected] " ,
subject .
subject )
245
250
246
251
def test_submit_and_register_anon_via_api_with_klant (
247
- self , m , mock_send_confirm , mock_captcha
252
+ self , m , mock_captcha , mock_send_confirm
248
253
):
249
254
MockAPICreateData .setUpServices ()
250
255
@@ -273,6 +278,7 @@ def test_submit_and_register_anon_via_api_with_klant(
273
278
form [
"email" ]
= "[email protected] "
274
279
form ["phonenumber" ] = "+31612345678"
275
280
form ["question" ] = "hey!\n \n waddup?"
281
+ form ["captcha" ] = 42
276
282
277
283
response = form .submit ().follow ()
278
284
@@ -329,7 +335,7 @@ def test_submit_and_register_anon_via_api_with_klant(
329
335
mock_send_confirm .
assert_called_once_with (
"[email protected] " ,
subject .
subject )
330
336
331
337
def test_submit_and_register_anon_via_api_without_klant (
332
- self , m , mock_send_confirm , mock_captcha
338
+ self , m , mock_captcha , mock_send_confirm
333
339
):
334
340
MockAPICreateData .setUpServices ()
335
341
@@ -359,6 +365,7 @@ def test_submit_and_register_anon_via_api_without_klant(
359
365
form [
"email" ]
= "[email protected] "
360
366
form ["phonenumber" ] = "+31612345678"
361
367
form ["question" ] = "hey!\n \n waddup?"
368
+ form ["captcha" ] = 42
362
369
363
370
response = form .submit ().follow ()
364
371
@@ -405,9 +412,13 @@ def test_submit_and_register_anon_via_api_without_klant(
405
412
self .assertTimelineLog ("registered contactmoment by API" )
406
413
mock_send_confirm .
assert_called_once_with (
"[email protected] " ,
subject .
subject )
407
414
415
+ @patch ("open_inwoner.openklant.forms.generate_question_answer_pair" )
408
416
def test_submit_and_register_anon_via_api_without_klant_does_not_send_empty_email_or_telephone (
409
- self , m , mock_send_confirm , mock_captcha
417
+ self , m , mock_captcha2 , mock_captcha , mock_send_confirm
410
418
):
419
+ # we need to patch the captcha Q&A twice because they are re-generated by the form
420
+ mock_captcha2 .return_value = ("" , 42 )
421
+
411
422
config = OpenKlantConfig .get_solo ()
412
423
config .register_contact_moment = True
413
424
config .register_bronorganisatie_rsin = "123456789"
@@ -441,6 +452,7 @@ def test_submit_and_register_anon_via_api_without_klant_does_not_send_empty_emai
441
452
form ["question" ] = "foobar"
442
453
form ["phonenumber" ] = contact_details ["phonenumber" ]
443
454
form ["email" ] = contact_details ["email" ]
455
+ form ["captcha" ] = 42
444
456
445
457
response = form .submit ().follow ()
446
458
@@ -463,7 +475,7 @@ def test_submit_and_register_anon_via_api_without_klant_does_not_send_empty_emai
463
475
self .assertNotIn ("telefoonnummer" , contactgegevens .keys ())
464
476
465
477
def test_register_bsn_user_via_api_without_id (
466
- self , m , mock_send_confirm , mock_captcha
478
+ self , m , mock_captcha , mock_send_confirm
467
479
):
468
480
MockAPICreateData .setUpServices ()
469
481
@@ -516,7 +528,7 @@ def test_register_bsn_user_via_api_without_id(
516
528
)
517
529
518
530
def test_submit_and_register_bsn_user_via_api (
519
- self , m , mock_send_confirm , mock_captcha
531
+ self , m , mock_captcha , mock_send_confirm
520
532
):
521
533
MockAPICreateData .setUpServices ()
522
534
@@ -592,7 +604,7 @@ def test_submit_and_register_bsn_user_via_api(
592
604
mock_send_confirm .
assert_called_once_with (
"[email protected] " ,
subject .
subject )
593
605
594
606
def test_submit_and_register_kvk_or_rsin_user_via_api (
595
- self , _m , mock_send_confirm , mock_captcha
607
+ self , _m , mock_captcha , mock_send_confirm
596
608
):
597
609
MockAPICreateData .setUpServices ()
598
610
@@ -697,7 +709,7 @@ def test_submit_and_register_kvk_or_rsin_user_via_api(
697
709
mock_send_confirm .reset_mock ()
698
710
699
711
def test_submit_and_register_bsn_user_via_api_and_update_klant (
700
- self , m , mock_send_confirm , mock_captcha
712
+ self , m , mock_captcha , mock_send_confirm
701
713
):
702
714
MockAPICreateData .setUpServices ()
703
715
@@ -780,12 +792,16 @@ def test_submit_and_register_bsn_user_via_api_and_update_klant(
780
792
mock_send_confirm .assert_called_once_with (data .user .email , subject .subject )
781
793
mock_send_confirm .reset_mock ()
782
794
795
+ @patch ("open_inwoner.openklant.forms.generate_question_answer_pair" )
783
796
def test_submit_and_register_kvk_or_rsin_user_via_api_and_update_klant (
784
- self , m , mock_send_confirm , mock_captcha
797
+ self , m , mock_captcha2 , mock_captcha , mock_send_confirm
785
798
):
786
799
self .maxDiff = None
787
800
MockAPICreateData .setUpServices ()
788
801
802
+ # we need to patch the captcha Q&A twice because they are re-generated by the form
803
+ mock_captcha2 .return_value = ("" , 42 )
804
+
789
805
config = OpenKlantConfig .get_solo ()
790
806
config .register_contact_moment = True
791
807
config .register_bronorganisatie_rsin = "123456789"
@@ -884,11 +900,15 @@ def test_submit_and_register_kvk_or_rsin_user_via_api_and_update_klant(
884
900
)
885
901
mock_send_confirm .reset_mock ()
886
902
903
+ @patch ("open_inwoner.openklant.forms.generate_question_answer_pair" )
887
904
def test_send_email_confirmation_is_configurable (
888
- self , m , mock_send_confirm , mock_captcha
905
+ self , m , mock_captcha2 , mock_captcha , mock_send_confirm
889
906
):
890
907
MockAPICreateData .setUpServices ()
891
908
909
+ # we need to patch the captcha Q&A twice because they are re-generated by the form
910
+ mock_captcha2 .return_value = ("" , 42 )
911
+
892
912
config = OpenKlantConfig .get_solo ()
893
913
config .register_contact_moment = True
894
914
config .register_bronorganisatie_rsin = "123456789"
@@ -918,6 +938,10 @@ def test_send_email_confirmation_is_configurable(
918
938
form [
"email" ]
= "[email protected] "
919
939
form ["phonenumber" ] = "+31612345678"
920
940
form ["question" ] = "hey!\n \n waddup?"
941
+ form ["captcha" ] = 42
942
+
943
+ # res = form.submit()
944
+ # import pdbr;pdbr.set_trace()
921
945
922
946
response = form .submit ().follow ()
923
947
0 commit comments