@@ -29,13 +29,20 @@ def unconfirmed_address():
29
29
30
30
31
31
@pytest .mark .django_db
32
+ @pytest .mark .usefixtures ('mock_notification_send' )
32
33
@pytest .mark .usefixtures ('mock_send_grid' )
33
34
class TestUserRequestExport :
34
35
35
36
@pytest .fixture ()
36
37
def url (self , user_one ):
37
38
return f'/{ API_BASE } users/{ user_one ._id } /settings/export/'
38
39
40
+ @pytest .fixture ()
41
+ def notification_type (self ):
42
+ NotificationTypeFactory (name = 'forgot_password' , notification_interval_choices = ['instantly' ])
43
+ NotificationTypeFactory (name = 'password_reset' , notification_interval_choices = ['instantly' ])
44
+ return
45
+
39
46
@pytest .fixture ()
40
47
def payload (self ):
41
48
return {
@@ -45,11 +52,11 @@ def payload(self):
45
52
}
46
53
}
47
54
48
- def test_get (self , app , user_one , url ):
55
+ def test_get (self , notification_type , app , user_one , url ):
49
56
res = app .get (url , auth = user_one .auth , expect_errors = True )
50
57
assert res .status_code == 405
51
58
52
- def test_post (self , mock_send_grid , app , user_one , user_two , url , payload ):
59
+ def test_post (self , notification_type , mock_send_grid , mock_notification_send , app , user_one , user_two , url , payload ):
53
60
# Logged out
54
61
res = app .post_json_api (url , payload , expect_errors = True )
55
62
assert res .status_code == 401
@@ -66,16 +73,16 @@ def test_post(self, mock_send_grid, app, user_one, user_two, url, payload):
66
73
assert user_one .email_last_sent is not None
67
74
assert mock_send_grid .call_count == 1
68
75
69
- def test_post_invalid_type (self , mock_send_grid , app , user_one , url , payload ):
76
+ def test_post_invalid_type (self , notification_type , mock_notification_send , app , user_one , url , payload ):
70
77
assert user_one .email_last_sent is None
71
78
payload ['data' ]['type' ] = 'Invalid Type'
72
79
res = app .post_json_api (url , payload , auth = user_one .auth , expect_errors = True )
73
80
assert res .status_code == 409
74
81
user_one .reload ()
75
82
assert user_one .email_last_sent is None
76
- assert mock_send_grid .call_count == 0
83
+ assert mock_notification_send .call_count == 0
77
84
78
- def test_exceed_throttle (self , app , user_one , url , payload ):
85
+ def test_exceed_throttle (self , notification_type , app , user_one , url , payload ):
79
86
assert user_one .email_last_sent is None
80
87
res = app .post_json_api (url , payload , auth = user_one .auth )
81
88
assert res .status_code == 204
@@ -88,6 +95,7 @@ def test_exceed_throttle(self, app, user_one, url, payload):
88
95
89
96
90
97
@pytest .mark .django_db
98
+ @pytest .mark .usefixtures ('mock_notification_send' )
91
99
class TestUserChangePassword :
92
100
93
101
@pytest .fixture ()
@@ -98,6 +106,12 @@ def user_one(self):
98
106
user .save ()
99
107
return user
100
108
109
+ @pytest .fixture ()
110
+ def notification_type (self ):
111
+ NotificationTypeFactory (name = 'forgot_password' , notification_interval_choices = ['instantly' ])
112
+ NotificationTypeFactory (name = 'password_reset' , notification_interval_choices = ['instantly' ])
113
+ return
114
+
101
115
@pytest .fixture ()
102
116
def url (self , user_one ):
103
117
return f'/{ API_BASE } users/{ user_one ._id } /settings/password/'
@@ -115,11 +129,11 @@ def payload(self, user_one):
115
129
}
116
130
}
117
131
118
- def test_get (self , app , user_one , url ):
132
+ def test_get (self , notification_type , app , user_one , url ):
119
133
res = app .get (url , auth = user_one .auth , expect_errors = True )
120
134
assert res .status_code == 405
121
135
122
- def test_post (self , app , user_one , user_two , url , payload ):
136
+ def test_post (self , notification_type , app , user_one , user_two , url , payload ):
123
137
# Logged out
124
138
res = app .post_json_api (url , payload , expect_errors = True )
125
139
assert res .status_code == 401
@@ -134,12 +148,12 @@ def test_post(self, app, user_one, user_two, url, payload):
134
148
user_one .reload ()
135
149
assert user_one .check_password ('password2' )
136
150
137
- def test_post_invalid_type (self , app , user_one , url , payload ):
151
+ def test_post_invalid_type (self , notification_type , app , user_one , url , payload ):
138
152
payload ['data' ]['type' ] = 'Invalid Type'
139
153
res = app .post_json_api (url , payload , auth = user_one .auth , expect_errors = True )
140
154
assert res .status_code == 409
141
155
142
- def test_exceed_throttle_failed_attempts (self , app , user_one , url , payload ):
156
+ def test_exceed_throttle_failed_attempts (self , notification_type , app , user_one , url , payload ):
143
157
payload ['data' ]['attributes' ]['existing_password' ] = 'wrong password'
144
158
payload ['data' ]['attributes' ]['new_password' ] = 'password2'
145
159
res = app .post_json_api (url , payload , auth = user_one .auth , expect_errors = True )
@@ -159,7 +173,7 @@ def test_exceed_throttle_failed_attempts(self, app, user_one, url, payload):
159
173
# Expected time is omitted to prevent probabilistic failures.
160
174
assert 'Request was throttled. Expected available in ' in res .json ['errors' ][0 ]['detail' ]
161
175
162
- def test_multiple_errors (self , app , user_one , url , payload ):
176
+ def test_multiple_errors (self , notification_type , app , user_one , url , payload ):
163
177
payload ['data' ]['attributes' ]['existing_password' ] = 'wrong password'
164
178
payload ['data' ]['attributes' ]['new_password' ] = '!'
165
179
res = app .post_json_api (url , payload , auth = user_one .auth , expect_errors = True )
@@ -203,13 +217,13 @@ def test_get(self, mock_notification_send, notification_type, app, url, user_one
203
217
user_one .reload ()
204
218
assert mock_notification_send .called
205
219
206
- def test_get_invalid_email (self , mock_notification_send , app , url , notification_type ):
220
+ def test_get_invalid_email (self , notification_type , mock_notification_send , app , url ):
207
221
url = f'{ url } ?email={ 'invalid_email' } '
208
222
res = app .get (url )
209
223
assert res .status_code == 200
210
224
assert not mock_notification_send .called
211
225
212
- def test_post (self , mock_notification_send , app , url , user_one , csrf_token , notification_type ):
226
+ def test_post (self , notification_type , mock_notification_send , app , url , user_one , csrf_token ):
213
227
app .set_cookie (CSRF_COOKIE_NAME , csrf_token )
214
228
encoded_email = urllib .parse .quote (user_one .email )
215
229
url = f'{ url } ?email={ encoded_email } '
@@ -231,7 +245,7 @@ def test_post(self, mock_notification_send, app, url, user_one, csrf_token, noti
231
245
assert user_one .check_password ('password2' )
232
246
assert mock_notification_send .called
233
247
234
- def test_post_empty_payload (self , app , url , csrf_token ):
248
+ def test_post_empty_payload (self , notification_type , app , url , csrf_token ):
235
249
app .set_cookie (CSRF_COOKIE_NAME , csrf_token )
236
250
payload = {
237
251
'data' : {
@@ -242,7 +256,7 @@ def test_post_empty_payload(self, app, url, csrf_token):
242
256
res = app .post_json_api (url , payload , expect_errors = True , headers = {'X-CSRFToken' : csrf_token })
243
257
assert res .status_code == 400
244
258
245
- def test_post_invalid_token (self , app , url , user_one , csrf_token ):
259
+ def test_post_invalid_token (self , notification_type , app , url , user_one , csrf_token ):
246
260
app .set_cookie (CSRF_COOKIE_NAME , csrf_token )
247
261
payload = {
248
262
'data' : {
@@ -256,7 +270,7 @@ def test_post_invalid_token(self, app, url, user_one, csrf_token):
256
270
res = app .post_json_api (url , payload , expect_errors = True , headers = {'X-THROTTLE-TOKEN' : 'test-token' , 'X-CSRFToken' : csrf_token })
257
271
assert res .status_code == 400
258
272
259
- def test_post_invalid_password (self , app , url , user_one , csrf_token , notification_type ):
273
+ def test_post_invalid_password (self , notification_type , app , url , user_one , csrf_token ):
260
274
app .set_cookie (CSRF_COOKIE_NAME , csrf_token )
261
275
encoded_email = urllib .parse .quote (user_one .email )
262
276
url = f'{ url } ?email={ encoded_email } '
@@ -275,7 +289,7 @@ def test_post_invalid_password(self, app, url, user_one, csrf_token, notificatio
275
289
res = app .post_json_api (url , payload , expect_errors = True , headers = {'X-THROTTLE-TOKEN' : 'test-token' , 'X-CSRFToken' : csrf_token })
276
290
assert res .status_code == 400
277
291
278
- def test_throrrle (self , app , url , user_one , notification_type ):
292
+ def test_throrrle (self , notification_type , app , url , user_one ):
279
293
encoded_email = urllib .parse .quote (user_one .email )
280
294
url = f'{ url } ?email={ encoded_email } '
281
295
res = app .get (url )
0 commit comments