aircox/aircox/tests/test_converters.py
Thomas Kairos 2ce435fb5d !112 !94: tests commons modules that contains most of the logic + zoneinfo (#113)
!112

Co-authored-by: bkfox <thomas bkfox net>
Reviewed-on: #113
2023-08-23 15:28:17 +02:00

55 lines
1.3 KiB
Python

from datetime import date
from django.utils.safestring import SafeString
import pytest
from aircox import converters
@pytest.fixture
def page_path_conv():
return converters.PagePathConverter()
@pytest.fixture
def week_conv():
return converters.WeekConverter()
@pytest.fixture
def date_conv():
return converters.DateConverter()
class TestPagePathConverter:
def test_to_python(self, page_path_conv):
val = "path_value"
result = page_path_conv.to_python(val)
assert result == "/" + val + "/"
def test_to_url(self, page_path_conv):
val = "/val"
result = page_path_conv.to_url(val)
assert isinstance(result, SafeString)
assert result == val[1:] + "/"
class TestWeekConverter:
def test_to_python(self, week_conv):
val = "2023/02"
assert week_conv.to_python(val) == date(2023, 1, 9)
def test_to_url(self, week_conv):
val = date(2023, 1, 10)
assert week_conv.to_url(val) == "2023/02"
class TestDateConverter:
def test_to_python(self, date_conv):
val = "2023/02/05"
assert date_conv.to_python(val) == date(2023, 2, 5)
def test_to_url(self, date_conv):
val = date(2023, 5, 10)
assert date_conv.to_url(val) == "2023/05/10"