aboutsummaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-07 12:31:49 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-07 12:31:49 +0200
commitaebf11a0cf6141f287fcbe40fbb094eeb702ec2a (patch)
tree39b8035bb825657cd90fb00c3a72e949cb6022ba /tests/unit
parent2cf5859a0bdb8771a73cd8fd65a45da5503cf184 (diff)
downloadfietsboek-aebf11a0cf6141f287fcbe40fbb094eeb702ec2a.tar.gz
fietsboek-aebf11a0cf6141f287fcbe40fbb094eeb702ec2a.tar.bz2
fietsboek-aebf11a0cf6141f287fcbe40fbb094eeb702ec2a.zip
start adding some unit tests
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/test_util.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py
new file mode 100644
index 0000000..c595e4e
--- /dev/null
+++ b/tests/unit/test_util.py
@@ -0,0 +1,57 @@
+from datetime import timedelta
+
+import pytest
+from markupsafe import Markup
+
+from fietsboek import util
+
+
+@pytest.mark.parametrize('md_source, expected', [
+ ("**foobar**", Markup("<p><strong>foobar</strong></p>")),
+ ("*foobar*", Markup("<p><em>foobar</em></p>")),
+ ("# foobar", Markup("<h1>foobar</h1>")),
+ ("<script>alert('evil')</script>",
+ Markup("&lt;script&gt;alert('evil')&lt;/script&gt;")),
+])
+def test_safe_markdown(md_source, expected):
+ assert util.safe_markdown(md_source) == expected
+
+
+@pytest.mark.parametrize('timestamp, fixed', [
+ ("2022-03-14T13:37:42", "2022-03-14T13:37:42"),
+ ("2022-03-14T13:37:42Z", "2022-03-14T13:37:42+00:00"),
+ ("2022-03-14T13:37:42+02:00", "2022-03-14T13:37:42+02:00"),
+])
+def test_fix_iso_timestamp(timestamp, fixed):
+ assert util.fix_iso_timestamp(timestamp) == fixed
+
+
+@pytest.mark.parametrize('delta, multiple, expected', [
+ (
+ timedelta(minutes=42),
+ timedelta(minutes=15),
+ timedelta(minutes=45),
+ ),
+ (
+ timedelta(minutes=33),
+ timedelta(minutes=15),
+ timedelta(minutes=30),
+ ),
+ (
+ timedelta(minutes=-12),
+ timedelta(minutes=15),
+ timedelta(minutes=-15),
+ ),
+ (
+ timedelta(minutes=-31),
+ timedelta(minutes=15),
+ timedelta(minutes=-30),
+ ),
+])
+def test_round_timedelta_to_multiple(delta, multiple, expected):
+ assert util.round_timedelta_to_multiple(delta, multiple) == expected
+
+
+@pytest.mark.parametrize('mps, kph', [(1, 3.6), (10, 36)])
+def test_mps_to_kph(mps, kph):
+ assert util.mps_to_kph(mps) == pytest.approx(kph, 0.1)