コード例 #1
0
def test_find_description(config):
    raw_lookml = """
view: dim_geography {
 sql_table_name: `BQDW.DimGeography` ;;

  dimension: city_code {
    type: string
    description: "this
    is
    an
    exsiting
    multiline
    description"
    sql: ${TABLE}.CityCode ;;
  }

  measure: count {
    type: count
    drill_fields: [detail*]
  }
}
    """
    # json_data = get_json_from_lookml(raw_lookml)
    modifier = LookMlModifier(config)
    lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view")
    desc, has_key = modifier.find_description(lookml, "dimension", "city_code")
    assert has_key
    assert (
        desc
        == """this
    is
    an
    exsiting
    multiline
    description"""
    )

    desc, has_key = modifier.find_description(lookml, "measure", "count")
    assert not has_key

    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(lookml, "dimension", "xxx")
    assert "Did not find dimension xxx" in str(e.value)

    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(lookml, "xxxx", "city_code")
    assert "Unrecognized header_type xxx" in str(e.value)
コード例 #2
0
def test_find_description(config):
    raw_lookml = """
view: dim_geography {
 sql_table_name: `BQDW.DimGeography` ;;

  dimension: city_code {
    type: string
    description: "this
    is
    an
    exsiting
    multiline
    description"
    sql: ${TABLE}.CityCode ;;
  }

  measure: count {
    type: count
    drill_fields: [detail*]
  }
}
    """
    json_data = get_json_from_lookml(raw_lookml)
    modifier = LookMlModifier(config)
    desc, has_key = modifier.find_description(json_data, 'dimension', 'city_code')
    assert has_key
    assert desc == """this
    is
    an
    exsiting
    multiline
    description"""

    desc, has_key = modifier.find_description(json_data, 'measure', 'count')
    assert not has_key

    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(json_data, 'dimension', 'xxx')
    assert 'Did not find dimension xxx' in str(e.value)

    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(json_data, 'xxxx', 'city_code')
    assert 'Unrecognized header_type xxx' in str(e.value)
コード例 #3
0
def test_find_description3(config):
    modifier = LookMlModifier(config)
    raw_lookml = """
        connection: "datawarehouse"
        include: "*.view.lkml"
        explore: an_explore {
        }
    """
    filename = "test/amodel.model.lkml"
    json_data = get_json_from_lookml(raw_lookml, filename)
    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(json_data, 'xxx', 'xxx')
    assert 'Only views are supported. Is this a LookML model?' in str(e.value)
    if os.path.exists(filename):
        os.remove(filename)
コード例 #4
0
def test_find_description3(config):
    raw_lookml = """
        connection: "datawarehouse"
        include: "*.view.lkml"
        explore: an_explore {
        }
    """
    filename = "test/amodel.model.lkml"
    modifier = LookMlModifier(config)
    lookml = get_lookml_from_raw_lookml(raw_lookml, "amodel.model")
    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(lookml, "xxx", "xxx")
    assert "Only views are supported. This is type model" in str(e.value)
    if os.path.exists(filename):
        os.remove(filename)
コード例 #5
0
def test_find_description2(config):
    modifier = LookMlModifier(config)
    raw_lookml = """
      view: first_view {
        dimension: memberID {
          type: string
        }
      }

      view: second_view {
        dimension: memberID {
          type: string
        }
      }
    """
    json_data = get_json_from_lookml(raw_lookml)
    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(json_data, 'xxx', 'xxx')
    assert 'There should only 1 view. We found 2' in str(e.value)
コード例 #6
0
def test_find_description2(config):
    modifier = LookMlModifier(config)
    raw_lookml = """
      view: first_view {
        dimension: memberID {
          type: string
        }
      }

      view: second_view {
        dimension: memberID {
          type: string
        }
      }
    """
    lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view")
    with pytest.raises(Exception) as e:
        desc, has_key = modifier.find_description(lookml, "xxx", "xxx")
    assert "There should only 1 view. We found 2" in str(e.value)