summaryrefslogtreecommitdiff
path: root/tests/test_auth.py
blob: 3fb2493a56228be3cbe8d8184280e7c3c53c56ad (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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