コード例 #1
0
def create_docs(doc_id_prefix, number, content=None, attachment_name=None, expiry=None, channels=None):
    """
    Keyword that creates a list of document bodies as a list for use with Add Bulk Docs keyword
    return result format:
    [
        {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_0', '_exp': 3},
        {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_1', '_exp': 3}, ...
    ]
    """

    if channels is None:
        channels = []

    types.verify_is_list(channels)

    docs = []

    for i in range(number):

        if doc_id_prefix is None:
            doc_id = str(uuid.uuid4())
        else:
            doc_id = "{}_{}".format(doc_id_prefix, i)

        doc = create_doc(doc_id, content, attachment_name, expiry, channels)
        docs.append(doc)

    return docs
コード例 #2
0
def create_doc(doc_id, content=None, attachment_name=None, expiry=None, channels=None):
    """
    Keyword that creates a document body as a list for use with Add Doc keyword
    return result format:
    {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_0', '_exp': 3}
    """

    if channels is None:
        channels = []

    types.verify_is_list(channels)

    doc = {}

    if id is not None:
        doc["_id"] = doc_id

    if expiry is not None:
        doc["_exp"] = expiry

    if content is not None:
        doc["content"] = content

    doc["channels"] = channels

    if attachment_name is not None:
        doc["_attachments"] = {
            attachment_name: {"data": get_attachment(attachment_name)}
        }

    logging.debug(doc)

    return doc
コード例 #3
0
    def __init__(self, name, password, channels, roles):
        self.name = name
        self.password = password

        types.verify_is_list(channels)
        self.channels = channels

        types.verify_is_list(roles)
        self.roles = roles
コード例 #4
0
    def __init__(self, name, password, channels, roles):
        self.name = name
        self.password = password

        types.verify_is_list(channels)
        self.channels = channels

        types.verify_is_list(roles)
        self.roles = roles
コード例 #5
0
def load_from_data_dir(names):

    types.verify_is_list(names)

    atts = []
    for name in names:
        file_path = "{}/{}".format(DATA_DIR, name)
        log_info("Loading attachment from file: {}".format(file_path))
        with open(file_path) as f:
            data = base64.standard_b64encode(f.read())
            atts.append(Attachment(name, data))
    return atts
コード例 #6
0
def create_doc(doc_id,
               content=None,
               attachments=None,
               expiry=None,
               channels=None,
               prop_generator=None):
    """
    Keyword that creates a document body as a list for use with Add Doc keyword
    return result format:
    {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_0', '_exp': 3}
    """

    if channels is None:
        channels = []

    if attachments is None:
        attachments = []

    types.verify_is_list(channels)
    types.verify_is_list(attachments)

    doc = {}

    if doc_id is not None:
        doc["_id"] = doc_id

    if expiry is not None:
        doc["_exp"] = expiry

    if content is not None:
        doc["content"] = content

    doc["channels"] = channels

    if attachments:
        # Loop through list of attachment and attach them to the doc
        doc["_attachments"] = {
            att.name: {
                "data": att.data
            }
            for att in attachments
        }

    logging.debug(doc)

    if prop_generator is not None:
        types.verify_is_callable(prop_generator)
        props = prop_generator()
        for k, v in props.items():
            doc[k] = v

    return doc
コード例 #7
0
    def create_buckets(self, bucket_names):
        """
        # Figure out what total ram available is
        # Divide by number of buckets
        """
        types.verify_is_list(bucket_names)

        if len(bucket_names) == 0:
            return
        log_info("Creating buckets: {}".format(bucket_names))

        # Get the amount of RAM to allocate for each server bucket
        per_bucket_ram_mb = self.get_ram_per_bucket(len(bucket_names))

        for bucket_name in bucket_names:
            self.create_bucket(bucket_name, per_bucket_ram_mb)
コード例 #8
0
def create_docs(doc_id_prefix,
                number,
                content=None,
                attachments_generator=None,
                expiry=None,
                channels=None,
                prop_generator=None):
    """
    Keyword that creates a list of document bodies as a list for use with Add Bulk Docs keyword
    return result format:
    [
        {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_0', '_exp': 3},
        {'channels': [u'NBC', u'ABC'], '_id': 'exp_3_1', '_exp': 3}, ...
    ]
    """

    if channels is None:
        channels = []

    types.verify_is_list(channels)

    if attachments_generator is not None:
        types.verify_is_callable(attachments_generator)

    docs = []

    for i in range(number):

        if doc_id_prefix is None:
            doc_id = str(uuid.uuid4())
        else:
            doc_id = "{}_{}".format(doc_id_prefix, i)

        # Call attachment generator if it has been defined
        attachments = None
        if attachments_generator is not None:
            attachments = attachments_generator()

        doc = create_doc(doc_id=doc_id,
                         content=content,
                         attachments=attachments,
                         expiry=expiry,
                         channels=channels,
                         prop_generator=prop_generator)
        docs.append(doc)

    return docs