oncall-engine/engine/common/tests/test_timezones.py
Joey Orlando 74b919ee3e
shift swap requests model + CRUD endpoints (#2597)
# What this PR does

This PR should allow us to start working on _most_ of the remaining
tasks for this feature set.
- Adds a basic `ShiftSwapRequest` model + CRUD endpoints. 
- Adds a `POST /api/internal/v1/shift_swaps/<id>/take` endpoint which
allows a benefactor to take a request (only when certain conditions
about the ssr are met)

Closes #2587 

## Checklist

- [x] Unit, integration, and e2e (if applicable) tests updated
- [x] Documentation added (or `pr:no public docs` PR label added if not
required) will be done in #2589
- [x] `CHANGELOG.md` updated (or `pr:no changelog` PR label added if not
required) (will update once we ship the finalized feature set)
2023-07-21 19:35:19 +00:00

43 lines
1.2 KiB
Python

import pytest
import pytz
from rest_framework.exceptions import APIException
import common.timezones as tz
from common.api_helpers.exceptions import BadRequest
@pytest.mark.parametrize(
"input,expected",
[
("UTC", pytz.timezone("UTC")),
("asdfasdfasdf", False),
],
)
def test_is_valid_timezone(input, expected):
assert tz.is_valid_timezone(input) == expected
@pytest.mark.parametrize(
"input,raises_exception",
[
("UTC", False),
("asdfasdfasdf", True),
],
)
def test_raise_exception_if_not_valid_timezone(input, raises_exception):
if raises_exception:
with pytest.raises(BadRequest, match="Invalid timezone"):
tz.raise_exception_if_not_valid_timezone(input)
else:
try:
tz.raise_exception_if_not_valid_timezone(input)
except Exception:
pytest.fail()
def test_raise_exception_if_not_valid_timezone_custom_exception():
class MyCustomException(APIException):
"asdfasdf"
with pytest.raises(MyCustomException, match="Invalid timezone"):
tz.raise_exception_if_not_valid_timezone("asdfasfd", exception_class=MyCustomException)