From 1e5adcc71955fc92b99777ad2780296a06477b02 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Tue, 6 Dec 2022 20:52:28 +0100 Subject: add some tests for the registration form --- tests/integration/test_register.py | 68 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/integration/test_register.py (limited to 'tests/integration') diff --git a/tests/integration/test_register.py b/tests/integration/test_register.py new file mode 100644 index 0000000..af1e313 --- /dev/null +++ b/tests/integration/test_register.py @@ -0,0 +1,68 @@ +import re + +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.""" + mails = [] + def send_message(server_url, username, password, message): + mails.append(message) + + monkeypatch.setattr(fietsboek.email, "send_message", send_message) + + 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' + response = form.submit().maybe_follow() + + assert b'A confirmation link has been sent' in response.body + assert len(mails) == 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() + token_path = VERIFICATION_LINK_PATTERN.search(body).group(1) + testapp.get(token_path) + + assert user.is_verified + + +def test_registration_short_password(testapp, route_path): + """Ensures that passwords that are too short are rejected.""" + registration = testapp.get(route_path('create-account')) + form = registration.form + form['email'] = 'foo-new@bar.com' + form['name'] = 'The new Foo' + form['password'] = 'foo' + form['repeat-password'] = 'foo' + response = form.submit().maybe_follow() + + assert re.search( + b'', + response.body, + ) + + +def test_registration_password_mismatch(testapp, route_path): + """Ensures that passwords that do not match are rejected.""" + registration = testapp.get(route_path('create-account')) + form = registration.form + form['email'] = 'foo-new@bar.com' + form['name'] = 'The new Foo' + form['password'] = 'foobarfoobar' + form['repeat-password'] = 'foobarfoo' + response = form.submit().maybe_follow() + + assert re.search( + b'', + response.body, + ) -- cgit v1.2.3