aboutsummaryrefslogtreecommitdiff
path: root/src/tests/test_api.py
blob: 063f32fe6f44456884ddc6dbba39c3170906bdb5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import pytest, re

from flask import session
from bson.json_util import dumps

from pprint import pprint

def test_api_get_all_users(client, app):
    response = client.get('/api/users')
    assert response.status_code == 200
    assert response.is_json
    assert re.search('username', str(response.data))

@pytest.mark.parametrize(('username', 'message'), (
    ('', b'{"msg": "Username is required."}'),
    ('neo', b'{"msg": "User neo is already registered."}'),
    ('neodarz', b'{"msg": "done"}')
))
def test_api_register(client, app, username, message):
    response = client.post('/api/user/register', data='{"username": "'+username+'"}')
    print(response.data)
    assert message in response.data