Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hussein-awala committed Aug 19, 2023
1 parent 88d0ba5 commit 0302e02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
22 changes: 12 additions & 10 deletions tests/www/views/test_views_extra_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from __future__ import annotations

import json
import urllib.parse
from unittest import mock

import pytest
Expand All @@ -30,7 +31,8 @@
from tests.test_utils.db import clear_db_runs
from tests.test_utils.mock_operators import AirflowLink, Dummy2TestOperator, Dummy3TestOperator

DEFAULT_DATE = timezone.datetime(2017, 1, 1)
DEFAULT_DATE = timezone.datetime(2017, 1, 1, tzinfo=timezone.utc)
STR_DEFAULT_DATE = urllib.parse.quote(DEFAULT_DATE.strftime("%Y-%m-%dT%H:%M:%S.%f%z"))

ENDPOINT = "extra_links"

Expand Down Expand Up @@ -129,7 +131,7 @@ def reset_task_instances():
def test_extra_links_works(dag_run, task_1, viewer_client, session):
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_1.dag_id}&task_id={task_1.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=foo-bar",
f"&execution_date={STR_DEFAULT_DATE}&link_name=foo-bar",
follow_redirects=True,
)

Expand All @@ -143,7 +145,7 @@ def test_extra_links_works(dag_run, task_1, viewer_client, session):
def test_global_extra_links_works(dag_run, task_1, viewer_client, session):
response = viewer_client.get(
f"{ENDPOINT}?dag_id={dag_run.dag_id}&task_id={task_1.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=github",
f"&execution_date={STR_DEFAULT_DATE}&link_name=github",
follow_redirects=True,
)

Expand All @@ -157,7 +159,7 @@ def test_global_extra_links_works(dag_run, task_1, viewer_client, session):
def test_operator_extra_link_override_global_extra_link(dag_run, task_1, viewer_client):
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_1.dag_id}&task_id={task_1.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=airflow",
f"&execution_date={STR_DEFAULT_DATE}&link_name=airflow",
follow_redirects=True,
)

Expand All @@ -171,7 +173,7 @@ def test_operator_extra_link_override_global_extra_link(dag_run, task_1, viewer_
def test_extra_links_error_raised(dag_run, task_1, viewer_client):
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_1.dag_id}&task_id={task_1.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=raise_error",
f"&execution_date={STR_DEFAULT_DATE}&link_name=raise_error",
follow_redirects=True,
)

Expand All @@ -185,7 +187,7 @@ def test_extra_links_error_raised(dag_run, task_1, viewer_client):
def test_extra_links_no_response(dag_run, task_1, viewer_client):
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_1.dag_id}&task_id={task_1.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=no_response",
f"&execution_date={STR_DEFAULT_DATE}&link_name=no_response",
follow_redirects=True,
)

Expand All @@ -206,7 +208,7 @@ def test_operator_extra_link_override_plugin(dag_run, task_2, viewer_client):
"""
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_2.dag_id}&task_id={task_2.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=airflow",
f"&execution_date={STR_DEFAULT_DATE}&link_name=airflow",
follow_redirects=True,
)

Expand All @@ -228,7 +230,7 @@ def test_operator_extra_link_multiple_operators(dag_run, task_2, task_3, viewer_
"""
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_2.dag_id}&task_id={task_2.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=airflow",
f"&execution_date={STR_DEFAULT_DATE}&link_name=airflow",
follow_redirects=True,
)

Expand All @@ -240,7 +242,7 @@ def test_operator_extra_link_multiple_operators(dag_run, task_2, task_3, viewer_

response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_3.dag_id}&task_id={task_3.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=airflow",
f"&execution_date={STR_DEFAULT_DATE}&link_name=airflow",
follow_redirects=True,
)

Expand All @@ -253,7 +255,7 @@ def test_operator_extra_link_multiple_operators(dag_run, task_2, task_3, viewer_
# Also check that the other Operator Link defined for this operator exists
response = viewer_client.get(
f"{ENDPOINT}?dag_id={task_3.dag_id}&task_id={task_3.task_id}"
f"&execution_date={DEFAULT_DATE}&link_name=google",
f"&execution_date={STR_DEFAULT_DATE}&link_name=google",
follow_redirects=True,
)

Expand Down
3 changes: 2 additions & 1 deletion tests/www/views/test_views_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@
DAG_ID_REMOVED = "removed_dag_for_testing_log_view"
TASK_ID = "task_for_testing_log_view"
DEFAULT_DATE = timezone.datetime(2017, 9, 1)
ENDPOINT = f"log?dag_id={DAG_ID}&task_id={TASK_ID}&execution_date={DEFAULT_DATE}"
STR_DEFAULT_DATE = urllib.parse.quote(DEFAULT_DATE.strftime("%Y-%m-%dT%H:%M:%S.%f%z"))
ENDPOINT = f"log?dag_id={DAG_ID}&task_id={TASK_ID}&execution_date={STR_DEFAULT_DATE}"


@pytest.fixture(scope="module", autouse=True)
Expand Down

0 comments on commit 0302e02

Please sign in to comment.