Skip to content

Commit a4ca1c8

Browse files
committed
add impact Notification WIP
1 parent 03d7dd1 commit a4ca1c8

File tree

4 files changed

+66
-107
lines changed

4 files changed

+66
-107
lines changed

osf/models/sanctions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,7 @@ def _rejection_url_context(self, user_id):
398398
return None
399399

400400
def _send_approval_request_email(self, user, notification_type, context):
401+
print(notification_type)
401402
NotificationType.objects.get(
402403
name=notification_type
403404
).emit(

osf/notifications.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,21 @@ notification_types:
234234
object_content_type_model_name: osfuser
235235
template: 'website/templates/emails/new_pending_submissions.html.mako'
236236
notification_freq_default: instantly
237+
- name: user_invite_draft_registration
238+
__docs__: ...
239+
object_content_type_model_name: osfuser
240+
template: 'website/templates/emails/new_pending_submissions.html.mako'
241+
notification_freq_default: instantly
242+
- name: user_invite_draft_registration
243+
__docs__: ...
244+
object_content_type_model_name: osfuser
245+
template: 'website/templates/emails/new_pending_submissions.html.mako'
246+
notification_freq_default: instantly
247+
- name: user_invite_osf_preprint
248+
__docs__: ...
249+
object_content_type_model_name: osfuser
250+
template: 'website/templates/emails/new_pending_submissions.html.mako'
251+
notification_freq_default: instantly
237252

238253
#### PROVIDER
239254
- name: new_pending_submissions
@@ -387,6 +402,16 @@ notification_types:
387402
object_content_type_model_name: abstractnode
388403
template: 'website/templates/emails/new_pending_submissions.html.mako'
389404
notification_freq_default: instantly
405+
- name: node_pending_retraction_admin
406+
__docs__: ...
407+
object_content_type_model_name: abstractnode
408+
template: 'website/templates/emails/new_pending_submissions.html.mako'
409+
notification_freq_default: instantly
410+
- name: node_pending_embargo_termination_admin
411+
__docs__: ...
412+
object_content_type_model_name: abstractnode
413+
template: 'website/templates/emails/new_pending_submissions.html.mako'
414+
notification_freq_default: instantly
390415
- name: wiki_updated
391416
__docs__: ...
392417
object_content_type_model_name: abstractnode

tests/test_registrations/test_retractions.py

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
InvalidSanctionApprovalToken, InvalidSanctionRejectionToken,
2323
NodeStateError,
2424
)
25-
from osf.models import Contributor, Retraction
25+
from osf.models import Contributor, Retraction, NotificationType
2626
from osf.utils import permissions
27+
from tests.utils import capture_notifications
2728

2829

2930
@pytest.mark.enable_bookmark_creation
@@ -806,14 +807,16 @@ def test_POST_retraction_does_not_send_email_to_unregistered_admins(self):
806807
existing_user=unreg
807808
)
808809
self.registration.save()
809-
self.app.post(
810-
self.retraction_post_url,
811-
json={'justification': ''},
812-
auth=self.user.auth,
813-
)
810+
with capture_notifications() as notifications:
811+
self.app.post(
812+
self.retraction_post_url,
813+
json={'justification': ''},
814+
auth=self.user.auth,
815+
)
814816
# Only the creator gets an email; the unreg user does not get emailed
815-
#assert mock_send_mail.call_count == 1
816-
assert False, 'redp test'
817+
assert len(notifications) == 1
818+
assert notifications[0]['type'] == NotificationType.Type.NODE_PENDING_RETRACTION_ADMIN
819+
817820

