Exemplo n.º 1
0
def build_the_standard_context_subscription_ontime_payload_with_the_previous_data_and_the_following(
        step):
    """
    Build the payload taking into account the entities and notify condition have to be defined before
    | attributes(list, separated by comma) | reference | duration |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities', 'notify_conditions'])
    if len(step.hashes) == 1:
        columns = ['attributes', 'reference', 'duration']
        for column in columns:
            if column not in step.hashes[0]:
                raise ValueError(
                    'The column {column} has to exist in the table. The table is: {hashes}'
                    .format(column=column, hashes=step.hashes))
        world.payloads[
            world.
            payloads_count] = PayloadUtils.build_standard_subscribe_context_payload(
                world.entities, step.hashes[0]['attributes'].split(','),
                'http://{ip}:{port}{path}'.format(
                    ip=world.config['mock']['host'],
                    port=world.config['mock']['port'],
                    path=step.hashes[0]['reference']),
                step.hashes[0]['duration'], world.notify_conditions)
Exemplo n.º 2
0
def build_the_standard_query_context_payload_with_the_previous_data(step):
    """
    Build the payload, taking into account the entities has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities'])
    if len(step.hashes) > 0:
        if 'attributes' in step.hashes[0]:
            rows = len(step.hashes)
            if rows != 1:
                raise ValueError(
                    'The table of the step has to have only 1 row but it has {rows}'
                    .format(rows=rows))
            world.payloads[
                world.
                payloads_count] = PayloadUtils.build_standard_query_context_payload(
                    world.entities, step.hashes[0]['attributes'].split(','))
        else:
            raise ValueError(
                'The column expected in the table is "attributes"')
    else:
        world.payloads[
            world.
            payloads_count] = PayloadUtils.build_standard_query_context_payload(
                world.entities)
Exemplo n.º 3
0
def build_the_standard_entity_delete_payload_with_the_previous_data(step):
    """
    Build the payload, taking into account the context_elements has to be defined in steps before
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['context_elements'])
    world.payloads[world.payloads_count] = PayloadUtils.build_standard_entity_delete_payload(
        world.context_elements)
Exemplo n.º 4
0
def there_is_requests_requested_to_the_mock(step, number_requests):
    check_world_attribute_is_not_none(['mock_data'])
    requests = json.loads(world.mock_data.text)['requests']
    number_mock_requests = 0
    for url in requests.keys():
        number_mock_requests += len(requests[url])
    assert str(number_requests) == str(
        number_mock_requests), 'The requests to the mock were {number_mock_requests} and the expeted are {number_expected}'.format(
        number_mock_requests=number_mock_requests, number_expected=number_requests)
Exemplo n.º 5
0
def build_the_standard_context_registration_payload_with_the_previous_data(step, duration):
    """
    Build the payload, taking into account the context_registration has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['context_registrations'])
    world.payloads[world.payloads_count] = PayloadUtils.build_context_registration_payload(
        world.context_registrations, duration)
Exemplo n.º 6
0
def build_the_standard_discover_context_availability_payload_with_the_previous_data(step):
    """
    Build the payload, taking into account the entities has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities'])
    world.payloads[world.payloads_count] = PayloadUtils.build_discover_context_availability_payload(
        world.entities)
Exemplo n.º 7
0
def build_the_standard_entity_delete_payload_with_the_previous_data(step):
    """
    Build the payload, taking into account the context_elements has to be defined in steps before
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['context_elements'])
    world.payloads[
        world.
        payloads_count] = PayloadUtils.build_standard_entity_delete_payload(
            world.context_elements)
Exemplo n.º 8
0
def the_path_in_the_last_request_contains(step, content):
    check_world_attribute_is_not_none(['mock_data'])
    mock_response = eval(world.mock_data.text)
    path = mock_response['requests'].keys()[0]
    try:
        assert path.find(
            content) >= 0, 'The content "{content}" is not in the path of the last request in the mock "{path}"'.format(
            content=str(content), path=str(path))
    except KeyError as e:
        world.log.error(mock_response)
        raise e
Exemplo n.º 9
0
def the_path_in_the_last_request_contains(step, content):
    check_world_attribute_is_not_none(['mock_data'])
    mock_response = eval(world.mock_data.text)
    path = mock_response['requests'].keys()[0]
    try:
        assert path.find(
            content
        ) >= 0, 'The content "{content}" is not in the path of the last request in the mock "{path}"'.format(
            content=str(content), path=str(path))
    except KeyError as e:
        world.log.error(mock_response)
        raise e
Exemplo n.º 10
0
def build_the_standard_context_registration_payload_with_the_previous_data(
        step, duration):
    """
    Build the payload, taking into account the context_registration has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['context_registrations'])
    world.payloads[
        world.
        payloads_count] = PayloadUtils.build_context_registration_payload(
            world.context_registrations, duration)
Exemplo n.º 11
0
def build_the_standard_discover_context_availability_payload_with_the_previous_data(
        step):
    """
    Build the payload, taking into account the entities has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities'])
    world.payloads[
        world.
        payloads_count] = PayloadUtils.build_discover_context_availability_payload(
            world.entities)
