def test_duplicate_name(self):
        # Create a mock store and put a participant in it
        participant = participant_update.ParticipantObject(
            participantid='0000000000000000', minfo={
                'name': 'participant',
            })
        store = MarketPlaceGlobalStore()
        store[participant.ObjectID] = participant.dump()

        # Because we have not "registered" any holdings, the name
        # should not be a duplicate
        update = holding_update.Register(
            update_type=holding_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/holding')
        self.assertTrue(
            market_place_object_update.global_is_valid_name(
                store,
                name='/holding',
                object_type=update.ObjectType,
                creator_id=participant.ObjectID,
            ))

        # Add a holding to the store with the creator being the participant
        # we inserted initially
        holding = holding_update.HoldingObject(objectid='0000000000000001',
                                               minfo={
                                                   'name':
                                                   '//participant/holding',
                                                   'creator':
                                                   participant.ObjectID
                                               })
        store[holding.ObjectID] = holding.dump()

        # Because the holding name is in the store, trying to register using
        # a relative name based upon creator and a fully-qualified name should
        # not be a valid name as it is a duplicate
        update = holding_update.Register(
            update_type=holding_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='/holding')
        self.assertFalse(
            market_place_object_update.global_is_valid_name(
                store,
                name='/holding',
                object_type=update.ObjectType,
                creator_id=participant.ObjectID))
        update = holding_update.Register(
            update_type=holding_update.Register.UpdateType,
            creator_id=participant.ObjectID,
            name='//participant/holding')
        self.assertFalse(
            market_place_object_update.global_is_valid_name(
                store,
                name='//participant/holding',
                object_type=update.ObjectType,
                creator_id=participant.ObjectID))
示例#2
0
    def register_holding(self, account, asset, count, name='', description=''):
        """
        Register a holding.

        :param id account: the identifier the account that scopes the holding
        :param id asset: the identifier for the asset to store in the holding
        :param int count: the initial number of assets to store in the holding
        :param str name: an optional name for the holding, unique for the
            current participant
        :param str description: an optional description for the holding

        :return: holding id
        :rtype: id
        """
        update = holding_update.Register()

        update.CreatorID = self.CreatorID
        update.AccountID = account
        update.AssetID = asset
        update.Count = count
        update.Name = name
        update.Description = description

        return self._register(update)