mirror of
https://github.com/QualityInUse/lab-random-maksktl.git
synced 2026-08-05 12:05:27 +03:00
lab random
This commit is contained in:
+43
-4
@@ -2,17 +2,56 @@
|
||||
|
||||
import pytest
|
||||
from hypothesis import given
|
||||
import json
|
||||
import hypothesis.strategies as st
|
||||
|
||||
from httpx import Client
|
||||
|
||||
my_spec = {
|
||||
"budget_minute_price": 17,
|
||||
"luxury_minute_price": 37,
|
||||
"budget_km_price": 11,
|
||||
"deviation": 0.14,
|
||||
"inno_discount": 0.06
|
||||
}
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
def test_app():
|
||||
client = Client(base_url=" https://instructors.pg.innopolis.university/innodrive/")
|
||||
client = Client(base_url="https://instructors.pg.innopolis.university/innodrive/")
|
||||
yield client # testing happens here
|
||||
|
||||
@pytest.mark.parametrize("email", ["i.ivanov@innopolis.university"])
|
||||
def test_spec(test_app, email):
|
||||
response = test_app.get("/spec/"+email)
|
||||
|
||||
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
|
||||
def test_spec(test_app, email):
|
||||
response = test_app.get("/spec/" + email)
|
||||
assert response.status_code == 200
|
||||
|
||||
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
|
||||
@given(numbers=st.integers(min_value=1, max_value=1000))
|
||||
def test_budget_multiple_requests(test_app, email, numbers):
|
||||
data = {
|
||||
"type": "budget",
|
||||
"plan": "minute",
|
||||
"distance": 10,
|
||||
"planned_distance": 10,
|
||||
"time": numbers,
|
||||
"planned_time": numbers,
|
||||
"inno_discount": "no"
|
||||
}
|
||||
response = test_app.post("/rangeprice/" + email, content=json.dumps(data))
|
||||
assert response.json()['price'] == my_spec["budget_minute_price"] * numbers
|
||||
|
||||
@pytest.mark.parametrize("email", ["m.matantsev@innopolis.university"])
|
||||
@given(numbers=st.integers(min_value=1, max_value=1000))
|
||||
def test_luxury_multiple_requests(test_app, email, numbers):
|
||||
data = {
|
||||
"type": "luxury",
|
||||
"plan": "minute",
|
||||
"distance": 10,
|
||||
"planned_distance": 10,
|
||||
"time": numbers,
|
||||
"planned_time": numbers,
|
||||
"inno_discount": "no"
|
||||
}
|
||||
response = test_app.post("/rangeprice/" + email, content=json.dumps(data))
|
||||
assert response.json()['price'] == my_spec["luxury_minute_price"] * numbers
|
||||
|
||||
@@ -5,3 +5,111 @@ import pytest
|
||||
from taskManager.taskManager import TaskManager
|
||||
from taskManager.task import Task
|
||||
import os
|
||||
|
||||
#TESTS FOR task.py
|
||||
@pytest.fixture
|
||||
def sample_task():
|
||||
instance = Task("Maks Taks", 1, "2024-03-17")
|
||||
return instance
|
||||
|
||||
|
||||
def test_task_init(sample_task):
|
||||
assert sample_task.task_text == "Maks Taks"
|
||||
assert sample_task.priority == 1
|
||||
assert sample_task.due_date == "2024-03-17"
|
||||
assert sample_task.completed == False
|
||||
|
||||
|
||||
def test_mark_completed(sample_task):
|
||||
sample_task.mark_completed()
|
||||
assert sample_task.completed == True
|
||||
|
||||
|
||||
def test_to_dict(sample_task):
|
||||
expected_dict = {
|
||||
"task_text": "Maks Taks",
|
||||
"priority": 1,
|
||||
"due_date": "2024-03-17",
|
||||
"completed": False
|
||||
}
|
||||
assert sample_task.to_dict() == expected_dict
|
||||
|
||||
|
||||
def test_from_dict():
|
||||
task_data = {
|
||||
"task_text": "Maks Taks",
|
||||
"priority": 1,
|
||||
"due_date": "2024-03-17",
|
||||
"completed": False
|
||||
}
|
||||
task_obj = Task.from_dict(task_data)
|
||||
assert task_obj.task_text == "Maks Taks"
|
||||
assert task_obj.priority == 1
|
||||
assert task_obj.due_date == "2024-03-17"
|
||||
assert task_obj.completed == False
|
||||
|
||||
|
||||
#TESTS FOR taskManager.py
|
||||
@pytest.fixture(scope="function")
|
||||
def sample_task_manager():
|
||||
if os.path.exists('./tasks.json'):
|
||||
os.remove('./tasks.json')
|
||||
taskManager = TaskManager()
|
||||
if taskManager.tasks is None:
|
||||
taskManager.load_tasks()
|
||||
return taskManager
|
||||
|
||||
@pytest.mark.parametrize("task_text, priority, due_date", [
|
||||
("Maks Taks 1", 1, "2024-03-17"),
|
||||
("Maks Taks 2", 2, "2024-03-18")
|
||||
])
|
||||
def test_task_operations(sample_task_manager, task_text, priority, due_date, capsys):
|
||||
if sample_task_manager.tasks is None:
|
||||
sample_task_manager.load_tasks()
|
||||
sample_task_manager.add_task(task_text, priority, due_date)
|
||||
assert len(sample_task_manager.tasks) == 1
|
||||
|
||||
index_to_delete = 1
|
||||
sample_task_manager.remove_task(index_to_delete)
|
||||
captured = capsys.readouterr()
|
||||
if index_to_delete < len(sample_task_manager.tasks):
|
||||
assert f"Removed task: {task_text}" in captured.out.strip()
|
||||
assert len(sample_task_manager.tasks) == 0
|
||||
else:
|
||||
assert "Invalid task number!" in captured.out.strip()
|
||||
|
||||
sample_task_manager.add_task(task_text, priority, due_date)
|
||||
index_to_update = 1
|
||||
sample_task_manager.complete_task(index_to_update)
|
||||
captured = capsys.readouterr()
|
||||
if index_to_update < len(sample_task_manager.tasks):
|
||||
assert "Task marked as completed!" in captured.out.strip()
|
||||
assert sample_task_manager.tasks[index_to_update].completed == True
|
||||
else:
|
||||
assert "Invalid task number!" in captured.out.strip()
|
||||
|
||||
|
||||
def test_list_tasks(sample_task_manager, capsys):
|
||||
if sample_task_manager.tasks is None:
|
||||
sample_task_manager.load_tasks()
|
||||
sample_task_manager.add_task("Maks Taks 1", 1, "2024-03-17")
|
||||
sample_task_manager.add_task("Maks Taks 2", 2, "2024-03-18")
|
||||
sample_task_manager.list_tasks()
|
||||
captured = capsys.readouterr()
|
||||
assert "Task List:" in captured.out
|
||||
assert "Maks Taks 1" in captured.out
|
||||
assert "Maks Taks 2" in captured.out
|
||||
|
||||
|
||||
def test_save_and_load_tasks(sample_task_manager):
|
||||
if sample_task_manager.tasks is None:
|
||||
sample_task_manager.load_tasks()
|
||||
sample_task_manager.add_task("Maks Taks", 1, "2024-03-17")
|
||||
sample_task_manager.save_tasks()
|
||||
|
||||
new_task_manager = TaskManager()
|
||||
if new_task_manager.tasks is None:
|
||||
new_task_manager.load_tasks()
|
||||
new_task_manager.load_tasks()
|
||||
assert len(new_task_manager.tasks) == 1
|
||||
assert new_task_manager.tasks[0].task_text == "Maks Taks"
|
||||
|
||||
Reference in New Issue
Block a user