Exemplo n.º 12
0
def the_path_in_the_last_request_contains(step, head):
    check_world_attribute_is_not_none(['mock_data'])
    mock_response = eval(world.mock_data.text)['requests']
    elements = len(mock_response.keys())
    try:
        headers = mock_response[mock_response.keys()[elements - 1]][0]['headers']
        assert head.lower() not in headers, \
            'The head {head} exist in the headers forwarded,\
             check the headers forwarded {headers}' \
                .format(head=head.lower(), headers=headers)
    except KeyError as e:
        world.log.error('The response received is: {response}'.format(response=mock_response))
        raise e
Exemplo n.º 13
0
def a_context_registrations_with_the_before_entities_and_attributes_and_the_following_providing_applications(step):
    """
    Step to create a constextRegistrations with the attributes and entities setted before, one for each providing application
    a context registrations with the before entities and attributes and the following providing applications
    | providing_application |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities', 'attributes_consult'])
    world.context_registrations = ContextRegistrations()
    for line in step.hashes:
        world.context_registrations.add_context_registration(
            world.entities, world.attributes_consult,
            'http://{ip}:{port}{path}'.format(ip=world.config['mock']['host'], port=world.config['mock']['port'],
                                              path=line['providing_application']))
Exemplo n.º 14
0
def a_context_registrations_with_the_before_entities_and_attributes_and_the_following_providing_applications(
        step):
    """
    Step to create a constextRegistrations with the attributes and entities setted before, one for each providing application
    a context registrations with the before entities and attributes and the following providing applications
    | providing_application |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities', 'attributes_consult'])
    world.context_registrations = ContextRegistrations()
    for line in step.hashes:
        world.context_registrations.add_context_registration(
            world.entities, world.attributes_consult,
            'http://{ip}:{port}{path}'.format(
                ip=world.config['mock']['host'],
                port=world.config['mock']['port'],
                path=line['providing_application']))
Exemplo n.º 15
0
def add_a_context_element_with_the_before_attrs_and_the_following_entities(step):
    """
    Step to create a contextElement if doesnt exist, and add the attributes data defined before
    add a context element with the before attrs and the followin entity properties
    | entity_id | entity_type | is_pattern(optional) |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['attributes_creation'])
    if not isinstance(world.context_elements, ContextElements):
        world.context_elements = ContextElements()
    for line in step.hashes:
        if "is_pattern" in line:
            world.context_elements.add_context_element(line['entity_id'], line['entity_type'],
                                                       world.attributes_creation,
                                                       line['is_pattern'])
        else:
            world.context_elements.add_context_element(line['entity_id'], line['entity_type'],
                                                       world.attributes_creation)
Exemplo n.º 16
0
def build_the_standard_query_context_payload_with_the_previous_data(step):
    """
    Build the payload, taking into account the entities has to be defined in steps before
    || attributes(list, separated by comma)(optional) ||
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities'])
    if len(step.hashes) > 0:
        if 'attributes' in step.hashes[0]:
            rows = len(step.hashes)
            if rows != 1:
                raise ValueError('The table of the step has to have only 1 row but it has {rows}'.format(rows=rows))
            world.payloads[world.payloads_count] = PayloadUtils.build_standard_query_context_payload(
                world.entities, step.hashes[0]['attributes'].split(','))
        else:
            raise ValueError('The column expected in the table is "attributes"')
    else:
        world.payloads[world.payloads_count] = PayloadUtils.build_standard_query_context_payload(
            world.entities)
Exemplo n.º 17
0
def build_the_standard_context_subscription_ontime_payload_with_the_previous_data_and_the_following(step):
    """
    Build the payload taking into account the entities and notify condition have to be defined before
    | attributes(list, separated by comma) | reference | duration |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['entities', 'notify_conditions'])
    if len(step.hashes) == 1:
        columns = ['attributes', 'reference', 'duration']
        for column in columns:
            if column not in step.hashes[0]:
                raise ValueError(
                    'The column {column} has to exist in the table. The table is: {hashes}'.format(column=column,
                                                                                                   hashes=step.hashes))
        world.payloads[world.payloads_count] = PayloadUtils.build_standard_subscribe_context_payload(
            world.entities, step.hashes[0]['attributes'].split(','),
            'http://{ip}:{port}{path}'.format(ip=world.config['mock']['host'], port=world.config['mock']['port'],
                                              path=step.hashes[0]['reference']),
            step.hashes[0]['duration'],
            world.notify_conditions)
Exemplo n.º 18
0
def add_a_context_element_with_the_before_attrs_and_the_following_entities(
        step):
    """
    Step to create a contextElement if doesnt exist, and add the attributes data defined before
    add a context element with the before attrs and the followin entity properties
    | entity_id | entity_type | is_pattern(optional) |
    :param step:
    :return:
    """
    check_world_attribute_is_not_none(['attributes_creation'])
    if not isinstance(world.context_elements, ContextElements):
        world.context_elements = ContextElements()
    for line in step.hashes:
        if "is_pattern" in line:
            world.context_elements.add_context_element(
                line['entity_id'], line['entity_type'],
                world.attributes_creation, line['is_pattern'])
        else:
            world.context_elements.add_context_element(
                line['entity_id'], line['entity_type'],
                world.attributes_creation)