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

42 statements  

1import pytest 

2 

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 

7 

8 

9@pytest.fixture(autouse=True) 

10def _(testconfig): 

11 pass 

12 

13 

14def test_GetNotificationSettings(db): 

15 _, token = generate_user() 

16 

17 with session_scope() as session: 

18 user = session.execute(select(User)).scalar_one() 

19 user.new_notifications_enabled = False 

20 

21 with notifications_session(token) as notifications: 

22 res = notifications.GetNotificationSettings(notifications_pb2.GetNotificationSettingsReq()) 

23 assert not res.new_notifications_enabled 

24 

25 with session_scope() as session: 

26 user = session.execute(select(User)).scalar_one() 

27 user.new_notifications_enabled = True 

28 

29 with notifications_session(token) as notifications: 

30 res = notifications.GetNotificationSettings(notifications_pb2.GetNotificationSettingsReq()) 

31 assert res.new_notifications_enabled 

32 

33 

34def test_SetNotificationSettings(db): 

35 _, token = generate_user() 

36 

37 with session_scope() as session: 

38 user = session.execute(select(User)).scalar_one() 

39 user.new_notifications_enabled = False 

40 

41 with notifications_session(token) as notifications: 

42 notifications.SetNotificationSettings( 

43 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=False) 

44 ) 

45 

46 with session_scope() as session: 

47 user = session.execute(select(User)).scalar_one() 

48 assert not user.new_notifications_enabled 

49 

50 with notifications_session(token) as notifications: 

51 notifications.SetNotificationSettings( 

52 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=True) 

53 ) 

54 

55 with session_scope() as session: 

56 user = session.execute(select(User)).scalar_one() 

57 assert user.new_notifications_enabled 

58 

59 with notifications_session(token) as notifications: 

60 notifications.SetNotificationSettings( 

61 notifications_pb2.SetNotificationSettingsReq(enable_new_notifications=False) 

62 ) 

63 

64 with session_scope() as session: 

65 user = session.execute(select(User)).scalar_one() 

66 assert not user.new_notifications_enabled