Exemplo n.º 1
0
def test_is_child():
    # Check that part 1 is a child, but part 3 is not
    test_parts = api_initialize.import_json('test_data.json')
    part1 = api_helper.get_part(1, test_parts)
    part3 = api_helper.get_part(3, test_parts)
    assert api_helper.is_child(part1, test_parts) == True
    assert api_helper.is_child(part3, test_parts) == False
Exemplo n.º 2
0
def get_subassemblies():
    # get_sub_assemblies returns a list of all subassemblies (parts that have
    # children and are also themselves children of some other part)

    if len(parts) == 0:
        # if no parts, return resource not found
        raise InvalidUsage('No parts exist', status_code=404)

    # find all  subassemblies -- parts for which the list of children is
    # not empty, and they are children of some other part
    subassemblies = [
        part for part in parts
        if part['children'] and api_helper.is_child(part, parts)
    ]
    return jsonify({'subassemblies': subassemblies})  # return list as json
Exemplo n.º 3
0
def get_orphans():
    # get_orphans returns a list of all orphans
    # (parts that do not have children and are not children of some other part)

    if len(parts) == 0:
        # if no parts, return resource not found
        raise InvalidUsage('No parts exist', status_code=404)

    # find all  orphans -- parts for which the list of children is empty,
    # and they are not children of some other part
    orphans = ([
        part for part in parts
        if not part['children'] and not api_helper.is_child(part, parts)
    ])

    return jsonify({'orphans': orphans})  # return list as json
Exemplo n.º 4
0
def get_components():
    # get_components returns a list of all components (partsthat do
    # not have children but are themselves children of some other part)

    if len(parts) == 0:
        # if no parts, return resource not found
        raise InvalidUsage('No parts exist', status_code=404)

    # find all  components -- parts for which the list of children is empty,
    # and they are children of some other part
    components = ([
        part for part in parts
        if not part['children'] and api_helper.is_child(part, parts)
    ])

    return jsonify({'components': components})  # return list as json
Exemplo n.º 5
0
def get_top_assemblies():
    # get_top_assemblies returns a list of all top level assemblies
    # (parts that have children and are not themselves children)

    if len(parts) == 0:
        # if no parts, return resource not found
        raise InvalidUsage('No parts exist', status_code=404)

    # find all top assemblies -- parts for which the list of children is not
    # empty, and they are not children of some other part
    top_assemblies = ([
        part for part in parts
        if part['children'] and not api_helper.is_child(part, parts)
    ])

    return jsonify({'top assemblies': top_assemblies})  # return list as json