aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/test_register.py40
-rw-r--r--tests/integration/test_smoke.py2
-rw-r--r--tests/unit/test_util.py16
3 files changed, 51 insertions, 7 deletions
diff --git a/tests/integration/test_register.py b/tests/integration/test_register.py
index af1e313..dc7b00a 100644
--- a/tests/integration/test_register.py
+++ b/tests/integration/test_register.py
@@ -1,19 +1,28 @@
import re
+import pytest
+
import fietsboek.email
from fietsboek import models
VERIFICATION_LINK_PATTERN = re.compile("http://example.com(/token/[A-Za-z0-9-]+)")
-def test_registration_working(testapp, dbsession, route_path, monkeypatch):
- """Ensures that a user can register, including using the verification link."""
+@pytest.fixture
+def mailcatcher(monkeypatch):
+ """Monkeypatches the send mail functionality.
+
+ Returns the list of mails sent.
+ """
mails = []
- def send_message(server_url, username, password, message):
+ def send_message(_server_url, _username, _passwords, message):
mails.append(message)
-
monkeypatch.setattr(fietsboek.email, "send_message", send_message)
+ yield mails
+
+def test_registration_working(testapp, dbsession, route_path, mailcatcher):
+ """Ensures that a user can register, including using the verification link."""
registration = testapp.get(route_path('create-account'))
form = registration.form
form['email'] = 'foo-new@bar.com'
@@ -23,18 +32,37 @@ def test_registration_working(testapp, dbsession, route_path, monkeypatch):
response = form.submit().maybe_follow()
assert b'A confirmation link has been sent' in response.body
- assert len(mails) == 1
+ assert len(mailcatcher) == 1
user = dbsession.execute(models.User.query_by_email('foo-new@bar.com')).scalar_one()
assert not user.is_verified
- body = mails[0].get_body().get_content()
+ body = mailcatcher[0].get_body().get_content()
token_path = VERIFICATION_LINK_PATTERN.search(body).group(1)
testapp.get(token_path)
assert user.is_verified
+def test_resend_verification_mail(testapp, dbsession, route_path, mailcatcher):
+ """Ensures that the verification link re-sending works."""
+ registration = testapp.get(route_path('create-account'))
+ form = registration.form
+ form['email'] = 'foo-new@bar.com'
+ form['name'] = 'The new Foo'
+ form['password'] = 'foobarpassword'
+ form['repeat-password'] = 'foobarpassword'
+ form.submit().maybe_follow()
+
+ req = testapp.get(route_path('resend-verification'))
+ req.form['email'] = 'foo-new@bar.com'
+ req.form.submit().maybe_follow()
+
+ assert len(mailcatcher) == 2
+ assert VERIFICATION_LINK_PATTERN.search(mailcatcher[0].get_body().get_content())
+ assert VERIFICATION_LINK_PATTERN.search(mailcatcher[1].get_body().get_content())
+
+
def test_registration_short_password(testapp, route_path):
"""Ensures that passwords that are too short are rejected."""
registration = testapp.get(route_path('create-account'))
diff --git a/tests/integration/test_smoke.py b/tests/integration/test_smoke.py
index 5176e88..cead68d 100644
--- a/tests/integration/test_smoke.py
+++ b/tests/integration/test_smoke.py
@@ -1,7 +1,7 @@
def test_home(testapp):
res = testapp.get("/")
assert res.status_code == 200
- assert b'<h1>Home</h1>' in res.body
+ assert b'<h1 class="float-start">Home</h1>' in res.body
def test_maintenance(testapp, data_manager):
diff --git a/tests/unit/test_util.py b/tests/unit/test_util.py
index 1a56911..6dc8e7d 100644
--- a/tests/unit/test_util.py
+++ b/tests/unit/test_util.py
@@ -88,6 +88,22 @@ def test_tour_metadata(gpx_file):
def test_mps_to_kph(mps, kph):
assert util.mps_to_kph(mps) == pytest.approx(kph, 0.1)
+@pytest.mark.parametrize('num_bytes, expected', [
+ (1, '1 B'),
+ (1023, '1023 B'),
+ (1024, '1.0 KiB'),
+ (1536, '1.5 KiB'),
+ (1024 ** 2, '1.0 MiB'),
+ (1024 ** 3, '1.0 GiB'),
+ (0, '0 B'),
+ # Negative sizes in itself are a bit weird, but they make sense as the
+ # difference between two size values, so they should still work.
+ (-1, '-1 B'),
+ (-1024, '-1.0 KiB'),
+])
+def test_human_size(num_bytes, expected):
+ assert util.human_size(num_bytes) == expected
+
def test_tile_url(app_request):
route_url = util.tile_url(app_request, "tile-proxy", provider="bobby")