def test_bad_fetch_param_raises(self): task = SqlServerFetch(db_name="test", user="******", host="test") with pytest.raises( ValueError, match= r"The 'fetch' parameter must be one of the following - \('one', 'many', 'all'\)", ): task.run(query="SELECT * FROM some_table", fetch="not a valid parameter")
def test_query_string_must_be_provided(self): task = SqlServerFetch(db_name="test", user="******", host="test") with pytest.raises(ValueError, match="A query string must be provided"): task.run()
from prefect.tasks.sql_server import SqlServerFetch from sql import get_manual_override_rows path = Path(__file__).resolve().parent / result_folder result_formatter = LocalResult(dir=path, location="{flow_name}/" "{scheduled_start_time:%d-%m_%H-%M-%S}/" "{task_full_name}-{task_run_id}.prefect_result") # Get our database items sql_task = SqlServerFetch(db_name=db_name, user=user, host=host, query=get_manual_override_rows, fetch='many', fetch_count=3, result=result_formatter, name="SQL-stuff" # commit: bool = False, ) # create a demo task @task def clean_dataframe(df): df = df[df[column] == some_item].filter(something) return df
def test_construction(self): task = SqlServerFetch(db_name="test", user="******", host="test") assert task.fetch == "one"
#-------------------------------------------------------------- # Task classes #-------------------------------------------------------------- get_manual_override_rows = """ --sql SELECT * from manual_override WHERE yes_no = 'yes' and text != 'No text - category selected manually'; """ # Get our database items sql_task = SqlServerFetch(db_name=prefect.config.sql_server.database, user=prefect.config.sql_server.user, host=prefect.config.sql_server.server, query=get_manual_override_rows, fetch='many', fetch_count=3, result=result_formatter, name="SQL-stuff" # commit: bool = False, ) #-------------------------------------------------------------- # Flow context #-------------------------------------------------------------- with Flow("github_flow") as f: password = EnvVarSecret(prefect.config.sql_server.password_var) logger = prefect.context.get("logger") thing = Parameter("thing", default=["Thing 1"]) d = dog(thing)