599ce0de54
data/interfaces/appr.py endpoints/appr/cnr_backend.py endpoints/appr/registry.py endpoints/appr/test/test_api.py endpoints/appr/test/test_registry.py
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import json
|
|
|
|
from flask import url_for
|
|
import pytest
|
|
|
|
from data import model
|
|
from endpoints.appr.registry import appr_bp
|
|
from test.fixtures import app, appconfig, database_uri, init_db_path, sqlitedb_file
|
|
|
|
|
|
@pytest.mark.parametrize('login_data, expected_code', [
|
|
({
|
|
"username": "devtable",
|
|
"password": "password"
|
|
}, 200),
|
|
({
|
|
"username": "devtable",
|
|
"password": "badpass"
|
|
}, 401),
|
|
({
|
|
"username": "devtable+dtrobot",
|
|
"password": "badpass"
|
|
}, 401),
|
|
({
|
|
"username": "devtable+dtrobot2",
|
|
"password": None
|
|
}, 200),
|
|
])
|
|
def test_login(login_data, expected_code, app, client):
|
|
if "+" in login_data['username'] and login_data['password'] is None:
|
|
username, robotname = login_data['username'].split("+")
|
|
_, login_data['password'] = model.user.create_robot(robotname, model.user.get_user(username))
|
|
app.register_blueprint(appr_bp, url_prefix='/cnr')
|
|
url = url_for('appr.login')
|
|
headers = {'Content-Type': 'application/json'}
|
|
data = {'user': login_data}
|
|
|
|
rv = client.open(url, method='POST', data=json.dumps(data), headers=headers)
|
|
assert rv.status_code == expected_code
|