Skip to content

Commit

Permalink
twaek code for correct mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
John Tordoff committed Jan 15, 2025
1 parent b268003 commit 3e710a4
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
2 changes: 0 additions & 2 deletions admin/base/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@

ALLOWED_HOSTS = [
'.osf.io',
'localhost',
'127.0.0.1'
]

AUTH_PASSWORD_VALIDATORS = [
Expand Down
45 changes: 42 additions & 3 deletions api_tests/requests/views/test_node_request_institutional_access.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,13 +194,52 @@ def test_institutional_admin_unauth_institution(self, app, project, institution_
assert res.status_code == 403
assert 'Institutional request access is not enabled.' in res.json['errors'][0]['detail']

@mock.patch('website.mails.send_mail')
def test_email_send_to_all_admins_once_on_institutional_request(self, mock_mail, app, project, url, create_payload, institutional_admin):
@mock.patch('api.requests.serializers.send_mail')
@mock.patch('osf.utils.machines.mails.send_mail')
def test_email_send_institutional_request_specific_email(
self,
mock_send_mail_machines,
mock_send_mail_serializers,
user_with_affiliation,
app,
project,
url,
create_payload,
institutional_admin,
institution
):
"""
Test that the institutional request triggers email notifications to appropriate recipients.
"""
# Set up mock behaviors
project.is_public = True
project.save()

# Perform the action
res = app.post_json_api(url, create_payload, auth=institutional_admin.auth)

# Ensure response is successful
assert res.status_code == 201
assert mock_mail.call_count == 1

assert mock_send_mail_serializers.call_count == 1
assert mock_send_mail_machines.call_count == 0

# Check calls for osf.utils.machines.mails.send_mail
mock_send_mail_serializers.assert_called_once_with(
to_addr=user_with_affiliation.username,
mail=NODE_REQUEST_INSTITUTIONAL_ACCESS_REQUEST,
user=user_with_affiliation,
bcc_addr=None,
reply_to=None,
**{
'sender': institutional_admin,
'recipient': user_with_affiliation,
'comment': create_payload['data']['attributes']['comment'],
'institution': institution,
'osf_url': mock.ANY,
'node': project,
}
)

@mock.patch('api.requests.serializers.send_mail')
def test_email_not_sent_without_recipient(self, mock_mail, app, project, institutional_admin, url,
Expand Down
1 change: 0 additions & 1 deletion osf/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ flags:
- flag_name: INSTITUTIONAL_DASHBOARD_2024
name: institutional_dashboard_2024
note: whether to surface older or updated (in 2024) institutional metrics
everyone: false

switches:
- flag_name: DISABLE_ENGAGEMENT_EMAILS
Expand Down

0 comments on commit 3e710a4

Please sign in to comment.