Example #1
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")
Example #2
0
    def test_add_admin_permission_in_institution_hierarchy(
            self, verify_token, enqueue_task):
        """Test add admin permissions in institution hierarchy."""
        first_user = mocks.create_user()
        second_user = mocks.create_user()
        third_user = mocks.create_user()

        first_inst = mocks.create_institution()
        second_inst = mocks.create_institution()
        third_inst = mocks.create_institution()

        first_inst.admin = first_user.key
        second_inst.admin = second_user.key
        third_inst.admin = third_user.key

        first_user.institutions_admin.append(first_inst.key)
        second_user.institutions_admin.append(second_inst.key)
        third_user.institutions_admin.append(third_inst.key)

        second_inst.parent_institution = first_inst.key
        third_inst.parent_institution = second_inst.key

        first_inst.children_institutions.append(second_inst.key)
        second_inst.children_institutions.append(third_inst.key)

        first_inst.put()
        second_inst.put()
        third_inst.put()

        first_user.put()
        second_user.put()
        third_user.put()

        invite = InviteInstitution()
        invite.invitee = third_user.email[0]
        invite.institution_key = third_inst.key
        invite.admin_key = second_user.key
        invite.stub_institution_key = third_inst.key
        invite.put()

        verify_token._mock_return_value = {'email': third_user.email[0]}
        enqueue_task.side_effect = self.enqueue_task

        self.assertEqual(first_user.permissions, {})
        self.assertEqual(second_user.permissions, {})
        self.assertEqual(third_user.permissions, {})

        self.body['data'] = {'sender_name': 'user name updated'}
        self.testapp.put_json(
            "/api/institutions/%s/invites/%s" %
            (third_inst.key.urlsafe(), invite.key.urlsafe()), self.body)

        first_user = first_user.key.get()
        second_user = second_user.key.get()
        third_user = third_user.key.get()

        self.assertTrue(
            has_permissions(third_user, third_inst.key.urlsafe(),
                            permissions.DEFAULT_ADMIN_PERMISSIONS))
        self.assertTrue(
            has_permissions(second_user, third_inst.key.urlsafe(),
                            permissions.DEFAULT_ADMIN_PERMISSIONS))