Coverage for src/tests/test_models.py: 100%
26 statements
« prev ^ index » next coverage.py v7.5.0, created at 2024-12-02 20:27 +0000
« prev ^ index » next coverage.py v7.5.0, created at 2024-12-02 20:27 +0000
1from datetime import date, datetime
3import pytest
4from sqlalchemy.sql import func
6from couchers.db import session_scope
7from couchers.models import User
8from couchers.sql import couchers_select as select
9from tests.test_fixtures import ( # noqa
10 db,
11 testconfig,
12)
15@pytest.fixture(autouse=True)
16def _(testconfig):
17 pass
20def test_user_age(db):
21 # these used to be test for our hand-rolled age, but moving to postgres now so just double check it does what we expect
22 today = date(2019, 7, 5)
24 with session_scope() as session:
25 assert session.execute(select(func.date_part("year", func.age(today, date(1990, 7, 4))))).scalar_one() == 29
26 assert session.execute(select(func.date_part("year", func.age(today, date(1990, 7, 31))))).scalar_one() == 28
27 assert session.execute(select(func.date_part("year", func.age(today, date(1992, 2, 29))))).scalar_one() == 27
30def test_user_display_joined():
31 assert User(joined=datetime(2020, 7, 10, 16, 34, 1, 1)).display_joined == datetime(2020, 7, 10, 16, 0, 0, 0)
32 assert User(joined=datetime(2025, 7, 10, 16, 59, 1, 1)).display_joined == datetime(2025, 7, 10, 16, 0, 0, 0)
33 assert User(joined=datetime(2020, 7, 10, 16, 0, 1, 1)).display_joined == datetime(2020, 7, 10, 16, 0, 0, 0)
34 assert User(joined=datetime(2020, 7, 10, 0, 0, 0, 0)).display_joined == datetime(2020, 7, 10, 0, 0, 0, 0)
37def test_user_display_last_active():
38 assert User(last_active=datetime(2020, 7, 10, 16, 34, 1, 1)).display_last_active == datetime(
39 2020, 7, 10, 16, 0, 0, 0
40 )
41 assert User(last_active=datetime(2025, 7, 10, 17, 59, 1, 1)).display_last_active == datetime(
42 2025, 7, 10, 17, 0, 0, 0
43 )
44 assert User(last_active=datetime(2020, 7, 10, 16, 0, 1, 1)).display_last_active == datetime(
45 2020, 7, 10, 16, 0, 0, 0
46 )
47 assert User(last_active=datetime(2020, 7, 10, 0, 0, 0, 0)).display_last_active == datetime(2020, 7, 10, 0, 0, 0, 0)