File size: 2,403 Bytes
6bed18e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import pytest
from datetime import datetime
from src.models.task import Task, TaskCreate, TaskUpdate, TaskResponse


def test_task_creation():
    """Test creating a basic task"""
    task_create = TaskCreate(
        title="Test Task",
        description="Test Description",
        user_id="user123"
    )

    assert task_create.title == "Test Task"
    assert task_create.description == "Test Description"
    assert task_create.user_id == "user123"
    assert task_create.completed is False  # Default value


def test_task_with_completed_true():
    """Test creating a task with completed=True"""
    task_create = TaskCreate(
        title="Completed Task",
        description="A completed task",
        completed=True,
        user_id="user123"
    )

    assert task_create.completed is True


def test_task_minimal_fields():
    """Test creating a task with minimal required fields"""
    task_create = TaskCreate(
        title="Minimal Task",
        user_id="user123"
    )

    assert task_create.title == "Minimal Task"
    assert task_create.user_id == "user123"
    assert task_create.description is None
    assert task_create.completed is False


def test_task_response_model():
    """Test the TaskResponse model"""
    task_response = TaskResponse(
        id=1,
        title="Response Task",
        description="A task response",
        completed=False,
        user_id="user123",
        created_at=datetime.now(),
        updated_at=datetime.now()
    )

    assert task_response.id == 1
    assert task_response.title == "Response Task"
    assert task_response.description == "A task response"
    assert task_response.completed is False
    assert task_response.user_id == "user123"


def test_task_update_model():
    """Test the TaskUpdate model"""
    task_update = TaskUpdate(
        title="Updated Title",
        description="Updated Description",
        completed=True
    )

    assert task_update.title == "Updated Title"
    assert task_update.description == "Updated Description"
    assert task_update.completed is True


def test_task_update_partial():
    """Test partial updates in TaskUpdate model"""
    task_update = TaskUpdate(title="Only Title Updated")

    assert task_update.title == "Only Title Updated"
    # Other fields should be None since they're optional
    assert task_update.description is None
    assert task_update.completed is None