11import pytest
2- from django .db import connection
3- from django .test .utils import CaptureQueriesContext
42
53from conferences .tests .factories import (
64 ConferenceFactory ,
97 KeynoteSpeakerFactory ,
108)
119from i18n .strings import LazyI18nString
12- from participants import models as participant_models
1310from participants .tests .factories import ParticipantFactory
1411from submissions .models import Submission
1512from submissions .tests .factories import SubmissionFactory , SubmissionTypeFactory
6865query SearchEvents(
6966 $firstConferenceId: ID!
7067 $secondConferenceId: ID!
71- $uncachedSubmissionId: ID!
7268) {
7369 first: searchEventsForSchedule(
7470 conferenceId: $firstConferenceId
8480 }
8581 }
8682 }
87- uncachedSubmission: submission(id: $uncachedSubmissionId) {
88- speaker {
89- participant {
90- speakerAvailabilities
91- }
92- }
93- }
9483 second: searchEventsForSchedule(
9584 conferenceId: $secondConferenceId
9685 query: "Shared"
10998"""
11099
111100
112- CACHED_PARTICIPANT_SEARCH_EVENTS_QUERY = """
113- query SearchEvents($code: String!, $conferenceId: ID!) {
114- conference(code: $code) {
115- keynotes {
116- speakers {
117- participant {
118- speakerAvailabilities
119- }
120- }
121- }
122- }
123- searchEventsForSchedule(conferenceId: $conferenceId, query: "Cached") {
124- results {
125- ... on Keynote {
126- speakers {
127- participant {
128- speakerAvailabilities
129- }
130- }
131- }
132- }
133- }
134- }
135- """
136-
137-
138101def _search_events_for_schedule (client , ** input ):
139102 return client .query (
140103 """query SearchEventsForSchedule($conferenceId: ID!, $query: String!) {
@@ -156,7 +119,7 @@ def _search_events_for_schedule(client, **input):
156119
157120@pytest .mark .parametrize (
158121 ("event_count" , "expected_queries" ),
159- [(1 , 9 ), (4 , 9 )],
122+ [(1 , 10 ), (4 , 10 )],
160123)
161124@pytest .mark .parametrize ("has_participant" , [True , False ])
162125def test_frontend_search_events_query (
@@ -311,27 +274,13 @@ def test_frontend_search_events_query_keeps_participants_scoped_by_conference(
311274 title = LazyI18nString ({"en" : f"Shared Talk { index } " , "it" : "" }),
312275 )
313276
314- uncached_speaker = UserFactory (full_name = "Uncached Speaker" )
315- ParticipantFactory (
316- conference = conferences [1 ],
317- user = uncached_speaker ,
318- speaker_availabilities = {"uncached" : True },
319- )
320- uncached_submission = SubmissionFactory (
321- conference = conferences [1 ],
322- speaker = uncached_speaker ,
323- status = Submission .STATUS .accepted ,
324- title = LazyI18nString ({"en" : "Unmatched Talk" , "it" : "" }),
325- )
326-
327277 admin_graphql_api_client .force_login (admin_superuser )
328- with django_assert_num_queries (13 ):
278+ with django_assert_num_queries (10 ):
329279 response = admin_graphql_api_client .query (
330280 MULTI_CONFERENCE_SEARCH_EVENTS_QUERY ,
331281 variables = {
332282 "firstConferenceId" : str (conferences [0 ].id ),
333283 "secondConferenceId" : str (conferences [1 ].id ),
334- "uncachedSubmissionId" : uncached_submission .hashid ,
335284 },
336285 )
337286
@@ -346,9 +295,6 @@ def test_frontend_search_events_query_keeps_participants_scoped_by_conference(
346295 }
347296 ]
348297 },
349- "uncachedSubmission" : {
350- "speaker" : {"participant" : {"speakerAvailabilities" : {"uncached" : True }}}
351- },
352298 "second" : {
353299 "results" : [
354300 {
@@ -361,42 +307,6 @@ def test_frontend_search_events_query_keeps_participants_scoped_by_conference(
361307 }
362308
363309
364- def test_frontend_search_events_query_reuses_cached_participants (
365- admin_graphql_api_client ,
366- admin_superuser ,
367- ):
368- conference = ConferenceFactory ()
369- keynote = KeynoteFactory (
370- conference = conference ,
371- title = LazyI18nString ({"en" : "Cached Keynote" , "it" : "" }),
372- )
373- speaker = KeynoteSpeakerFactory (keynote = keynote ).user
374- ParticipantFactory (
375- conference = conference ,
376- user = speaker ,
377- speaker_availabilities = {"cached" : True },
378- )
379-
380- admin_graphql_api_client .force_login (admin_superuser )
381- with CaptureQueriesContext (connection ) as queries :
382- response = admin_graphql_api_client .query (
383- CACHED_PARTICIPANT_SEARCH_EVENTS_QUERY ,
384- variables = {
385- "code" : conference .code ,
386- "conferenceId" : str (conference .id ),
387- },
388- )
389-
390- participant_table = participant_models .Participant ._meta .db_table
391- assert sum (f'FROM "{ participant_table } "' in query ["sql" ] for query in queries ) == 1
392- assert "errors" not in response
393- participant = {"participant" : {"speakerAvailabilities" : {"cached" : True }}}
394- assert response ["data" ] == {
395- "conference" : {"keynotes" : [{"speakers" : [participant ]}]},
396- "searchEventsForSchedule" : {"results" : [{"speakers" : [participant ]}]},
397- }
398-
399-
400310@pytest .mark .parametrize ("user_to_test" , ["admin_user" , "user" , "not_authenticated" ])
401311def test_cannot_search_without_permission (
402312 admin_graphql_api_client ,
0 commit comments