aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Schadt <kingdread@gmx.de>2022-07-09 19:30:18 +0200
committerDaniel Schadt <kingdread@gmx.de>2022-07-09 19:30:18 +0200
commit8cdf665c0c8c83abf6bf3ccdc4c594e039e59107 (patch)
treeb60234bc0d10aadc44fa1d743131a5e4869a30b2
parentcd9d1b1c31cfce7ffb2563fca1bea5907d575eee (diff)
downloadfietsboek-8cdf665c0c8c83abf6bf3ccdc4c594e039e59107.tar.gz
fietsboek-8cdf665c0c8c83abf6bf3ccdc4c594e039e59107.tar.bz2
fietsboek-8cdf665c0c8c83abf6bf3ccdc4c594e039e59107.zip
add tests for the login form
-rw-r--r--testing.ini2
-rw-r--r--tests/integration/test_login.py65
-rw-r--r--tests/integration/test_smoke.py4
3 files changed, 71 insertions, 0 deletions
diff --git a/testing.ini b/testing.ini
index 65980f4..9fad722 100644
--- a/testing.ini
+++ b/testing.ini
@@ -14,6 +14,8 @@ pyramid.default_locale_name = en
sqlalchemy.url = sqlite:///%(here)s/testing.sqlite
+session_key = TESTING_KEY_DO_NOT_USE
+
retry.attempts = 3
[pshell]
diff --git a/tests/integration/test_login.py b/tests/integration/test_login.py
new file mode 100644
index 0000000..8be77d7
--- /dev/null
+++ b/tests/integration/test_login.py
@@ -0,0 +1,65 @@
+import pytest
+
+from fietsboek import models
+
+
+@pytest.fixture()
+def testuser(dbsession):
+ user = models.User(email='foo@bar.com')
+ user.set_password("foobar")
+ dbsession.add(user)
+ return user
+
+
+def test_login_working(testapp, testuser):
+ """Ensures that a verified user can log in with the right password."""
+ testuser.is_verified = True
+
+ login = testapp.get('/login')
+ form = login.form
+ form['email'] = 'foo@bar.com'
+ form['password'] = 'foobar'
+ response = form.submit().maybe_follow()
+
+ assert b'Logout' in response.body
+
+
+def test_login_not_verified(testapp, testuser):
+ """Ensures that a user that has not yet verified their email address can
+ not log in.
+ """
+ login = testapp.get('/login')
+ form = login.form
+ form['email'] = 'foo@bar.com'
+ form['password'] = 'foobar'
+ response = form.submit().maybe_follow()
+
+ assert b'Logout' not in response.body
+ assert b'not verified yet' in response.body
+
+
+def test_login_wrong_email(testapp, testuser):
+ """Ensures that a wrong email address won't let you log in."""
+ login = testapp.get('/login')
+
+ form = login.form
+ form['email'] = 'fooooooooo@bar.com'
+ form['password'] = 'foobar'
+ response = form.submit().maybe_follow()
+
+ assert b'Logout' not in response.body
+ assert b'Invalid login credentials' in response.body
+
+
+def test_login_wrong_password(testapp, testuser):
+ """Ensures that a wrong password won't let you log in."""
+ testuser.is_verified = True
+
+ login = testapp.get('/login')
+ form = login.form
+ form['email'] = 'foo@bar.com'
+ form['password'] = 'raboof'
+ response = form.submit().maybe_follow()
+
+ assert b'Logout' not in response.body
+ assert b'Invalid login credentials' in response.body
diff --git a/tests/integration/test_smoke.py b/tests/integration/test_smoke.py
new file mode 100644
index 0000000..1288da0
--- /dev/null
+++ b/tests/integration/test_smoke.py
@@ -0,0 +1,4 @@
+def test_home(testapp):
+ res = testapp.get("/")
+ assert res.status_code == 200
+ assert b'<h1>Home</h1>' in res.body