diff options
author | Daniel Schadt <kingdread@gmx.de> | 2022-12-06 20:52:28 +0100 |
---|---|---|
committer | Daniel Schadt <kingdread@gmx.de> | 2022-12-06 20:52:28 +0100 |
commit | 1e5adcc71955fc92b99777ad2780296a06477b02 (patch) | |
tree | af4ac8397e71ae940a823cbc791ebd44f4687aaa /tests | |
parent | 762afb76e972787ab6b547f69a629b8bfb5f7611 (diff) | |
download | fietsboek-1e5adcc71955fc92b99777ad2780296a06477b02.tar.gz fietsboek-1e5adcc71955fc92b99777ad2780296a06477b02.tar.bz2 fietsboek-1e5adcc71955fc92b99777ad2780296a06477b02.zip |
add some tests for the registration form
Diffstat (limited to 'tests')
-rw-r--r-- | tests/__init__.py | 0 | ||||
-rw-r--r-- | tests/integration/test_register.py | 68 |
2 files changed, 68 insertions, 0 deletions
diff --git a/tests/__init__.py b/tests/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/tests/__init__.py +++ /dev/null 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'<div class="alert alert-primary" role="alert">\\s*Password not long enough\\s*</div>', + 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'<div class="alert alert-primary" role="alert">\\s*' + b'Passwords don't match\\s*</div>', + response.body, + ) |