def test_claim_shareoffer(self):
        """Test that the claim_shareoffer function works properly.

        A share_offer isn't a direct share to a user. Instead, its offered in
        that an share is created but only sent to an email address. However,
        any user can accept the share as long as it hasn't been accepted or the
        offer hasn't been rescended.

        """
        # setup the share_offer
        user1 = self.factory.make_user(username='sharer')
        root = StorageObject.objects.get_root(user1)
        share = self.factory.make_share(
            subtree=root, name='Share', access=Share.VIEW, accepted=False,
            email='fake@example.com')
        # user can't accept their own share offer
        self.assertRaises(
            errors.DoesNotExist, self.gw.claim_shareoffer, user1.id,
            user1.username, user1.get_full_name(), share.id)
        # basic test success...user already exist
        user2 = self.factory.make_user(username='sharee')
        self.gw.claim_shareoffer(
            user2.id, user2.username, user2.get_full_name(), share.id)
        share = Share.objects.get(id=share.id)
        self.assertEqual(share.shared_to, user2)
        self.assertEqual(share.accepted, True)
        user2 = self.gw.get_user(user2.id)
        self.assertEqual(user2.is_active, True)
        # Exception raised when accepted twice
        self.assertRaises(
            errors.ShareAlreadyAccepted, self.gw.claim_shareoffer, user2.id,
            user2.username, user2.visible_name, share.id)
        # test with new user
        share = self.factory.make_share(
            subtree=root, name='Share2', access=Share.VIEW, accepted=False,
            email='fake2@example.com')
        self.gw.claim_shareoffer(user2.id + 1, 'user3', 'user 3', share.id)
        user3 = self.gw.get_user(user2.id + 1)
        # the user is created, but is inactive
        self.assertEqual(user3.is_active, False)
        # subscribing will call something like this:
        u = self.gw.create_or_update_user(
            'user3', visible_name='user 3', max_storage_bytes=2 * (2 ** 30))
        user3 = self.gw.get_user(u.id)
        self.assertEqual(user3.is_active, True)

        share = Share.objects.get(id=share.id)
        self.assertEqual(share.shared_to, user3._user)
        self.assertEqual(share.accepted, True)