Skip to content

Commit

Permalink
Adding timeout to the api request
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamclaughlin authored Apr 27, 2024
1 parent be697e4 commit ce9d6e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/integrations/google_workspace/google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def get_federal_holidays():

# call the api to get the public holidays
url = f"https://canada-holidays.ca/api/v1/holidays?federal=true&year={year}"
response = requests.get(url)
response = requests.get(url, timeout=10)

# Store the observed dates of the holidays and return the list
holidays = []
Expand Down
13 changes: 12 additions & 1 deletion app/tests/integrations/google_workspace/test_google_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,9 @@ def test_no_available_slots_within_search_limit(

# test that the federal holidays are correctly parsed
def test_get_federal_holidays(requests_mock):
# set the timeout to 10s
requests_mock.DEFAULT_TIMEOUT = 10

# Mock the API response
mocked_response = {
"holidays": [
Expand All @@ -513,6 +516,9 @@ def test_get_federal_holidays(requests_mock):

# test that holidays are correctly fetched for a different year
def test_get_federal_holidays_with_different_year(requests_mock):
# set the timeout to 10s
requests_mock.DEFAULT_TIMEOUT = 10

# Mock the API response for a different year
requests_mock.get(
"https://canada-holidays.ca/api/v1/holidays?federal=true&year=2025",
Expand All @@ -534,6 +540,9 @@ def test_get_federal_holidays_with_different_year(requests_mock):

# Test that an empty list is returned when there are no holidays
def test_api_returns_empty_list(requests_mock):
# set the timeout to 10s
requests_mock.DEFAULT_TIMEOUT = 10

# Mock no holidays
requests_mock.get(
"https://canada-holidays.ca/api/v1/holidays?federal=true&year=2024",
Expand All @@ -549,6 +558,8 @@ def test_api_returns_empty_list(requests_mock):

# Test that a leap year is correctly handled
def test_leap_year_handling(requests_mock):
# set the timeout to 10s
requests_mock.DEFAULT_TIMEOUT = 10
# Mock response for a leap year with an extra day
requests_mock.get(
"https://canada-holidays.ca/api/v1/holidays?federal=true&year=2024",
Expand All @@ -558,7 +569,7 @@ def test_leap_year_handling(requests_mock):
"observedDate": "2024-02-29"
} # Assuming this is a special leap year holiday
]
},
}
)

# Execute
Expand Down

0 comments on commit ce9d6e7

Please sign in to comment.