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'