def test_process_file(): config = { "rules": { "other_rules": [{ "name": "NoOrphansRule", "run": True }] } } raw_lookml = """ view: aview { dimension: dimname { type: string } } """ filename = "test/aview.view.lkml" lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view") rule = NoOrphansRule(config) rule.process_lookml(lookml) d = rule.view_dict assert len(d) == 1 assert "aview" in d assert d["aview"] == filename if os.path.exists(filename): os.remove(filename)
def test_run1(): raw_lookml = """ view: aview { sql_table_name: bqdw.engagement_score ;; } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view") relevant, passed = DataSourceRule().run(lookml) assert relevant assert passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
def test_explores2(): raw_lookml = """ view: aview { dimension: SHOUTYNAME { type: string } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view") explores = lookml.explores() assert explores is None assert not lookml.has_explores()
def test_run4(): raw_lookml = """ connection: "datawarehouse" include: "*.view.lkml" explore: an_explore { } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "amodel.model") relevant, passed = DataSourceRule().run(lookml) assert not relevant assert not passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
def test_run3(): raw_lookml = """ connection: "datawarehouse" include: "*.view.lkml" explore: an_explore { } """ lookml = get_lookml_from_raw_lookml(raw_lookml, 'amodel.model') relevant, passed = FilenameViewnameMatchRule().run(lookml) assert not relevant assert not passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
def test_run2(): raw_lookml = """ view: aview { dimension: memberID { type: string } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view") relevant, passed = DataSourceRule().run(lookml) assert relevant assert not passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
def test_run(): raw_lookml = """ view: aview { dimension: memberID { type: string } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, 'junkyname.view') relevant, passed = FilenameViewnameMatchRule().run(lookml) assert relevant assert not passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
def test_run2(): raw_lookml = """ view: aview { dimension: memberID { type: string } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, 'tmp.view') relevant, passed = OneViewPerFileRule().run(lookml) assert relevant assert passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
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)
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)
def test_run3(): raw_lookml = """ view: aview { derived_table: { sql: SELECT * from table ;; } dimension: memberID { type: string } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "aview.view") relevant, passed = DataSourceRule().run(lookml) assert relevant assert passed if os.path.exists(lookml.infilepath): os.remove(lookml.infilepath)
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)
def test_explores(): #this will test duplicate model keys raw_lookml=""" connection: "datawarehouse" include: "*.view.lkml" week_start_day: sunday week_start_day: monday explore: explore1 { from: view1 join: view2 { from: view2 } } """ lookml = get_lookml_from_raw_lookml(raw_lookml, "amodel.model") explores = lookml.explores() assert explores is not None assert lookml.has_explores() assert lookml.json_data['week_start_day'] == 'monday'