예제 #1
0
def test_add_yearly_todo_happy_path():
    todo_service = DummyTodoService([])
    result = asyncio.run(
        add_yearly_todo(
            description="Make Bed",
            start_date=datetime.date(2010, 1, 1),
            note=None,
            current_user=auth.User(
                user_id=1,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
            month=11,
            day=1,
        ))
    assert result == api.TodoResponse(
        todo_id=-1,
        category=core.TodoCategory.Todo,
        description="Make Bed",
        frequency="Nov 1",
        next=datetime.date(2010, 11, 1),
        display=False,
        note="",
    )
예제 #2
0
def test_add_monthly_todo_happy_path():
    todo_service = DummyTodoService([])
    result = asyncio.run(
        add_monthly_todo(
            description="Dust",
            advance_days=3,
            month_day=10,
            note=None,
            start_date=datetime.date(2010, 1, 1),
            current_user=auth.User(
                user_id=1,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=-1,
        category=core.TodoCategory.Todo,
        description="Dust",
        frequency="Monthly, day 10",
        next=datetime.date(2010, 10, 10),
        display=True,
        note="",
    )
예제 #3
0
def test_add_irregular_todo_happy_path() -> None:
    todo_service = DummyTodoService([])
    result = asyncio.run(
        add_irregular_todo(
            description="Make bed",
            note=None,
            start_date=datetime.date(2010, 1, 1),
            advance_days=14,
            month=1,
            week=2,
            week_day=3,
            current_user=auth.User(
                user_id=1,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=-1,
        category=core.TodoCategory.Todo,
        description="Make bed",
        frequency="Irregular",
        next=datetime.date(2010, 1, 12),
        display=True,
        note="",
    )
예제 #4
0
def test_all_todos_happy_path():
    todo_service = DummyTodoService([
        todo_domain.Yearly(
            todo_id=1,
            user_id=1,
            category=core.TodoCategory.Todo,
            description="Dust",
            advance_days=3,
            note="",
            start_date=datetime.date(2010, 1, 1),
            date_added=datetime.date(2010, 1, 1),
            date_completed=None,
            month=todo_domain.Month.January,
            day=11,
        ),
        todo_domain.Weekly(
            todo_id=2,
            user_id=2,
            category=core.TodoCategory.Todo,
            description="Make Bed",
            advance_days=10,
            note="",
            start_date=datetime.date(2009, 1, 1),
            date_added=datetime.date(2009, 1, 2),
            date_completed=datetime.date(2010, 1, 1),
            week_day=todo_domain.Weekday.Tuesday,
        ),
    ])
    result = asyncio.run(
        all_todos(
            current_user=auth.User(
                user_id=1,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == [
        api.TodoResponse(
            todo_id=1,
            category=core.TodoCategory.Todo,
            description="Dust",
            frequency="Jan 11",
            next=datetime.date(2021, 1, 11),
            display=True,
            note="",
        ),
        api.TodoResponse(
            todo_id=2,
            category=core.TodoCategory.Todo,
            description="Make Bed",
            frequency="Tue",
            next=datetime.date(2021, 3, 23),
            display=True,
            note="",
        ),
    ]
예제 #5
0
def test_get_user_happy_path():
    current_user = auth.User(
        user_id=1,
        username="******",
        email=pydantic.EmailStr("*****@*****.**"),
        password_hash=PASSWORD_HASH,
    )
    result = asyncio.run(get_user(current_user))
    assert result == api.UserResponse(
        username="******",
        email="*****@*****.**",
    )
예제 #6
0
def test_update_irregular_todo_happy_path() -> None:
    todo_service = DummyTodoService([
        todo_domain.Irregular(
            advance_days=0,
            category=core.TodoCategory.Todo,
            date_added=datetime.date(2010, 1, 2),
            date_completed=None,
            description="Run tests for user 1",
            note="",
            start_date=datetime.date(2009, 1, 1),
            todo_id=1,
            user_id=1,
            month=todo_domain.Month.January,
            week_day=todo_domain.Weekday.Friday,
            week_number=4,
        ),
        todo_domain.Irregular(
            advance_days=0,
            category=core.TodoCategory.Todo,
            date_added=datetime.date(2010, 1, 2),
            date_completed=None,
            description="Run tests for user 2",
            note="",
            start_date=datetime.date(2009, 1, 1),
            todo_id=2,
            user_id=2,
            month=todo_domain.Month.October,
            week_day=todo_domain.Weekday.Thursday,
            week_number=3,
        ),
    ])
    result = asyncio.run(
        update_irregular_todo(
            todo_id=2,
            description="Make bed",
            current_user=auth.User(
                user_id=2,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=2,
        category=core.TodoCategory.Todo,
        description="Make bed",
        frequency="Irregular",
        next=datetime.date(2010, 10, 21),
        display=False,
        note="",
    )
예제 #7
0
def test_get_current_active_user_happy_path() -> None:
    token_service = DummyTokenService()
    user_service = DummyUserService()

    user = get_current_active_user(token=ACCESS_TOKEN,
                                   token_service=token_service,
                                   user_service=user_service)
    assert user == auth.User(
        user_id=1,
        username="******",
        email=pydantic.EmailStr("*****@*****.**"),
        password_hash=PASSWORD_HASH,
    )
예제 #8
0
def test_update_yearly_todo_happy_path():
    todo_service = DummyTodoService([
        todo_domain.Yearly(
            todo_id=1,
            user_id=1,
            category=core.TodoCategory.Todo,
            description="Dust",
            advance_days=3,
            note="",
            start_date=datetime.date(2010, 1, 1),
            date_added=datetime.date(2010, 1, 1),
            date_completed=None,
            month=todo_domain.Month.January,
            day=11,
        ),
        todo_domain.Yearly(
            todo_id=2,
            user_id=2,
            category=core.TodoCategory.Todo,
            description="Make Bed",
            advance_days=10,
            note="",
            start_date=datetime.date(2009, 1, 1),
            date_added=datetime.date(2009, 1, 2),
            date_completed=datetime.date(2010, 1, 1),
            month=todo_domain.Month.October,
            day=1,
        ),
    ])
    result = asyncio.run(
        update_xdays_todo(
            todo_id=2,
            description="Vaccum",
            current_user=auth.User(
                user_id=2,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=2,
        category=core.TodoCategory.Todo,
        description="Vaccum",
        frequency="Oct 1",
        next=datetime.date(2010, 10, 1),
        display=False,
        note="",
    )
예제 #9
0
def test_update_one_time_todo_happy_path():
    todo_service = DummyTodoService([
        todo_domain.Once(
            todo_id=1,
            user_id=1,
            category=core.TodoCategory.Todo,
            description="Dust",
            advance_days=3,
            once_date=datetime.date(2010, 1, 1),
            note="",
            start_date=datetime.date(2010, 1, 1),
            date_added=datetime.date(2010, 1, 1),
            date_completed=None,
        ),
        todo_domain.Once(
            todo_id=2,
            user_id=2,
            category=core.TodoCategory.Todo,
            description="Make Bed",
            advance_days=10,
            once_date=datetime.date(2010, 12, 31),
            note="",
            start_date=datetime.date(2009, 1, 1),
            date_added=datetime.date(2009, 1, 2),
            date_completed=datetime.date(2010, 1, 1),
        ),
    ])
    result = asyncio.run(
        update_one_time_todo(
            todo_id=2,
            description="Make Bed",
            date=datetime.date(2010, 1, 1),
            note=None,
            current_user=auth.User(
                user_id=2,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=2,
        category=core.TodoCategory.Todo,
        description="Make Bed",
        frequency="2010-12-31",
        next=datetime.date(2010, 12, 31),
        display=False,
        note="",
    )
예제 #10
0
def test_update_daily_todo_happy_path() -> None:
    todo_service = DummyTodoService([
        todo_domain.Daily(
            advance_days=0,
            category=core.TodoCategory.Todo,
            date_added=datetime.date(2010, 1, 2),
            date_completed=None,
            description="Run tests for user 1",
            note="",
            start_date=datetime.date(2009, 1, 1),
            todo_id=1,
            user_id=1,
        ),
        todo_domain.Daily(
            advance_days=0,
            category=core.TodoCategory.Todo,
            date_added=datetime.date(2010, 1, 2),
            date_completed=None,
            description="Run tests for user 2",
            note="",
            start_date=datetime.date(2009, 1, 1),
            todo_id=2,
            user_id=2,
        ),
    ])
    result = asyncio.run(
        update_daily_todo(
            todo_id=2,
            description="Make bed",
            current_user=auth.User(
                user_id=2,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result == api.TodoResponse(
        todo_id=2,
        category=core.TodoCategory.Todo,
        description="Make bed",
        frequency="Daily",
        next=datetime.date.today(),
        display=True,
        note="",
    )
예제 #11
0
def test_delete_todo():
    todo_service = DummyTodoService([
        todo_domain.Yearly(
            todo_id=1,
            user_id=1,
            category=core.TodoCategory.Todo,
            description="Dust",
            advance_days=3,
            note="",
            start_date=datetime.date(2010, 1, 1),
            date_added=datetime.date(2010, 1, 1),
            date_completed=None,
            month=todo_domain.Month.January,
            day=11,
        ),
        todo_domain.Weekly(
            todo_id=2,
            user_id=2,
            category=core.TodoCategory.Todo,
            description="Make Bed",
            advance_days=10,
            note="",
            start_date=datetime.date(2009, 1, 1),
            date_added=datetime.date(2009, 1, 2),
            date_completed=datetime.date(2010, 1, 1),
            week_day=todo_domain.Weekday.Tuesday,
        ),
    ])
    result = asyncio.run(
        delete_todo(
            todo_id=1,
            current_user=auth.User(
                user_id=1,
                username="******",
                email=pydantic.EmailStr("*****@*****.**"),
                password_hash="1234" * 15,
            ),
            todo_service=todo_service,
        ))
    assert result is None