aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_functional.py13
-rw-r--r--tests/test_views.py23
-rw-r--r--tests/unit/test_util.py57
3 files changed, 57 insertions, 36 deletions
diff --git a/tests/test_functional.py b/tests/test_functional.py
deleted file mode 100644
index 6102063..0000000
--- a/tests/test_functional.py
+++ /dev/null
@@ -1,13 +0,0 @@
-from fietsboek import models
-
-def test_my_view_success(testapp, dbsession):
- model = models.MyModel(name='one', value=55)
- dbsession.add(model)
- dbsession.flush()
-
- res = testapp.get('/', status=200)
- assert res.body
-
-def test_notfound(testapp):
- res = testapp.get('/badurl', status=404)
- assert res.status_code == 404
diff --git a/tests/test_views.py b/tests/test_views.py
deleted file mode 100644
index 08347b6..0000000
--- a/tests/test_views.py
+++ /dev/null
@@ -1,23 +0,0 @@
-from fietsboek import models
-from fietsboek.views.default import my_view
-from fietsboek.views.notfound import notfound_view
-
-
-def test_my_view_failure(app_request):
- info = my_view(app_request)
- assert info.status_int == 500
-
-def test_my_view_success(app_request, dbsession):
- model = models.MyModel(name='one', value=55)
- dbsession.add(model)
- dbsession.flush()
-
- info = my_view(app_request)
- assert app_request.response.status_int == 200
- assert info['one'].name == 'one'
- assert info['project'] == 'fietsboek'
-
-def test_notfound_view(app_request):
- info = notfound_view(app_request)
- assert app_request.response.status_int == 404
- assert info == {}
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)