from datetime import date, datetime, timedelta
import pytest

from aircox import utils


def test_redirect():
    with pytest.raises(utils.Redirect):
        utils.redirect("/redirect")


def test_str_to_date():
    result = utils.str_to_date("2023-01-10", "-")
    assert result == date(2023, 1, 10)


def test_cast_date():
    val = datetime(2023, 1, 12)
    result = utils.cast_date(val)
    assert isinstance(result, date)
    assert result == val.date()


def test_date_or_default():
    result = utils.date_or_default(None, date)
    assert isinstance(result, date)
    assert result == date.today()


def test_to_timedelta():
    val = datetime(2023, 1, 10, hour=20, minute=10, second=1)
    assert utils.to_timedelta(val) == timedelta(hours=20, minutes=10, seconds=1)


def test_to_seconds():
    val = datetime(2023, 1, 10, hour=20, minute=10, second=1)
    assert utils.to_seconds(val) == 20 * 3600 + 10 * 60 + 1


def test_seconds_to_time():
    val = 20 * 3600 + 10 * 60 + 1
    result = utils.seconds_to_time(val)
    assert (result.hour, result.minute, result.second) == (20, 10, 1)
