def test_generate_materializations(sample): out = DbtOutput(result=sample) materializations = [mat for mat in generate_materializations(out)] assert len(materializations) == 3 mat_names = {mat.asset_key for mat in materializations} assert mat_names == {AssetKey(["model", "my_schema", f"table_{i}"]) for i in range(1, 4)}
def test_load_from_manifest_json(): manifest_path = file_relative_path(__file__, "sample_manifest.json") with open(manifest_path, "r") as f: manifest_json = json.load(f) run_results_path = file_relative_path(__file__, "sample_run_results.json") with open(run_results_path, "r") as f: run_results_json = json.load(f) dbt_assets = load_assets_from_dbt_manifest(manifest_json=manifest_json) assert_assets_match_project(dbt_assets) dbt = MagicMock() dbt.run.return_value = DbtOutput(run_results_json) assets_job = build_assets_job( "assets_job", dbt_assets, resource_defs={"dbt": ResourceDefinition.hardcoded_resource(dbt)}, ) assert assets_job.execute_in_process().success
def test_runtime_metadata_fn(): manifest_path = file_relative_path(__file__, "sample_manifest.json") with open(manifest_path, "r") as f: manifest_json = json.load(f) run_results_path = file_relative_path(__file__, "sample_run_results.json") with open(run_results_path, "r") as f: run_results_json = json.load(f) def runtime_metadata_fn(context, node_info): return { "op_name": context.solid_def.name, "dbt_model": node_info["name"] } dbt_assets = load_assets_from_dbt_manifest( manifest_json=manifest_json, runtime_metadata_fn=runtime_metadata_fn) assert_assets_match_project(dbt_assets) dbt = MagicMock() dbt.run.return_value = DbtOutput(run_results_json) assets_job = build_assets_job( "assets_job", dbt_assets, resource_defs={"dbt": ResourceDefinition.hardcoded_resource(dbt)}, ) result = assets_job.execute_in_process() assert result.success materializations = [ event.event_specific_data.materialization for event in result.events_for_node(dbt_assets[0].op.name) if event.event_type_value == "ASSET_MATERIALIZATION" ] assert len(materializations) == 4 assert materializations[0].metadata_entries == [ MetadataEntry("op_name", value=dbt_assets[0].op.name), MetadataEntry("dbt_model", value=materializations[0].asset_key.path[0]), ]
def test_pickle_roundtrip(): rr = DbtOutput(result=DBT_RESULT_DICT) rr_new = pickle.loads(pickle.dumps(rr)) assert vars(rr) == vars(rr_new)