From c329196c52cb4b11cac4f6c5f8af15b2d533056a Mon Sep 17 00:00:00 2001 From: Sakan Nirattisaykul <94357278+sakan811@users.noreply.github.com> Date: Thu, 12 Dec 2024 19:32:20 +0700 Subject: [PATCH] test: fix tests --- .../test_scrape_missing_dates.py | 20 +++++++++---------- .../test_whole_month_graphql_scraper.py | 7 ++++--- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/test_missing_date_checker/test_scrape_missing_dates.py b/tests/test_missing_date_checker/test_scrape_missing_dates.py index be9c1a4..57ef49f 100644 --- a/tests/test_missing_date_checker/test_scrape_missing_dates.py +++ b/tests/test_missing_date_checker/test_scrape_missing_dates.py @@ -1,4 +1,5 @@ import datetime +import pytz import pytest from sqlalchemy import func, create_engine @@ -20,20 +21,17 @@ async def test_scrape_missing_dates(tmp_path) -> None: booking_details_param = BookingDetails(city='Osaka', group_adults=1, num_rooms=1, group_children=0, selected_currency='USD', scrape_only_hotel=True) - today = datetime.datetime.today() - if today.month == 12: - month = 1 - year = today.year + 1 - else: - month = today.month + 1 - year = today.year + today = datetime.datetime.now(pytz.UTC) + next_month = (today.replace(day=1) + datetime.timedelta(days=32)).replace(day=1) + year, month = next_month.year, next_month.month month_str = str(month).zfill(2) - first_missing_date = f'{year}-{month_str}-01' - second_missing_date = f'{year}-{month_str}-11' - third_missing_date = f'{year}-{month_str}-20' - missing_dates = [first_missing_date, second_missing_date, third_missing_date] + missing_dates = [ + f'{year}-{month_str}-01', + f'{year}-{month_str}-11', + f'{year}-{month_str}-20' + ] await scrape_missing_dates(missing_dates_list=missing_dates, booking_details_class=booking_details_param, engine=engine) diff --git a/tests/test_whole_mth_scraper/test_whole_month_graphql_scraper.py b/tests/test_whole_mth_scraper/test_whole_month_graphql_scraper.py index ee012cc..71d06c8 100644 --- a/tests/test_whole_mth_scraper/test_whole_month_graphql_scraper.py +++ b/tests/test_whole_mth_scraper/test_whole_month_graphql_scraper.py @@ -1,4 +1,5 @@ import datetime +import pytz import pytest @@ -7,7 +8,7 @@ @pytest.mark.asyncio async def test_whole_month_graphql_scraper(): - today = datetime.datetime.now() + today = datetime.datetime.now(pytz.UTC) current_mth = today.month current_year = today.year @@ -24,7 +25,7 @@ async def test_whole_month_graphql_scraper(): @pytest.mark.asyncio async def test_whole_month_graphql_scraper_past_date(): - today = datetime.datetime.now() + today = datetime.datetime.now(pytz.UTC) past_mth = today.month - 1 current_year = today.year @@ -34,4 +35,4 @@ async def test_whole_month_graphql_scraper_past_date(): country='Japan') df = await scraper.scrape_whole_month() - assert df.empty + assert df.empty \ No newline at end of file