|
4 | 4 | from google.protobuf import empty_pb2 |
5 | 5 |
|
6 | 6 | from couchers.constants import HOST_REQUEST_MIN_LENGTH_UTF16 |
| 7 | +from couchers.db import session_scope |
7 | 8 | from couchers.proto import conversations_pb2, dashboard_pb2, discussions_pb2, events_pb2, requests_pb2 |
8 | | -from couchers.utils import today |
| 9 | +from couchers.utils import Timestamp_from_datetime, now, today |
9 | 10 | from tests.fixtures.db import generate_user |
10 | 11 | from tests.fixtures.sessions import ( |
11 | 12 | account_session, |
|
14 | 15 | events_session, |
15 | 16 | requests_session, |
16 | 17 | ) |
| 18 | +from tests.test_communities import create_community |
17 | 19 |
|
18 | 20 |
|
19 | 21 | @pytest.fixture(autouse=True) |
@@ -87,7 +89,9 @@ def test_GetDashboardV2_matches_individual_rpcs(db, moderator): |
87 | 89 | with events_session(token1) as api: |
88 | 90 | my_events = api.ListMyEvents(events_pb2.ListMyEventsReq(page_size=3)) |
89 | 91 | community_events = api.ListMyEvents( |
90 | | - events_pb2.ListMyEventsReq(page_size=3, my_communities=True, my_communities_exclude_global=True) |
| 92 | + events_pb2.ListMyEventsReq( |
| 93 | + page_size=3, my_communities=True, my_communities_exclude_global=True, exclude_attending=True |
| 94 | + ) |
91 | 95 | ) |
92 | 96 | with discussions_session(token1) as api: |
93 | 97 | discussions = api.ListMyCommunitiesDiscussions(discussions_pb2.ListMyCommunitiesDiscussionsReq(page_size=3)) |
@@ -133,6 +137,54 @@ def test_GetDashboardV2_buckets_by_role(db, moderator): |
133 | 137 | assert len(res.surfing.host_requests) == 0 |
134 | 138 |
|
135 | 139 |
|
| 140 | +def test_GetDashboardV2_community_events_excludes_attending(db, moderator): |
| 141 | + # Pins the exclude_attending parameter the web frontend sends: an event the user is |
| 142 | + # attending shows under my_events and must not also duplicate into community_events. |
| 143 | + user1, token1 = generate_user() |
| 144 | + user2, token2 = generate_user() |
| 145 | + |
| 146 | + with session_scope() as session: |
| 147 | + # community_events excludes global-level communities, so nest down to a subregion |
| 148 | + world = create_community(session, 0, 100, "World", [user1, user2], [], None) |
| 149 | + macroregion = create_community(session, 0, 100, "Macroregion", [user1, user2], [], world) |
| 150 | + region = create_community(session, 0, 100, "Region", [user1, user2], [], macroregion) |
| 151 | + subregion = create_community(session, 0, 100, "Subregion", [user1, user2], [], region) |
| 152 | + community_id = subregion.id |
| 153 | + |
| 154 | + start = now() |
| 155 | + |
| 156 | + def make_event(hours: int) -> events_pb2.CreateEventReq: |
| 157 | + return events_pb2.CreateEventReq( |
| 158 | + title="Test Event", |
| 159 | + content="Test content.", |
| 160 | + location=events_pb2.EventLocation(address="Near Null Island", lat=0.1, lng=0.2), |
| 161 | + parent_community_id=community_id, |
| 162 | + timezone="UTC", |
| 163 | + start_time=Timestamp_from_datetime(start + timedelta(hours=hours)), |
| 164 | + end_time=Timestamp_from_datetime(start + timedelta(hours=hours + 1)), |
| 165 | + ) |
| 166 | + |
| 167 | + with events_session(token2) as api: |
| 168 | + e_attending = api.CreateEvent(make_event(1)).event_id |
| 169 | + e_community_only = api.CreateEvent(make_event(2)).event_id |
| 170 | + |
| 171 | + moderator.approve_event_occurrence(e_attending) |
| 172 | + moderator.approve_event_occurrence(e_community_only) |
| 173 | + |
| 174 | + with events_session(token1) as api: |
| 175 | + api.SetEventAttendance( |
| 176 | + events_pb2.SetEventAttendanceReq(event_id=e_attending, attendance_state=events_pb2.ATTENDANCE_STATE_GOING) |
| 177 | + ) |
| 178 | + |
| 179 | + with dashboard_session(token1) as api: |
| 180 | + res = api.GetDashboardV2(dashboard_pb2.GetDashboardV2Req()) |
| 181 | + |
| 182 | + # the attended event shows under my_events (which with no flags includes all relationships)... |
| 183 | + assert e_attending in {e.event_id for e in res.my_events.events} |
| 184 | + # ...while community_events must exclude it (exclude_attending), showing only the rest |
| 185 | + assert [e.event_id for e in res.community_events.events] == [e_community_only] |
| 186 | + |
| 187 | + |
136 | 188 | def test_GetDashboardV2_empty(db): |
137 | 189 | user, token = generate_user() |
138 | 190 | with dashboard_session(token) as api: |
|
0 commit comments