|
1 | 1 | from datetime import timedelta |
2 | 2 | from typing import Any |
3 | 3 |
|
| 4 | +import grpc |
4 | 5 | import pytest |
5 | 6 | from google.protobuf import empty_pb2, wrappers_pb2 |
6 | 7 | from sqlalchemy import select |
@@ -751,6 +752,62 @@ def test_event_search_filter_subscription_attendance_organizing_my_communities( |
751 | 752 | assert {event.title for event in res.events} == {"Subscribed event", "Attending event", "Organized event"} |
752 | 753 |
|
753 | 754 |
|
| 755 | +def test_event_search_exclude_attending(sample_community, create_event, moderator: Moderator): |
| 756 | + """Test that exclude_attending removes events the user is attending or organizing.""" |
| 757 | + user, token = generate_user() |
| 758 | + other_user, other_token = generate_user() |
| 759 | + |
| 760 | + with communities_session(token) as api: |
| 761 | + api.JoinCommunity(communities_pb2.JoinCommunityReq(community_id=sample_community)) |
| 762 | + |
| 763 | + with session_scope() as session: |
| 764 | + create_community(session, 55, 60, "Other community", [other_user], [], None) |
| 765 | + |
| 766 | + with events_session(other_token) as api: |
| 767 | + e_attending = create_event(api, title="Attending event") |
| 768 | + e_community_only = create_event(api, title="Community only event") |
| 769 | + create_event( |
| 770 | + api, |
| 771 | + title="Other community event", |
| 772 | + offline_information=events_pb2.OfflineEventInformation(lat=58, lng=1, address="Somewhere"), |
| 773 | + ) |
| 774 | + |
| 775 | + with session_scope() as session: |
| 776 | + occurrence_ids = session.execute(select(EventOccurrence.id)).scalars().all() |
| 777 | + for oid in occurrence_ids: |
| 778 | + moderator.approve_event_occurrence(oid) |
| 779 | + |
| 780 | + with events_session(token) as api: |
| 781 | + e_organized = create_event(api, title="Organized event") |
| 782 | + api.SetEventAttendance( |
| 783 | + events_pb2.SetEventAttendanceReq( |
| 784 | + event_id=e_attending.event_id, attendance_state=events_pb2.ATTENDANCE_STATE_GOING |
| 785 | + ) |
| 786 | + ) |
| 787 | + |
| 788 | + with search_session(token) as api: |
| 789 | + # baseline: my_communities returns all community events including attended/organized |
| 790 | + res = api.EventSearch(search_pb2.EventSearchReq(my_communities=True)) |
| 791 | + assert {event.title for event in res.events} == { |
| 792 | + "Attending event", |
| 793 | + "Community only event", |
| 794 | + "Organized event", |
| 795 | + } |
| 796 | + |
| 797 | + # my_communities + exclude_attending: drops attended and organized events |
| 798 | + res = api.EventSearch(search_pb2.EventSearchReq(my_communities=True, exclude_attending=True)) |
| 799 | + assert {event.title for event in res.events} == {"Community only event"} |
| 800 | + |
| 801 | + # exclude_attending alone (no other filter = all events): drops attended and organized |
| 802 | + res = api.EventSearch(search_pb2.EventSearchReq(exclude_attending=True)) |
| 803 | + assert {event.title for event in res.events} == {"Community only event", "Other community event"} |
| 804 | + |
| 805 | + # attending + exclude_attending is invalid |
| 806 | + with pytest.raises(grpc.RpcError) as e: |
| 807 | + api.EventSearch(search_pb2.EventSearchReq(attending=True, exclude_attending=True)) |
| 808 | + assert e.value.code() == grpc.StatusCode.INVALID_ARGUMENT |
| 809 | + |
| 810 | + |
754 | 811 | def test_regression_search_multiple_pages(db): |
755 | 812 | """ |
756 | 813 | There was a bug when there are multiple pages of results |
|
0 commit comments