def setUp(cls):
        """Provide the base for the tests."""
        super(InviteInstitutionHandlerTest, cls).setUp()

        app = cls.webapp2.WSGIApplication(
            [(InviteInstitutionHandlerTest.INVITE_INSTITUTION_URI, InviteInstitutionHandler),
             ], debug=True)
        cls.testapp = cls.webtest.TestApp(app)

        # create models
        # new User
        cls.user_admin = mocks.create_user('*****@*****.**')
        # Other user
        cls.other_user = mocks.create_user('*****@*****.**')
        # new Institution inst test
        cls.inst_test = mocks.create_institution()
        cls.inst_test.admin = cls.user_admin.key
        cls.inst_test.state = "active"
        cls.inst_test.put()
        # New invite user
        cls.data = {
            'invitee': '*****@*****.**',
            'admin_key': cls.user_admin.key.urlsafe(),
            'institution_key': cls.inst_test.key.urlsafe(),
            'suggestion_institution_name': 'test'
        }
        cls.invite = InviteInstitution.create(cls.data)
        cls.invite.put()
示例#2
0
    def test_patch_with_a_wrong_invite(self, verify_token):
        """Test patch with a wrong invite."""
        data = {
            'invitee': '*****@*****.**',
            'admin_key': self.user_admin.key.urlsafe(),
            'institution_key': self.inst_test.key.urlsafe(),
            'suggestion_institution_name': 'test',
            'type_of_invite': 'INSTITUTION'
        }
        self.invite = InviteInstitution.create(data)
        self.invite.put()

        with self.assertRaises(Exception) as raises_context:
            self.testapp.patch('/api/invites/user/%s' %
                               self.invite.key.urlsafe())

        message_exception = self.get_message_exception(
            str(raises_context.exception))

        invite_class_name = self.invite.__class__.__name__
        expected_message = "Error! The invite's type is %s, but InviteUser is the expected one" % invite_class_name

        self.assertEqual(
            message_exception, expected_message,
            "Expected exception message must be equal to %s" %
            expected_message)
示例#3
0
    def test_make(self):
        """Test make method."""
        invite_institution = InviteInstitution.create(self.data)
        invite_institution.put()
        stub_institution = invite_institution.stub_institution_key.get()

        maked_invite = invite_institution.make()

        expected_maked_invite = {
            'admin_name':
            self.admin.name,
            'sender_name':
            self.invite.sender_name,
            'key':
            invite_institution.key.urlsafe(),
            'status':
            self.invite.status,
            'institution_admin':
            self.institution.make(["name"]),
            'institution':
            self.institution.make(InviteInstitution.INST_PROPS_TO_MAKE),
            'invitee':
            self.user.email[0],
            'suggestion_institution_name':
            'new Institution',
            'stub_institution':
            stub_institution.make(['name', 'key', 'state']),
            'type_of_invite':
            'INSTITUTION'
        }

        self.assertEquals(
            maked_invite, expected_maked_invite,
            "The maked invite should be equal to the expected one")
示例#4
0
 def test_create_accept_notification(self, mock_method):
     """Test create a regular accept response notification."""
     invite = InviteInstitution.create(self.data)
     invite.put()
     self.user.current_institution = self.institution.key
     self.user.put()
     id = invite.create_accept_response_notification(
         'ACCEPT_INVITE_INSTITUTION', self.institution.key,
         invite.admin_key.urlsafe(), self.user)
     mock_method.assert_called()
     self.assertTrue(id != None)
示例#5
0
 def test_create_system_notification(self, mock_method):
     """Test create a system notification."""
     invite = InviteInstitution.create(self.data)
     invite.put()
     self.user.current_institution = self.institution.key
     self.user.put()
     id = invite.create_accept_response_notification(
         'ADD_ADM_PERMISSIONS', self.institution.key,
         self.user.key.urlsafe())
     mock_method.assert_called()
     self.assertTrue(id != None)
    def test_delete(self, verify_token, send_notification):
        """Test method delete of InviteInstitutionHandler."""
        invite_institution = InviteInstitution.create(self.data)
        invite_institution.put()

        self.testapp.delete('/api/invites/institution/%s' %
                            invite_institution.key.urlsafe())

        invite_institution = invite_institution.key.get()
        self.assertTrue(invite_institution.status == "rejected")

        # assert the notification was sent
        send_notification.assert_called()
示例#7
0
    def test_create(self):
        """Test create method."""
        created_invite = InviteInstitution.create(self.data)
        stub_institution_key = created_invite.stub_institution_key

        expected_invite = InviteInstitution()
        expected_invite.admin_key = self.admin.key
        expected_invite.is_request = False
        expected_invite.institution_key = self.institution.key
        expected_invite.sender_key = self.admin.key
        expected_invite.sender_name = self.admin.name
        expected_invite.invitee = self.user.email[0]
        expected_invite.suggestion_institution_name = "new Institution"
        expected_invite.stub_institution_key = stub_institution_key

        self.assertEquals(
            created_invite, expected_invite,
            "The created invite should be equal to the expected one")