@@ -642,3 +642,94 @@ def test_dcm_test_command(
642642 result = runner .invoke_with_connection (["dcm" , "test" , project_name ])
643643 assert result .exit_code == 0 , result .output
644644 assert "expectation(s) passed successfully" in result .output
645+
646+
647+ @pytest .mark .qa_only
648+ @pytest .mark .integration
649+ def test_dcm_refresh_command (
650+ runner ,
651+ test_database ,
652+ project_directory ,
653+ object_name_provider ,
654+ sql_test_helper ,
655+ ):
656+ project_name = object_name_provider .create_and_get_next_object_name ()
657+ base_table_name = f"{ test_database } .PUBLIC.RefreshBaseTable"
658+ dynamic_table_name = f"{ test_database } .PUBLIC.RefreshDynamicTable"
659+
660+ with project_directory ("dcm_project" ) as project_root :
661+ result = runner .invoke_with_connection (["dcm" , "create" , project_name ])
662+ assert result .exit_code == 0 , result .output
663+
664+ # Deploy the project.
665+ result = runner .invoke_with_connection_json (
666+ [
667+ "dcm" ,
668+ "deploy" ,
669+ project_name ,
670+ "-D" ,
671+ f"table_name='{ test_database } .PUBLIC.OutputTestTable'" ,
672+ ]
673+ )
674+ assert result .exit_code == 0 , result .output
675+
676+ # 1) Without any dynamic tables, run refresh command - should report no dynamic tables.
677+ result = runner .invoke_with_connection (["dcm" , "refresh" , project_name ])
678+ assert result .exit_code == 0 , result .output
679+ assert "No dynamic tables found in the project." in result .output
680+
681+ # 2) Define base table and dynamic table with long refresh time.
682+ table_definitions = f"""
683+ define table identifier('{ base_table_name } ') (
684+ id int, name varchar, email varchar
685+ );
686+
687+ define dynamic table identifier('{ dynamic_table_name } ')
688+ target_lag = '1000 minutes'
689+ WAREHOUSE = xs
690+ as select * from { base_table_name } ;
691+ """
692+ file_a_path = project_root / "file_a.sql"
693+ original_content = file_a_path .read_text ()
694+ file_a_path .write_text (original_content + table_definitions )
695+
696+ # Deploy the project.
697+ result = runner .invoke_with_connection_json (
698+ [
699+ "dcm" ,
700+ "deploy" ,
701+ project_name ,
702+ "-D" ,
703+ f"table_name='{ test_database } .PUBLIC.OutputTestTable'" ,
704+ ]
705+ )
706+ assert result .exit_code == 0 , result .output
707+
708+ # 3) Insert data into the base table.
709+ insert_data_sql = f"""
710+ INSERT INTO { base_table_name } (id, name, email) VALUES
711+ (1, 'Alice Johnson', '[email protected] '), 712+ (2, 'Bob Williams', '[email protected] '), 713+ (3, 'Charlie Brown', '[email protected] '); 714+ """
715+ sql_test_helper .execute_single_sql (insert_data_sql )
716+
717+ # 4) Verify that data is NOT yet in the dynamic table (due to long refresh time).
718+ check_dt_sql = f"SELECT COUNT(*) as cnt FROM { dynamic_table_name } "
719+ result = sql_test_helper .execute_single_sql (check_dt_sql )
720+ count_before = result [0 ]["CNT" ]
721+ assert count_before == 0 , "Dynamic table should be empty before refresh."
722+
723+ # 5) Run dcm refresh command.
724+ result = runner .invoke_with_connection (["dcm" , "refresh" , project_name ])
725+ assert result .exit_code == 0 , result .output
726+ # Should show at least 1 table was refreshed
727+ assert (
728+ "1 dynamic table(s) refreshed" in result .output
729+ or "dynamic table(s) refreshed" in result .output
730+ )
731+
732+ # 6) Verify that data is NOW in the dynamic table.
733+ result = sql_test_helper .execute_single_sql (check_dt_sql )
734+ count_after = result [0 ]["CNT" ]
735+ assert count_after == 3 , "Dynamic table should have 3 rows after refresh."
0 commit comments