@@ -431,6 +431,7 @@ def test_children_project_filter(
431431 edges{
432432 node{
433433 createdAt
434+ name
434435 occurrences{
435436 edges{
436437 node{
@@ -776,50 +777,71 @@ def test_get_past_events(
776777
777778 next_project = ProjectFactory (year = 2021 )
778779
779- # Unpublished occurrences
780- OccurrenceFactory .create_batch (
781- 2 , time = timezone .now (), event = EventFactory (project = project ), venue = venue
780+ past = timezone .now () - timedelta (
781+ minutes = settings .KUKKUU_ENROLLED_OCCURRENCE_IN_PAST_LEEWAY + 1
782+ )
783+ not_enough_past = timezone .now () - timedelta (
784+ minutes = settings .KUKKUU_ENROLLED_OCCURRENCE_IN_PAST_LEEWAY - 1
782785 )
786+ future = timezone .now () + timedelta (minutes = 1 )
783787
784- # Published occurrences in the past
785- event = EventFactory (published_at = timezone .now (), project = project )
786- past_occurrence_1 = OccurrenceFactory (
787- time = datetime (1970 , 1 , 1 , 0 , 0 , 0 , tzinfo = pytz .timezone (settings .TIME_ZONE )),
788- event = event ,
789- venue = venue ,
788+ # Enrolled occurrence in the past, event should be visible
789+ event = EventFactory (
790+ published_at = timezone .now (),
791+ project = project ,
792+ name = "enrolled occurrence in the past" ,
790793 )
794+ OccurrenceFactory (time = future , event = event , venue = venue )
795+ the_past_occurrence = OccurrenceFactory (time = past , event = event , venue = venue )
796+ EnrolmentFactory (child = child_with_user_guardian , occurrence = the_past_occurrence )
791797
792- OccurrenceFactory (
793- time = datetime (1970 , 1 , 1 , 0 , 0 , 0 , tzinfo = pytz .timezone (settings .TIME_ZONE )),
794- event__published_at = timezone .now (),
795- event__project = project ,
796- venue = venue ,
798+ # Enrolled occurrence in the past but not enough, event should be NOT visible
799+ event_2 = EventFactory (
800+ published_at = timezone .now (),
801+ project = project ,
802+ name = "enrolled occurrence in the past but not enough" ,
803+ )
804+ OccurrenceFactory (time = future , event = event_2 , venue = venue )
805+ the_not_so_past_occurrence = OccurrenceFactory (
806+ time = not_enough_past , event = event_2 , venue = venue
807+ )
808+ EnrolmentFactory (
809+ child = child_with_user_guardian , occurrence = the_not_so_past_occurrence
797810 )
798- # Past occurrence but from another project
811+
812+ # Event without an enrolment in the past, should be visible
813+ event_3 = EventFactory (
814+ published_at = timezone .now (), project = project , name = "event in the past"
815+ )
816+ OccurrenceFactory (time = past , event = event_3 , venue = venue )
817+ OccurrenceFactory (time = not_enough_past , event = event_3 , venue = venue )
818+
819+ # Event without an enrolment in the future, should NOT be visible
820+ event_4 = EventFactory (
821+ published_at = timezone .now (), project = project , name = "event in the future"
822+ )
823+ OccurrenceFactory (time = not_enough_past , event = event_4 , venue = venue )
824+ OccurrenceFactory (time = future , event = event_4 , venue = venue )
825+
826+ # Past occurrence but from another project, should NOT be visible
799827 OccurrenceFactory (
800- time = datetime ( 1970 , 1 , 1 , 0 , 0 , 0 , tzinfo = pytz . timezone ( settings . TIME_ZONE )) ,
828+ time = past ,
801829 event__published_at = timezone .now (),
802830 event__project = next_project ,
831+ event__name = "another project event" ,
803832 venue = venue ,
804833 )
805834
806- # Recent published occurrence
807- OccurrenceFactory (time = timezone .now (), event = event , venue = venue )
808-
809- # Unpublished occurrences in the past
835+ # Unpublished occurrences in the past, should NOT be visible
810836 OccurrenceFactory .create_batch (
811837 3 ,
812838 time = datetime (1970 , 1 , 1 , 0 , 0 , 0 , tzinfo = pytz .timezone (settings .TIME_ZONE )),
813839 event__project = project ,
840+ event__name = "unpublished event in the past" ,
814841 venue = venue ,
815842 )
816843
817- EnrolmentFactory (child = child_with_user_guardian , occurrence = past_occurrence_1 )
818-
819844 executed = guardian_api_client .execute (CHILD_EVENTS_QUERY , variables = variables )
820- # Still return enroled events if they are past events
821- # Should only return past events from current project
822- assert len (executed ["data" ]["child" ]["pastEvents" ]["edges" ]) == 1
823845 snapshot .assert_match (executed )
824846
825847 guardian_api_client .user .projects .add (project )
0 commit comments