From d869ce549049e408ccef128dbd56e50b8fd3fe92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gyulai=20D=C3=A1niel?= Date: Wed, 4 Nov 2020 07:29:32 -0500 Subject: [PATCH] Added python based tests --- tests/test_auth.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ tests/test_case.py | 50 ++++++++++++++++++++++++++++++++++++++ tests/test_doc.py | 31 ++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100644 tests/test_auth.py create mode 100644 tests/test_case.py create mode 100644 tests/test_doc.py diff --git a/tests/test_auth.py b/tests/test_auth.py new file mode 100644 index 0000000..ab9ce59 --- /dev/null +++ b/tests/test_auth.py @@ -0,0 +1,60 @@ +import requests +import json + +url_base = "http://localhost:56030" + +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) diff --git a/tests/test_case.py b/tests/test_case.py new file mode 100644 index 0000000..a7a8f2a --- /dev/null +++ b/tests/test_case.py @@ -0,0 +1,50 @@ +import requests +import json + +url_base = "http://localhost:56030" + +def test_case_basic(): + case_id = "1f4g5" + body = {"SessionID": "a"} + response = requests.post(url_base + "/api/Case/"+case_id, json=body) + data = json.loads(response.text) + print(data) + assert data["id"] == case_id + +def test_case_unauthorized(): + case_id = "1f4g5" + body = {"SessionID": "b"} + response = requests.post(url_base + "/api/Case/"+case_id, json=body) + assert response.status_code == 401 + +def test_case_update(): + case_id = "5f6h4" + body = {"CaseID": case_id, "UpdateMsg": "a", "SessionID": "a"} + response = requests.put(url_base + "/api/Case/"+case_id+"/update", json=body) + assert response.status_code == 200 + +def test_case_update_unauthorized(): + case_id = "5f6h4" + body = {"CaseID": case_id, "UpdateMsg": "a", "SessionID": "b"} + response = requests.put(url_base + "/api/Case/"+case_id+"/update", json=body) + assert response.status_code == 401 + +def test_case_close(): + case_id = "5f6h4" + body = {"CaseID": case_id, "UpdateMsg": "a", "SessionID": "a"} + response = requests.put(url_base + "/api/Case/"+case_id+"/close", json=body) + assert response.status_code == 200 + +def test_case_close_unauthorized(): + case_id = "5f6h4" + body = {"CaseID": case_id, "UpdateMsg": "a", "SessionID": "b"} + response = requests.put(url_base + "/api/Case/"+case_id+"/close", json=body) + assert response.status_code == 401 + +def test_case_filter(): + parent_id = "34g5g53" + body = {"SessionID": "a", "Filters": {"ParentID": parent_id}} + response = requests.post(url_base + "/api/Case/filter", json=body) + data = json.loads(response.text) + for i in data["cases"]: + assert i["parentID"] == parent_id diff --git a/tests/test_doc.py b/tests/test_doc.py new file mode 100644 index 0000000..0c0d3f1 --- /dev/null +++ b/tests/test_doc.py @@ -0,0 +1,31 @@ +import requests +import json + +url_base = "http://localhost:56030" + +def test_doc_get(): + response = requests.get(url_base + "/api/Doc") + data = json.loads(response.text) + assert data["status"] == 0 + for val in data["body"].values(): + assert "firstName" in val + +def test_doc_assistants(): + doc_id = "a23f" + response = requests.get(url_base + "/api/Doc/" + doc_id + "/assistants") + data = json.loads(response.text) + assert data["status"] == 0 + for key, val in data["body"].items(): + assert key == "doctorID" or "firstName" in val + if key == "doctorID": + assert val == doc_id + +def test_doc_children(): + doc_id = "a23f" + response = requests.get(url_base + "/api/Doc/" + doc_id + "/children") + data = json.loads(response.text) + assert data["status"] == 0 + for key, val in data["body"].items(): + assert key == "doctorID" or "firstName" in val + if key == "doctorID": + assert val == doc_id