34
34
from osf .utils import permissions
35
35
from addons .wiki .models import WikiPage , WikiVersion
36
36
from addons .wiki .tests .factories import WikiFactory , WikiVersionFactory
37
+ from tests .utils import capture_notifications
37
38
from website import language
38
39
from website .util import web_url_for , api_url_for
39
40
@@ -736,10 +737,11 @@ def test_can_receive_resend_confirmation_email(self):
736
737
res = self .app .get (self .get_url )
737
738
form = res .get_form ('resendForm' )
738
739
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 )
740
742
741
743
# check email, request and response
742
- assert mock_send_mail . called
744
+ assert notifications
743
745
assert res .status_code == 200
744
746
assert res .request .path == self .post_url
745
747
assert_in_html ('If there is an OSF account' , res .text )
@@ -750,10 +752,11 @@ def test_cannot_receive_resend_confirmation_email_1(self):
750
752
res = self .app .get (self .get_url )
751
753
form = res .get_form ('resendForm' )
752
754
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 )
754
757
755
758
# check email, request and response
756
- assert not mock_send_mail . called
759
+ assert not notifications
757
760
assert res .status_code == 200
758
761
assert res .request .path == self .post_url
759
762
assert_in_html ('has already been confirmed' , res .text )
@@ -764,10 +767,11 @@ def test_cannot_receive_resend_confirmation_email_2(self):
764
767
res = self .app .get (self .get_url )
765
768
form = res .get_form ('resendForm' )
766
769
form [
'email' ]
= '[email protected] '
767
- res = form .submit (self .app )
770
+ with capture_notifications () as notifications :
771
+ res = form .submit (self .app )
768
772
769
773
# check email, request and response
770
- assert not mock_send_mail . called
774
+ assert not notifications
771
775
assert res .status_code == 200
772
776
assert res .request .path == self .post_url
773
777
assert_in_html ('If there is an OSF account' , res .text )
@@ -933,10 +937,11 @@ def test_get_forgot_password(self):
933
937
# test that user from disabled institution can receive reset password email
934
938
def test_can_receive_reset_password_email (self ):
935
939
# 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 })
937
942
938
943
# check mail was sent
939
- assert mock_send_mail . called
944
+ assert not notifications
940
945
# check http 200 response
941
946
assert res .status_code == 200
942
947
# check request URL is /forgotpassword
@@ -952,10 +957,11 @@ def test_can_receive_reset_password_email(self):
952
957
# test that non-existing user cannot receive reset password email
953
958
def test_cannot_receive_reset_password_email (self ):
954
959
# 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 })
956
962
957
963
# check mail was not sent
958
- assert not mock_send_mail . called
964
+ assert not notifications
959
965
# check http 200 response
960
966
assert res .status_code == 200
961
967
# check request URL is /forgotpassword-institution
@@ -973,10 +979,11 @@ def test_not_active_user_no_reset_password_email(self):
973
979
self .user .deactivate_account ()
974
980
self .user .save ()
975
981
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 })
977
984
978
985
# check mail was not sent
979
- assert not mock_send_mail . called
986
+ assert not notifications
980
987
# check http 200 response
981
988
assert res .status_code == 200
982
989
# check request URL is /forgotpassword-institution
@@ -1002,83 +1009,6 @@ def test_cannot_reset_password_twice_quickly(self):
1002
1009
assert_not_in_html ('If there is an OSF account' , res .text )
1003
1010
1004
1011
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
-
1082
1012
@pytest .mark .enable_bookmark_creation
1083
1013
class TestPreprintBannerView (OsfTestCase ):
1084
1014
def setUp (self ):
0 commit comments