summaryrefslogtreecommitdiff
path: root/tests/test_auth.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_auth.py')
-rw-r--r--tests/test_auth.py32
1 files changed, 17 insertions, 15 deletions
diff --git a/tests/test_auth.py b/tests/test_auth.py
index c96d14f..96dd959 100644
--- a/tests/test_auth.py
+++ b/tests/test_auth.py
@@ -1,6 +1,6 @@
import pytest
-from flask import g, session, json, url_for, request
+from flask import g, json, url_for, request
from sw.db import get_db
from sw.auth import login_required, specific_user_required, json_input
@@ -24,15 +24,6 @@ def test_register(client, app):
assert db_result is not None
-def test_login_right_credentials(client, auth):
- assert auth.login().status_code == 200
-
- with client:
- client.get("/")
- assert session["user_id"] == 1
- assert g.user["username"] == "test"
-
-
@pytest.mark.parametrize(
("username", "password", "message"),
(
@@ -46,12 +37,26 @@ def test_login_right_credentials(client, auth):
def test_register_validate_input(client, username, password, message):
response = client.post(
"/auth/register",
- data=json.dumps({"username": username, "password": password,}),
+ data=json.dumps({"username": username, "password": password}),
headers={"Content-Type": "application/json"},
)
assert message in response.data
+@pytest.mark.parametrize(
+ ("username", "password", "expected_status_code"),
+ (
+ ("test", "test", 200),
+ ("test", "other", 403),
+ ("test", None, 403),
+ (None, "test", 403),
+ ),
+)
+def test_login(client, username, auth, password, expected_status_code):
+ response = auth.login(username=username, password=password)
+ assert response.status_code == expected_status_code
+
+
def test_login_required_no_user(client, app):
test_endpoint = "/test/dummy_endpoint"
@@ -63,7 +68,6 @@ def test_login_required_no_user(client, app):
response = client.get(test_endpoint)
assert response.status_code == 403
- assert b"Should be unreachable" not in response.data
def test_login_required_with_user(client, app, auth):
@@ -149,9 +153,7 @@ def test_specific_user_required_right_user(client, app, auth):
('{ "valid": "JSON"}', "application/ld+json", 201),
),
)
-def test_json_input_empty_input(
- client, app, input_data, content_type, expected_response
-):
+def test_json_input(client, app, input_data, content_type, expected_response):
test_endpoint = "/test/dummy_endpoint"
@app.route(test_endpoint, methods=["POST"])