def test_search_assets_by_name_multiple():
    #given
    browser = AfStructureBrowser(assets_query=".*Extruding Process")

    # when
    actual = browser.search_assets(TEST_STRUCTURE)

    # then
    assert actual is not None
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock\\Extruding Process":
        {
            "name": "Extruding Process",
            "description": "Current percent savings in energy use.",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock\\Extruding Process",
            "attributes": [{
                "name": "test"
            }]
        },
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process": {
            "name": "Second Extruding Process",
            "description": "Description 2",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process",
            "template": "Boiler",
            "attributes": [{
                "name": "test"
            }]
        }
    }

    assert expected == actual
def test_select_attributes_from_all_assets():
    # given
    browser = AfStructureBrowser(assets_query=".*",
                                 assets_field="name",
                                 attributes_query="Fuel",
                                 attributes_field="name")

    # when
    actual = browser.search_assets(TEST_STRUCTURE_WITH_ATTRIBUTES)

    # then
    assert actual is not None
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen": {
            "name": "NuGreen",
            "path": "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen",
            "attributes": [{
                "name": "Fuel",
                "description": "Fuel description"
            }]
        },
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process": {
            "name":
            "Second Extruding Process",
            "description":
            "Description 2",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process",
            "attributes": [{
                "name": "Fuel",
                "description": "Fuel description second 2"
            }]
        }
    }
    assert expected == actual
def test_select_no_attributes():
    # given
    browser = AfStructureBrowser(
        assets_query=".*",
        assets_field="name",
        attributes_query="no attributes with this name",
        attributes_field="name")

    # when
    actual = browser.search_assets(TEST_STRUCTURE_WITH_ATTRIBUTES)

    # then
    assert actual is not None
    expected = {}
    assert expected == actual
def test_select_attributes_by_pi_point_name():
    # given
    browser = AfStructureBrowser(assets_query=".*",
                                 assets_field="name",
                                 attributes_query="SINUSOIDU_1",
                                 attributes_field="point")

    # when
    actual = browser.search_assets(TEST_STRUCTURE_WITH_ATTRIBUTES)

    # then
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock": {
            "name":
            "Little Rock",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock",
            "description":
            "Current ...",
            "attributes": [{
                "name":
                "Water Savings",
                "categories": [{
                    "name":
                    "Energy Savings KPI",
                    "description":
                    "Relative energy use per ton of process feed."
                }],
                "description":
                "Current percent savings in energy use.",
                "value":
                "",
                "type":
                "System.Double",
                "path":
                "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock\\Extruding Process\\Equipment\\B-045|Water Savings",
                "point": {
                    "name": "SINUSOIDU_1",
                    "id": "10837",
                    "path": "\\\\EC2AMAZ-0EE3VGR\\SINUSOIDU_1"
                }
            }]
        }
    }

    assert actual is not None
    assert expected == actual
def test_select_attributes_by_name():
    # given
    browser = AfStructureBrowser(assets_query="NuGreen",
                                 assets_field="name",
                                 attributes_query="Fuel")

    # when
    actual = browser.search_assets(TEST_STRUCTURE_WITH_ATTRIBUTES)

    # then
    assert actual is not None
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen": {
            "name": "NuGreen",
            "path": "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen",
            "attributes": [{
                "name": "Fuel",
                "description": "Fuel description"
            }]
        }
    }
    assert expected == actual
示例#6
0
def search_af_structure():
    search_json = request.get_json()

    assets_query = search_json['assetsQuery'].replace('*', '.*')
    asset_field = search_json[
        'assetsField'] if search_json['assetsField'] != "" else "name"
    attributes_query = search_json['attributesQuery'].replace(
        '*', '.*') if search_json['attributesQuery'] != "" else ".*"
    attributes_field = search_json[
        'attributesField'] if search_json['attributesField'] != "" else "name"

    if asset_field == 'path':
        assets_query = ".*" + assets_query

    browser = AfStructureBrowser(assets_query=assets_query,
                                 assets_field=asset_field,
                                 attributes_query=attributes_query,
                                 attributes_field=attributes_field)
    feed_manager = _create_managed_feeds_manager(app.config)
    structure = feed_manager.get_latest_af_structure(
        database=app.config['af_structure_database'])
    result = browser.search_assets([structure])
    return jsonify(result)
def test_search_assets_by_path():
    #given
    browser = AfStructureBrowser(
        assets_query=".*Little Rock\\Extruding Process.*", assets_field="path")

    # when
    actual = browser.search_assets(TEST_STRUCTURE)

    # then
    assert actual is not None
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock\\Extruding Process":
        {
            "name": "Extruding Process",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Little Rock\\Extruding Process",
            "description": "Current percent savings in energy use.",
            "attributes": [{
                "name": "test"
            }]
        }
    }
    assert expected == actual
def test_search_assets_by_template():
    #given
    browser = AfStructureBrowser(assets_query="Boiler",
                                 assets_field="template")

    # when
    actual = browser.search_assets(TEST_STRUCTURE)

    # then
    assert actual is not None
    expected = {
        "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process": {
            "name": "Second Extruding Process",
            "description": "Description 2",
            "path":
            "\\\\EC2AMAZ-0EE3VGR\\NuGreen\\NuGreen\\Second Extruding Process",
            "template": "Boiler",
            "attributes": [{
                "name": "test"
            }]
        }
    }

    assert expected == actual