summaryrefslogtreecommitdiff
path: root/tests/test_auth.py
diff options
context:
space:
mode:
authorTom Harley2021-07-03 00:18:13 +0000
committerTom Harley2021-07-03 00:18:13 +0000
commit7c5c6c52250ca57257ab4af2cc9cdf4425595ec0 (patch)
treed36019286125bf984e0c267645d53ff562533ebf /tests/test_auth.py
downloadswap-7c5c6c52250ca57257ab4af2cc9cdf4425595ec0.tar.gz
swap-7c5c6c52250ca57257ab4af2cc9cdf4425595ec0.zip

Initial commit

Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
new file mode 100644
index 0000000..3fb2493
--- /dev/null
+++ b/tests/test_auth.py
@@ -0,0 +1,40 @@
+import pytest
+
+from flask import g, session, json
+
+from sw.db import get_db
+
+
+def test_register(client, app):
+ response = client.post(
+ "/auth/register",
+ data=json.dumps({"username": "a", "password": "a",}),
+ content_type="application/json",
+ )
+
+ # TODO assert "/u/a" in response.headers["Location"]
+
+ with app.app_context():
+ db_result = (
+ get_db().execute("select * from user where username='a'",).fetchone()
+ )
+ assert db_result is not None
+
+
+@pytest.mark.parametrize(
+ ("username", "password", "message"),
+ (
+ (None, "", b"Username required"),
+ ("", "", b"Username must not be empty"),
+ ("a", None, b"Password required"),
+ ("a", "", b"Password must not be empty"),
+ ("test", "test", b"Username test is taken"),
+ ),
+)
+def test_register_validate_input(client, username, password, message):
+ response = client.post(
+ "/auth/register",
+ data=json.dumps({"username": username, "password": password,}),
+ content_type="application/json",
+ )
+ assert message in response.data