Skip to content

Commit fe39dfb

Browse files
committed
Add changes for exclude_attending communities merged since this PR opened
1 parent e7967bc commit fe39dfb

2 files changed

Lines changed: 55 additions & 2 deletions

File tree

app/backend/src/couchers/servicers/dashboard.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def GetDashboardV2(
6161
page_size=DASHBOARD_PAGE_SIZE,
6262
my_communities=True,
6363
my_communities_exclude_global=True,
64+
exclude_attending=True,
6465
),
6566
context,
6667
session,

app/backend/src/tests/test_dashboard.py

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from google.protobuf import empty_pb2
55

66
from couchers.constants import HOST_REQUEST_MIN_LENGTH_UTF16
7+
from couchers.db import session_scope
78
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
910
from tests.fixtures.db import generate_user
1011
from tests.fixtures.sessions import (
1112
account_session,
@@ -14,6 +15,7 @@
1415
events_session,
1516
requests_session,
1617
)
18+
from tests.test_communities import create_community
1719

1820

1921
@pytest.fixture(autouse=True)
@@ -87,7 +89,9 @@ def test_GetDashboardV2_matches_individual_rpcs(db, moderator):
8789
with events_session(token1) as api:
8890
my_events = api.ListMyEvents(events_pb2.ListMyEventsReq(page_size=3))
8991
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+
)
9195
)
9296
with discussions_session(token1) as api:
9397
discussions = api.ListMyCommunitiesDiscussions(discussions_pb2.ListMyCommunitiesDiscussionsReq(page_size=3))
@@ -133,6 +137,54 @@ def test_GetDashboardV2_buckets_by_role(db, moderator):
133137
assert len(res.surfing.host_requests) == 0
134138

135139

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+
136188
def test_GetDashboardV2_empty(db):
137189
user, token = generate_user()
138190
with dashboard_session(token) as api:

0 commit comments

Comments
 (0)