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