818821
def test_POST_pending_embargo_returns_HTTPError_HTTPOK(self):
819822
self.registration.embargo_registration(
@@ -904,16 +907,16 @@ def test_valid_POST_retraction_when_pending_retraction_raises_400(self, mock_sen
904907
)
905908
assert res.status_code == 400
906909

907-
@mock.patch('website.mails.send_mail')
908-
def test_valid_POST_calls_send_mail_with_username(self, mock_send):
909-
self.app.post(
910-
self.retraction_post_url,
911-
json={'justification': ''},
912-
auth=self.user.auth,
913-
)
914-
assert mock_send.called
915-
args, kwargs = mock_send.call_args
916-
assert self.user.username in args
910+
def test_valid_POST_calls_send_mail_with_username(self):
911+
with capture_notifications() as notifications:
912+
self.app.post(
913+
self.retraction_post_url,
914+
json={'justification': ''},
915+
auth=self.user.auth,
916+
)
917+
assert len(notifications) == 1
918+
username = notifications[0]['kargs']['user'].username
919+
assert self.user.username == username
917920

918921
def test_non_contributor_GET_approval_returns_HTTPError_UNAUTHORIZED(self):
919922
non_contributor = AuthUserFactory()

tests/test_webtests.py

Lines changed: 19 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
from osf.utils import permissions
3535
from addons.wiki.models import WikiPage, WikiVersion
3636
from addons.wiki.tests.factories import WikiFactory, WikiVersionFactory
37+
from tests.utils import capture_notifications
3738
from website import language
3839
from website.util import web_url_for, api_url_for
3940

@@ -736,10 +737,11 @@ def test_can_receive_resend_confirmation_email(self):
736737
res = self.app.get(self.get_url)
737738
form = res.get_form('resendForm')
738739
form['email'] = self.unconfirmed_user.unconfirmed_emails[0]
739-
res = form.submit(self.app)
740+
with capture_notifications() as notifications:
741+
res = form.submit(self.app)
740742

741743
# check email, request and response
742-
assert mock_send_mail.called
744+
assert notifications
743745
assert res.status_code == 200
744746
assert res.request.path == self.post_url
745747
assert_in_html('If there is an OSF account', res.text)
@@ -750,10 +752,11 @@ def test_cannot_receive_resend_confirmation_email_1(self):
750752
res = self.app.get(self.get_url)
751753
form = res.get_form('resendForm')
752754
form['email'] = self.confirmed_user.emails.first().address
753-
res = form.submit(self.app)
755+
with capture_notifications() as notifications:
756+
res = form.submit(self.app)
754757

755758
# check email, request and response
756-
assert not mock_send_mail.called
759+
assert not notifications
757760
assert res.status_code == 200
758761
assert res.request.path == self.post_url
759762
assert_in_html('has already been confirmed', res.text)
@@ -764,10 +767,11 @@ def test_cannot_receive_resend_confirmation_email_2(self):
764767
res = self.app.get(self.get_url)
765768
form = res.get_form('resendForm')
766769
form['email'] = '[email protected]'
767-
res = form.submit(self.app)
770+
with capture_notifications() as notifications:
771+
res = form.submit(self.app)
768772

769773
# check email, request and response
770-
assert not mock_send_mail.called
774+
assert not notifications
771775
assert res.status_code == 200
772776
assert res.request.path == self.post_url
773777
assert_in_html('If there is an OSF account', res.text)
@@ -933,10 +937,11 @@ def test_get_forgot_password(self):
933937
# test that user from disabled institution can receive reset password email
934938
def test_can_receive_reset_password_email(self):
935939
# submit email to institutional forgot-password page
936-
res = self.app.post(self.post_url, data={'forgot_password-email': self.user.username})
940+
with capture_notifications() as notifications:
941+
res = self.app.post(self.post_url, data={'forgot_password-email': self.user.username})
937942

938943
# check mail was sent
939-
assert mock_send_mail.called
944+
assert not notifications
940945
# check http 200 response
941946
assert res.status_code == 200
942947
# check request URL is /forgotpassword
@@ -952,10 +957,11 @@ def test_can_receive_reset_password_email(self):
952957
# test that non-existing user cannot receive reset password email
953958
def test_cannot_receive_reset_password_email(self):
954959
# load forgot password page and submit email
955-
res = self.app.post(self.post_url, data={'forgot_password-email': 'fake' + self.user.username})
960+
with capture_notifications() as notifications:
961+
res = self.app.post(self.post_url, data={'forgot_password-email': 'fake' + self.user.username})
956962

957963
# check mail was not sent
958-
assert not mock_send_mail.called
964+
assert not notifications
959965
# check http 200 response
960966
assert res.status_code == 200
961967
# check request URL is /forgotpassword-institution
@@ -973,10 +979,11 @@ def test_not_active_user_no_reset_password_email(self):
973979
self.user.deactivate_account()
974980
self.user.save()
975981

976-
res = self.app.post(self.post_url, data={'forgot_password-email': self.user.username})
982+
with capture_notifications() as notifications:
983+
res = self.app.post(self.post_url, data={'forgot_password-email': self.user.username})
977984

978985
# check mail was not sent
979-
assert not mock_send_mail.called
986+
assert not notifications
980987
# check http 200 response
981988
assert res.status_code == 200
982989
# check request URL is /forgotpassword-institution
@@ -1002,83 +1009,6 @@ def test_cannot_reset_password_twice_quickly(self):
10021009
assert_not_in_html('If there is an OSF account', res.text)
10031010

10041011

1005-
@unittest.skip('Public projects/components are dynamically loaded now.')
1006-
class TestAUserProfile(OsfTestCase):
1007-
1008-
def setUp(self):
1009-
OsfTestCase.setUp(self)
1010-
1011-
self.user = AuthUserFactory()
1012-
self.me = AuthUserFactory()
1013-
self.project = ProjectFactory(creator=self.me, is_public=True, title=fake.bs())
1014-
self.component = NodeFactory(creator=self.me, parent=self.project, is_public=True, title=fake.bs())
1015-
1016-
# regression test for https://github.com/CenterForOpenScience/osf.io/issues/2623
1017-
def test_has_public_projects_and_components(self):
1018-
# I go to my own profile
1019-
url = web_url_for('profile_view_id', uid=self.me._primary_key)
1020-
# I see the title of both my project and component
1021-
res = self.app.get(url, auth=self.me.auth)
1022-
assert_in_html(self.component.title, res)
1023-
assert_in_html(self.project.title, res)
1024-
1025-
# Another user can also see my public project and component
1026-
url = web_url_for('profile_view_id', uid=self.me._primary_key)
1027-
# I see the title of both my project and component
1028-
res = self.app.get(url, auth=self.user.auth)
1029-
assert_in_html(self.component.title, res)
1030-
assert_in_html(self.project.title, res)
1031-
1032-
def test_shows_projects_with_many_contributors(self):
1033-
# My project has many contributors
1034-
for _ in range(5):
1035-
user = UserFactory()
1036-
self.project.add_contributor(user, auth=Auth(self.project.creator), save=True)
1037-
1038-
# I go to my own profile
1039-
url = web_url_for('profile_view_id', uid=self.me._primary_key)
1040-
res = self.app.get(url, auth=self.me.auth)
1041-
# I see '3 more' as a link
1042-
assert '3 more' in res.text
1043-
1044-
res = res.click('3 more')
1045-
assert res.request.path == self.project.url
1046-
1047-
def test_has_no_public_projects_or_components_on_own_profile(self):
1048-
# User goes to their profile
1049-
url = web_url_for('profile_view_id', uid=self.user._id)
1050-
res = self.app.get(url, auth=self.user.auth)
1051-
1052-
# user has no public components/projects
1053-
assert 'You have no public projects' in res
1054-
assert 'You have no public components' in res
1055-
1056-
def test_user_no_public_projects_or_components(self):
1057-
# I go to other user's profile
1058-
url = web_url_for('profile_view_id', uid=self.user._id)
1059-
# User has no public components/projects
1060-
res = self.app.get(url, auth=self.me.auth)
1061-
assert 'This user has no public projects' in res
1062-
assert 'This user has no public components'in res
1063-
1064-
# regression test
1065-
def test_does_not_show_registrations(self):
1066-
project = ProjectFactory(creator=self.user)
1067-
component = NodeFactory(parent=project, creator=self.user, is_public=False)
1068-
# User has a registration with public components
1069-
reg = RegistrationFactory(project=component.parent_node, creator=self.user, is_public=True)
1070-
for each in reg.nodes:
1071-
each.is_public = True
1072-
each.save()
1073-
# I go to other user's profile
1074-
url = web_url_for('profile_view_id', uid=self.user._id)
1075-
# Registration does not appear on profile
1076-
res = self.app.get(url, auth=self.me.auth)
1077-
assert 'This user has no public components' in res
1078-
assert reg.title not in res
1079-
assert reg.nodes[0].title not in res
1080-
1081-
10821012
@pytest.mark.enable_bookmark_creation
10831013
class TestPreprintBannerView(OsfTestCase):
10841014
def setUp(self):

0 commit comments

Comments
 (0)