Coverage for src/tests/test_notifications.py: 100%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1import pytest
3from couchers.models import User
4from couchers.sql import couchers_select as select
5from proto import notifications_pb2
6from tests.test_fixtures import db, generate_user, notifications_session, session_scope, testconfig # noqa
9@pytest.fixture(autouse=True)
10def _(testconfig):
11 pass
14def test_GetNotificationSettings(db):
15 _, token = generate_user()
17 with session_scope() as session:
18 user = session.execute(select(User)).scalar_one()
19 user.new_notifications_enabled = False
21 with notifications_session(token) as notifications:
22 res = notifications.GetNotificationSettings(notifications_pb2.GetNotificationSettingsReq())
23 assert not res.new_notifications_enabled
25 with session_scope() as session:
26 user = session.execute(select(User)).scalar_one()
27 user.new_notifications_enabled = True
29 with notifications_session(token) as notifications:
30 res = notifications.GetNotificationSettings(notifications_pb2.GetNotificationSettingsReq())
31 assert res.new_notifications_enabled
34def test_SetNotificationSettings(db):
35 _, token = generate_user()
37 with session_scope() as session:
38 user = session.execute(select(User)).scalar_one()
39 user.new_notifications_enabled = False
41 with notifications_session(token) as notifications:
42 notifications.SetNotificationSettings(
43 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=False)
44 )
46 with session_scope() as session:
47 user = session.execute(select(User)).scalar_one()
48 assert not user.new_notifications_enabled
50 with notifications_session(token) as notifications:
51 notifications.SetNotificationSettings(
52 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=True)
53 )
55 with session_scope() as session:
56 user = session.execute(select(User)).scalar_one()
57 assert user.new_notifications_enabled
59 with notifications_session(token) as notifications:
60 notifications.SetNotificationSettings(
61 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=False)
62 )
64 with session_scope() as session:
65 user = session.execute(select(User)).scalar_one()
66 assert not user.new_notifications_enabled