diff --git a/endpoints/Question/__init__.py b/endpoints/Question/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/endpoints/Question/alternatives.py b/endpoints/Question/alternatives.py new file mode 100644 index 0000000..daf6286 --- /dev/null +++ b/endpoints/Question/alternatives.py @@ -0,0 +1,13 @@ +import requests + + +class Alternatives: + + def __init__(self): + self.url = "http://127.0.0.1:8000/alternatives" + self.headers = {"accept": "application/json"} + + def get_alternatives(self, question_id: int): + url = f"{self.url}/{question_id}" + response = requests.get(url, headers=self.headers) + return response diff --git a/endpoints/Question/question.py b/endpoints/Question/question.py new file mode 100644 index 0000000..4c83395 --- /dev/null +++ b/endpoints/Question/question.py @@ -0,0 +1,13 @@ +import requests + + +class Question: + + def __init__(self): + self.url = "http://127.0.0.1:8000/question" + self.headers = {"accept": "application/json"} + + def get_question(self, position: int): + url = f"{self.url}/{position}" + response = requests.get(url, headers=self.headers) + return response diff --git a/endpoints/User/__init__.py b/endpoints/User/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/endpoints/User/users.py b/endpoints/User/users.py new file mode 100644 index 0000000..758fa9c --- /dev/null +++ b/endpoints/User/users.py @@ -0,0 +1,12 @@ +import requests + + +class User: + + def __init__(self): + self.url = "http://127.0.0.1:8000/user" + self.headers = {"accept": "application/json"} + + def get_user(self): + response = requests.get(self.url, headers=self.headers) + return response diff --git a/endpoints/get_root.py b/endpoints/get_root.py new file mode 100644 index 0000000..0bd7108 --- /dev/null +++ b/endpoints/get_root.py @@ -0,0 +1,9 @@ +import requests + +URL = "http://127.0.0.1:8000/" +headers = {"accept": "application/json"} + + +def get_root(params: dict = None): + response = requests.get(URL, headers=headers, params=params) + return response diff --git a/endpoints/get_user.py b/endpoints/get_user.py new file mode 100644 index 0000000..d081623 --- /dev/null +++ b/endpoints/get_user.py @@ -0,0 +1,10 @@ +import requests + +URL = "http://127.0.0.1:8000/" +headers = {"accept": "application/json"} + + +def get_user(params: dict = None): + url = URL + "user" + response = requests.get(url, headers=headers, params=params) + return response diff --git a/mtest/__init__.py b/mtest/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mtest/test_get_alternatives.py b/mtest/test_get_alternatives.py new file mode 100644 index 0000000..7d57550 --- /dev/null +++ b/mtest/test_get_alternatives.py @@ -0,0 +1,63 @@ +from endpoints.Question.alternatives import Alternatives + + +def test_get_alternatives_1(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id=1) + assert response.status_code == 200 + assert isinstance( + response.json(), list + ), f".get_question_alternatives_1() returned unexpected json: {response.json()}" + print(response.json()) + assert response.json()[0]["id"] == 1 and response.json()[0]["alternative"] == "compact" + assert response.json()[0]["question_id"] == 1 + assert response.json()[1]["alternative"] == "utilitary" + assert response.json()[2]["alternative"] == "sporting" + assert response.json()[3]["alternative"] == "suv" + + +def test_get_question_position_2(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id=2) + assert response.status_code == 200 + assert isinstance( + response.json(), list + ), f".get_question_position_2() returned unexpected json: {response.json()}" + assert response.json()[0]["id"] == 5 and response.json()[0]["alternative"] == "low" + assert response.json()[1]["question_id"] == 2 and response.json()[1]["id"] == 6 + + +def test_get_question_negative(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id=-1) + assert response.status_code == 200 + assert isinstance( + response.json(), list + ), f".get_question_negative() returned unexpected json: {response.json()}" + + +def test_get_question_large(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id=1000) + assert response.status_code == 200 + assert isinstance( + response.json(), list + ), f".get_question_large() returned unexpected json: {response.json()}" + + +def test_get_question_string(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id="foo") + assert response.status_code == 422 + assert isinstance( + response.json(), dict + ), f".get_question_string() returned unexpected json: {response.json()}" + + +def test_get_question_none(): + alternatives = Alternatives() + response = alternatives.get_alternatives(question_id=None) + assert response.status_code == 422 + assert isinstance( + response.json(), dict + ), f".get_question_none() returned unexpected json: {response.json()}" diff --git a/mtest/test_get_question.py b/mtest/test_get_question.py new file mode 100644 index 0000000..5069dd7 --- /dev/null +++ b/mtest/test_get_question.py @@ -0,0 +1,59 @@ +from endpoints.Question.question import Question + + +def test_get_question_position_1(): + questions = Question() + response = questions.get_question(position=1) + assert response.status_code == 200 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" + assert response.json()["id"] == 1 and response.json()["position"] == 1 + assert response.json()["question"] == "Which car model/category are you looking for?" + + +def test_get_question_position_2(): + questions = Question() + response = questions.get_question(position=2) + assert response.status_code == 200 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" + assert response.json()["id"] == 3 and response.json()["position"] == 2 + assert response.json()["question"] == "What type of fuel is your ideal car?" + + +def test_get_question_negative(): + questions = Question() + response = questions.get_question(position=-1) + assert response.status_code == 400 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" + + +def test_get_question_large(): + questions = Question() + response = questions.get_question(position=1000) + assert response.status_code == 400 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" + + +def test_get_question_string(): + questions = Question() + response = questions.get_question(position="foo") + assert response.status_code == 422 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" + + +def test_get_question_none(): + questions = Question() + response = questions.get_question(position=None) + assert response.status_code == 422 + assert isinstance( + response.json(), dict + ), f".get_question() returned unexpected json: {response.json()}" diff --git a/mtest/test_get_root.py b/mtest/test_get_root.py new file mode 100644 index 0000000..8b13f8d --- /dev/null +++ b/mtest/test_get_root.py @@ -0,0 +1,7 @@ +from endpoints.get_root import get_root + + +def test_get_root(): + response = get_root() + assert response.status_code == 200 + assert response.json()["message"] == "Fast API in Python" diff --git a/mtest/test_get_user.py b/mtest/test_get_user.py new file mode 100644 index 0000000..778276f --- /dev/null +++ b/mtest/test_get_user.py @@ -0,0 +1,12 @@ +from endpoints.User.users import User + + +def test_get_user(): + user = User() + response = user.get_user() + assert response.status_code == 200 + assert isinstance( + response.json(), list + ), f".get_user() returned unexpected json: {response.json()}" + assert response.json()[0]["id"] == 1 and response.json()[0]["name"] == "Márcio" + assert response.json()[1]["id"] == 2 and response.json()[1]["name"] == "Leandro"