Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file added endpoints/Question/__init__.py
Empty file.
13 changes: 13 additions & 0 deletions endpoints/Question/alternatives.py
Original file line number Diff line number Diff line change
@@ -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
13 changes: 13 additions & 0 deletions endpoints/Question/question.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added endpoints/User/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions endpoints/User/users.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions endpoints/get_root.py
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions endpoints/get_user.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added mtest/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions mtest/test_get_alternatives.py
Original file line number Diff line number Diff line change
@@ -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()}"
59 changes: 59 additions & 0 deletions mtest/test_get_question.py
Original file line number Diff line number Diff line change
@@ -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()}"
7 changes: 7 additions & 0 deletions mtest/test_get_root.py
Original file line number Diff line number Diff line change
@@ -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"
12 changes: 12 additions & 0 deletions mtest/test_get_user.py
Original file line number Diff line number Diff line change
@@ -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"