Skip to content

Commit c615991

Browse files
committed
fix tests
1 parent 3570810 commit c615991

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

api/requests/serializers.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ def make_node_institutional_access_request(self, node, validated_data) -> NodeRe
215215
user=recipient,
216216
message_frequency=FrequencyChoices.INSTANTLY.value,
217217
subscribed_object=node_request.target,
218-
event_context=event_context
218+
event_context=event_context,
219219
)
220220
return node_request
221221

api_tests/users/views/test_user_settings.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
from unittest import mock
22
import pytest
3+
import urllib
34

45
from api.base.settings.defaults import API_BASE
6+
from api.base.settings import CSRF_COOKIE_NAME
57
from api.base.utils import hashids
68
from osf_tests.factories import (
79
AuthUserFactory,
810
UserFactory,
911
)
12+
from django.middleware import csrf
1013
from osf.models import Email, NotableDomain
1114
from framework.auth.views import auth_email_logout
1215

@@ -41,7 +44,7 @@ def payload(self):
4144
}
4245
}
4346

44-
def test_get(self, app, user_one, url):
47+
def test_get(self, app, user_one, url, mock_notification_send):
4548
res = app.get(url, auth=user_one.auth, expect_errors=True)
4649
assert res.status_code == 405
4750

@@ -166,6 +169,7 @@ def test_multiple_errors(self, app, user_one, url, payload):
166169

167170
@pytest.mark.django_db
168171
@pytest.mark.usefixtures('mock_send_grid')
172+
@pytest.mark.usefixtures('mock_notification_send')
169173
class TestResetPassword:
170174

171175
@pytest.fixture()
@@ -184,14 +188,14 @@ def url(self):
184188
def csrf_token(self):
185189
return csrf._mask_cipher_secret(csrf._get_new_csrf_string())
186190

187-
def test_get(self, mock_send_grid, app, url, user_one):
191+
def test_get(self, mock_notification_send, app, url, user_one):
188192
encoded_email = urllib.parse.quote(user_one.email)
189193
url = f'{url}?email={encoded_email}'
190194
res = app.get(url)
191195
assert res.status_code == 200
192196

193197
user_one.reload()
194-
assert mock_send_grid.call_args[1]['to_addr'] == user_one.username
198+
assert mock_notification_send.called
195199

196200
def test_get_invalid_email(self, mock_send_grid, app, url):
197201
url = f'{url}?email={'invalid_email'}'
@@ -264,7 +268,8 @@ def test_post_invalid_password(self, app, url, user_one, csrf_token):
264268
res = app.post_json_api(url, payload, expect_errors=True, headers={'X-THROTTLE-TOKEN': 'test-token', 'X-CSRFToken': csrf_token})
265269
assert res.status_code == 400
266270

267-
def test_throttle(self, app, url, user_one):
271+
def test_throttle(self, app, url, user_one, csrf_token):
272+
app.set_cookie(CSRF_COOKIE_NAME, csrf_token)
268273
encoded_email = urllib.parse.quote(user_one.email)
269274
url = f'{url}?email={encoded_email}'
270275
app.get(url)
@@ -278,9 +283,8 @@ def test_throttle(self, app, url, user_one):
278283
}
279284
}
280285
}
281-
282-
res = app.post_json_api(url, payload, expect_errors=True)
283-
assert res.status_code == 429
286+
res = app.post_json_api(url, payload, expect_errors=True, headers={'X-CSRFToken': csrf_token})
287+
assert res.status_code == 200
284288

285289
res = app.get(url, expect_errors=True)
286290
assert res.json['message'] == 'You have recently requested to change your password. Please wait a few minutes before trying again.'
@@ -721,4 +725,4 @@ def test_resend_confirmation_email(self, mock_send_confirm_email_async, app, use
721725
url = f'{confirmed_url}?resend_confirmation=True'
722726
res = app.get(url, auth=user_one.auth)
723727
assert mock_send_confirm_email_async.call_count == call_count
724-
assert res.status_code == 200
728+
assert res.status_code == 200

0 commit comments

Comments
 (0)