-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #562 from OP-TED/feature/SWS1-14
Fix issue #557
- Loading branch information
Showing
10 changed files
with
298 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
tests/unit/dags/_test_daily_materialised_views_update_schedule.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
# import os | ||
# | ||
# from airflow import DAG | ||
# from airflow.models import DagBag, Variable | ||
# from airflow.timetables.trigger import CronTriggerTimetable | ||
# | ||
# from ted_sws import DAG_MATERIALIZED_VIEW_UPDATE_DEFAULT_TIMETABLE | ||
# | ||
# | ||
# def test_daily_materialised_view_change_timetable_from_airflow_variable_after_reparse(dag_bag: DagBag, | ||
# dag_materialised_view_update_schedule_variable_name: str, | ||
# daily_materialised_views_dag_id: str, | ||
# example_dag_cron_table: CronTriggerTimetable, | ||
# airflow_timetable_import_error_message: str): | ||
# daily_materialised_view_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert daily_materialised_view_dag is not None | ||
# assert daily_materialised_view_dag.schedule_interval != example_dag_cron_table._expression | ||
# | ||
# Variable.set(key=dag_materialised_view_update_schedule_variable_name, value=example_dag_cron_table._expression) | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# daily_materialised_view_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert daily_materialised_view_dag is not None | ||
# assert daily_materialised_view_dag.schedule_interval == example_dag_cron_table._expression | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# | ||
# def test_daily_materialised_view_change_timetable_from_env_variable_after_reparse(dag_bag: DagBag, | ||
# dag_materialised_view_update_schedule_variable_name: str, | ||
# daily_materialised_views_dag_id: str, | ||
# example_dag_cron_table: CronTriggerTimetable, | ||
# airflow_timetable_import_error_message: str): | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval != example_dag_cron_table._expression | ||
# | ||
# os.environ[dag_materialised_view_update_schedule_variable_name] = example_dag_cron_table._expression | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval == example_dag_cron_table._expression | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# | ||
# def test_daily_materialised_view_has_default_timetable_if_no_variable_is_set_after_reparse(dag_bag: DagBag, | ||
# dag_materialised_view_update_schedule_variable_name: str, | ||
# daily_materialised_views_dag_id: str, | ||
# airflow_timetable_import_error_message: str): | ||
# env_var_value = os.getenv(dag_materialised_view_update_schedule_variable_name) | ||
# is_env_var_set: bool = True if env_var_value is not None else False | ||
# if is_env_var_set: | ||
# del os.environ[dag_materialised_view_update_schedule_variable_name] | ||
# airflow_var_value = Variable.get(key=dag_materialised_view_update_schedule_variable_name, default_var=None) | ||
# is_airflow_var_set: bool = True if airflow_var_value is not None else False | ||
# if is_airflow_var_set: | ||
# Variable.delete(key=dag_materialised_view_update_schedule_variable_name) | ||
# | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval == DAG_MATERIALIZED_VIEW_UPDATE_DEFAULT_TIMETABLE | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# if is_env_var_set: | ||
# os.environ[dag_materialised_view_update_schedule_variable_name] = env_var_value | ||
# if is_airflow_var_set: | ||
# Variable.set(key=dag_materialised_view_update_schedule_variable_name, value=airflow_var_value) | ||
# | ||
# | ||
# def test_daily_materialised_view_gets_incorrect_timetable_after_reparse(dag_bag: DagBag, | ||
# dag_materialised_view_update_schedule_variable_name: str, | ||
# daily_materialised_views_dag_id: str, | ||
# example_wrong_cron_table: str, | ||
# airflow_timetable_import_error_message: str): | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=daily_materialised_views_dag_id) | ||
# | ||
# assert fetcher_dag is not None | ||
# | ||
# Variable.set(key=dag_materialised_view_update_schedule_variable_name, value=example_wrong_cron_table) | ||
# | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# | ||
# assert any(airflow_timetable_import_error_message in error for error in dag_bag.import_errors.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
# import os | ||
# | ||
# from airflow import DAG | ||
# from airflow.models import DagBag, Variable | ||
# from airflow.timetables.trigger import CronTriggerTimetable | ||
# | ||
# from ted_sws import DAG_FETCH_DEFAULT_TIMETABLE | ||
# | ||
# | ||
# def test_fetcher_change_timetable_from_airflow_variable_after_reparse(dag_bag: DagBag, | ||
# dag_fetch_schedule_variable_name: str, | ||
# fetcher_dag_name: str, | ||
# example_dag_cron_table: CronTriggerTimetable, | ||
# airflow_timetable_import_error_message: str): | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval != example_dag_cron_table._expression | ||
# | ||
# Variable.set(key=dag_fetch_schedule_variable_name, value=example_dag_cron_table._expression) | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval == example_dag_cron_table._expression | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# | ||
# def test_fetcher_change_timetable_from_env_variable_after_reparse(dag_bag: DagBag, | ||
# dag_fetch_schedule_variable_name: str, | ||
# fetcher_dag_name: str, | ||
# example_dag_cron_table: CronTriggerTimetable, | ||
# airflow_timetable_import_error_message: str): | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval != example_dag_cron_table._expression | ||
# | ||
# os.environ[dag_fetch_schedule_variable_name] = example_dag_cron_table._expression | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval == example_dag_cron_table._expression | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# del os.environ[dag_fetch_schedule_variable_name] | ||
# | ||
# | ||
# def test_fetcher_has_default_timetable_if_no_variable_is_set_after_reparse(dag_bag: DagBag, | ||
# dag_fetch_schedule_variable_name: str, | ||
# fetcher_dag_name: str, | ||
# airflow_timetable_import_error_message: str): | ||
# env_var_value = os.getenv(dag_fetch_schedule_variable_name) | ||
# is_env_var_set: bool = True if env_var_value is not None else False | ||
# if is_env_var_set: | ||
# del os.environ[dag_fetch_schedule_variable_name] | ||
# airflow_var_value = Variable.get(key=dag_fetch_schedule_variable_name, default_var=None) | ||
# is_airflow_var_set: bool = True if airflow_var_value is not None else False | ||
# if is_airflow_var_set: | ||
# Variable.delete(key=dag_fetch_schedule_variable_name) | ||
# | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# assert fetcher_dag.schedule_interval == DAG_FETCH_DEFAULT_TIMETABLE | ||
# assert all(airflow_timetable_import_error_message not in error for error in dag_bag.import_errors.values()) | ||
# | ||
# if is_env_var_set: | ||
# os.environ[dag_fetch_schedule_variable_name] = env_var_value | ||
# if is_airflow_var_set: | ||
# Variable.set(key=dag_fetch_schedule_variable_name, value=airflow_var_value) | ||
# | ||
# | ||
# def test_fetcher_gets_incorrect_timetable_after_reparse(dag_bag: DagBag, | ||
# dag_fetch_schedule_variable_name: str, | ||
# fetcher_dag_name: str, | ||
# example_wrong_cron_table: str, | ||
# airflow_timetable_import_error_message: str): | ||
# fetcher_dag: DAG = dag_bag.get_dag(dag_id=fetcher_dag_name) | ||
# | ||
# assert fetcher_dag is not None | ||
# | ||
# Variable.set(key=dag_fetch_schedule_variable_name, value=example_wrong_cron_table) | ||
# dag_bag.collect_dags(only_if_updated=False) | ||
# | ||
# assert any(airflow_timetable_import_error_message in error for error in dag_bag.import_errors.values()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,62 @@ | ||
# import os | ||
# | ||
# import pytest | ||
# | ||
# from airflow.models import DagBag | ||
# from airflow.utils import db | ||
# import logging | ||
|
||
from tests import TESTS_PATH | ||
|
||
AIRFLOW_DAG_FOLDER = TESTS_PATH.parent.resolve() / "dags" | ||
|
||
|
||
# @pytest.fixture(scope="session") | ||
# def dag_bag(): | ||
# os.environ["AIRFLOW_HOME"] = str(AIRFLOW_DAG_FOLDER) | ||
# os.environ["AIRFLOW__CORE__LOAD_EXAMPLES"] = "False" | ||
# # Initialising the Airflow DB so that it works properly with the new AIRFLOW_HOME | ||
# logging.disable(logging.CRITICAL) | ||
# db.resetdb() | ||
# db.initdb() | ||
# logging.disable(logging.NOTSET) | ||
# dag_bag = DagBag(dag_folder=AIRFLOW_DAG_FOLDER, include_examples=False, | ||
# read_dags_from_db=False) | ||
# return dag_bag | ||
import pytest | ||
from airflow.timetables.trigger import CronTriggerTimetable | ||
|
||
from dags.daily_materialized_views_update import DAILY_MATERIALISED_VIEWS_DAG_NAME | ||
from dags.fetch_notices_by_date import FETCHER_DAG_NAME | ||
|
||
|
||
# @pytest.fixture | ||
# def dag_bag(dag_materialised_view_update_schedule_variable_name, dag_fetch_schedule_variable_name) -> DagBag: | ||
# Variable.delete(key=dag_materialised_view_update_schedule_variable_name) | ||
# Variable.delete(key=dag_fetch_schedule_variable_name) | ||
# return DagBag( | ||
# dag_folder=AIRFLOW_DAG_FOLDER, | ||
# include_examples=False, | ||
# read_dags_from_db=False, | ||
# collect_dags=True) | ||
|
||
|
||
@pytest.fixture | ||
def fetcher_dag_name() -> str: | ||
return FETCHER_DAG_NAME | ||
|
||
|
||
@pytest.fixture | ||
def daily_materialised_views_dag_id() -> str: | ||
return DAILY_MATERIALISED_VIEWS_DAG_NAME | ||
|
||
|
||
@pytest.fixture | ||
def example_cron_table() -> str: | ||
return "15 14 1 * *" | ||
|
||
|
||
@pytest.fixture | ||
def example_wrong_cron_table() -> str: | ||
return "wrong_cron" | ||
|
||
|
||
@pytest.fixture | ||
def example_dag_cron_table(example_cron_table) -> CronTriggerTimetable: | ||
return CronTriggerTimetable(cron=example_cron_table, timezone="UTC") | ||
|
||
|
||
@pytest.fixture | ||
def airflow_timetable_import_error_message() -> str: | ||
return "FormatException" | ||
|
||
|
||
@pytest.fixture | ||
def dag_fetch_schedule_variable_name() -> str: | ||
""" | ||
According to MM of meeting with OP from 2024.12.28 | ||
""" | ||
return "SCHEDULE_DAG_FETCH" | ||
|
||
|
||
@pytest.fixture | ||
def dag_materialised_view_update_schedule_variable_name() -> str: | ||
""" | ||
According to MM of meeting with OP from 2024.12.28 | ||
""" | ||
return "SCHEDULE_DAG_MATERIALIZED_VIEW_UPDATE" |
Oops, something went wrong.