Skip to content

Commit 4c50c6c

Browse files
committed
fix mail mocking issues for password reset
1 parent 519b710 commit 4c50c6c

2 files changed

Lines changed: 17 additions & 6 deletions

File tree

api_tests/users/views/sanction_response/test_user_sanction_response.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def test_post_missing_fields(self, app, sanction_url, user):
5151
auth=user.auth,
5252
expect_errors=True
5353
)
54-
print(res.json)
5554
assert res.json['errors'] == [
5655
{
5756
'source': {

api_tests/users/views/test_user_settings.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
AuthUserFactory,
1010
UserFactory,
1111
)
12+
from website import settings
1213
from django.middleware import csrf
1314
from osf.models import Email, NotableDomain
1415
from framework.auth.views import auth_email_logout
@@ -92,7 +93,7 @@ class TestUserChangePassword:
9293
@pytest.fixture()
9394
def user_one(self):
9495
user = UserFactory()
95-
user.set_password('password1')
96+
user.set_password('password1', notify=False)
9697
user.auth = (user.username, 'password1')
9798
user.save()
9899
return user
@@ -128,7 +129,8 @@ def test_post(self, app, user_one, user_two, url, payload):
128129
assert res.status_code == 403
129130

130131
# Logged in
131-
res = app.post_json_api(url, payload, auth=user_one.auth)
132+
with mock.patch.object(settings, 'USE_EMAIL', False):
133+
res = app.post_json_api(url, payload, auth=user_one.auth)
132134
assert res.status_code == 204
133135
user_one.reload()
134136
assert user_one.check_password('password2')
@@ -267,7 +269,7 @@ def test_post_invalid_password(self, app, url, user_one, csrf_token):
267269
res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token})
268270
assert res.status_code == 400
269271

270-
def test_throttle(self, app, url, user_one):
272+
def test_throttle(self, app, url, user_one, csrf_token):
271273
encoded_email = urllib.parse.quote(user_one.email)
272274
url = f'{url}?email={encoded_email}'
273275
app.get(url)
@@ -282,8 +284,18 @@ def test_throttle(self, app, url, user_one):
282284
}
283285
}
284286

285-
res = app.post_json_api(url, payload, expect_errors=True)
286-
res = app.post_json_api(url, payload, expect_errors=True)
287+
res = app.post_json_api(
288+
url,
289+
payload,
290+
headers={'X-CSRFToken': csrf_token},
291+
expect_errors=True
292+
)
293+
res = app.post_json_api(
294+
url,
295+
payload,
296+
headers={'X-CSRFToken': csrf_token},
297+
expect_errors=True
298+
)
287299
assert res.status_code == 429
288300

289301
res = app.get(url, expect_errors=True)

0 commit comments

Comments
 (0)