import requests import json from config import url_base def test_auth_basic(): body = {"Email": "a", "Password": "a"} response = requests.post(url_base() + "/api/Auth/login", json=body) data = json.loads(response.text) assert data["firstName"] == "Sajt" assert data["lastName"] == "Osperec" assert data["id"] == "asdfasdfadf" def test_auth_fail(): body = {"Email": "b", "Password": "b"} response = requests.post(url_base() + "/api/Auth/login", json=body) assert response.status_code == 401 def test_auth_register(): body = {"Email": "b", "FirstName": "a", "LastName": "a", "Password": "a", "Role": 0} response = requests.post(url_base() + "/api/Auth/register", json=body) data = json.loads(response.text) assert data["status"] == 0 def test_auth_register_bad_pass(): body = {"Email": "b", "FirstName": "a", "LastName": "a", "Password": "1", "Role": 0} response = requests.post(url_base() + "/api/Auth/register", json=body) data = json.loads(response.text) assert data["status"] == 1 assert data["body"]["reason"] == "Password does not meet complexity requirements!" def test_auth_register_email_taken(): body = {"Email": "a", "FirstName": "a", "LastName": "a", "Password": "a", "Role": 0} response = requests.post(url_base() + "/api/Auth/register", json=body) data = json.loads(response.text) assert data["status"] == 1 assert data["body"]["reason"] == "a is already registered!" def test_auth_child(): body = {"SessionId": "id", "FirstName": "a", "LastName": "a", "BirthDate": "x", "SocSecNum": "2"} response = requests.post(url_base() + "/api/Auth/child", json=body) data = json.loads(response.text) assert data["status"] == 0 assert "childID" in data["body"] def test_auth_child_ssn_taken(): body = {"SessionId": "id", "FirstName": "a", "LastName": "a", "BirthDate": "x", "SocSecNum": "111111111"} response = requests.post(url_base() + "/api/Auth/child", json=body) data = json.loads(response.text) assert data["status"] == 1 assert "SSN" in data["body"]["reason"] def test_auth_child_unauthorized(): body = {"SessionId": "a", "FirstName": "a", "LastName": "a", "BirthDate": "x", "SocSecNum": "2"} response = requests.post(url_base() + "/api/Auth/child", json=body) assert response.status_code == 401 body = {"Email": "a", "FirstName": "a", "LastName": "a", "Password": "1", "Role": 0} response = requests.post(url_base() + "/api/Auth/register", json=body) print(response.text)