From 05876e2d7e3c37a66ebb6beaa3dfc030249c821f Mon Sep 17 00:00:00 2001 From: Dan Helfman Date: Sat, 29 Dec 2007 20:00:42 +0000 Subject: [PATCH] Another unit test for sending invites. --- controller/test/Test_controller.py | 14 ++++++ controller/test/Test_users.py | 74 ++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) diff --git a/controller/test/Test_controller.py b/controller/test/Test_controller.py index dfee48d..ac76dca 100644 --- a/controller/test/Test_controller.py +++ b/controller/test/Test_controller.py @@ -107,6 +107,20 @@ class Test_controller( object ): User.sql_has_access = lambda self, notebook_id, read_write = False, owner = False: \ lambda database: sql_has_access( self, notebook_id, read_write, owner, database ) + def sql_update_access( self, notebook_id, read_write, owner, database ): + for ( user_id, notebook_infos ) in database.user_notebook.items(): + for notebook_info in notebook_infos: + ( db_notebook_id, db_read_write, db_owner ) = notebook_info + + if self.object_id == user_id and notebook_id == db_notebook_id: + notebook_infos_copy = list( notebook_infos ) + notebook_infos_copy.remove( notebook_info ) + notebook_infos_copy.append( ( notebook_id, read_write, owner ) ) + database.user_notebook[ user_id ] = notebook_infos_copy + + User.sql_update_access = lambda self, notebook_id, read_write = False, owner = False: \ + lambda database: sql_update_access( self, notebook_id, read_write, owner, database ) + def sql_load_revisions( self, database ): note_list = database.objects.get( self.object_id ) if not note_list: return None diff --git a/controller/test/Test_users.py b/controller/test/Test_users.py index 3ae1f77..e757557 100644 --- a/controller/test/Test_users.py +++ b/controller/test/Test_users.py @@ -1167,6 +1167,80 @@ class Test_users( Test_controller ): ) ) assert access is True + def test_send_invites_similar_already_redeemed( self ): + Stub_smtp.reset() + smtplib.SMTP = Stub_smtp + self.login() + + self.user.rate_plan = 1 + self.database.save( self.user ) + + email_addresses_list = [ u"foo@example.com" ] + email_addresses = email_addresses_list[ 0 ] + + # first send an invite with read_write and owner set to False + self.http_post( "/users/send_invites", dict( + notebook_id = self.notebooks[ 0 ].object_id, + email_addresses = email_addresses, + access = u"viewer", + invite_button = u"send invites", + ), session_id = self.session_id ) + + matches = self.INVITE_LINK_PATTERN.search( smtplib.SMTP.message ) + invite_id1 = matches.group( 2 ) + assert invite_id1 + + # login as another user and redeem the invite + self.login2() + result = self.http_post( "/users/redeem_invite", dict( + invite_id = invite_id1, + ), session_id = self.session_id ) + + # then send a similar invite to the same email address with read_write and owner set to True + self.login() + result = self.http_post( "/users/send_invites", dict( + notebook_id = self.notebooks[ 0 ].object_id, + email_addresses = email_addresses, + access = u"owner", + invite_button = u"send invites", + ), session_id = self.session_id ) + + invites = result[ u"invites" ] + assert len( invites ) == 1 + invite = invites[ 0 ] + assert invite + assert invite.read_write is True + assert invite.owner is True + + matches = self.INVITE_LINK_PATTERN.search( smtplib.SMTP.message ) + invite_id2 = matches.group( 2 ) + assert invite_id2 + + # assert that both invites have the read_write / owner flags set to True now + invite1_list = self.database.objects.get( invite_id1 ) + assert invite1_list + assert len( invite1_list ) >= 2 + invite1 = invite1_list[ -1 ] + assert invite1 + assert invite1.read_write is True + assert invite1.owner is True + + invite2_list = self.database.objects.get( invite_id2 ) + assert invite2_list + assert len( invite2_list ) >= 1 + invite2 = invite2_list[ -1 ] + assert invite2 + assert invite2.read_write is True + assert invite2.owner is True + + # assert that the user_notebook table has also been updated accordingly + access = self.database.select_one( bool, self.user.sql_has_access( + self.notebooks[ 0 ].object_id, + read_write = True, + owner = True, + ) ) + assert access is True + def test_send_invites_with_generic_from_address( self ): Stub_smtp.reset() smtplib.SMTP = Stub_smtp