@@ -659,6 +659,15 @@ def test_fetches_async_by_default(self):
659
659
verified = True ,
660
660
primary = False ,
661
661
)
662
+ # Reflect reality -- to be an MIT student, you *must* have a verified mit.edu
663
+ self .participant .affiliation = "MU"
664
+ self .participant .save ()
665
+ factories .EmailAddressFactory .create (
666
+ user = self .participant .user ,
667
+ verified = True ,
668
+ primary = False ,
669
+
670
+ )
662
671
factories .SignUpFactory .create (participant = self .participant , on_trip = True )
663
672
664
673
with mock .patch .object (tasks .update_member_stats , "delay" ) as update :
@@ -680,6 +689,7 @@ def test_fetches_async_by_default(self):
680
689
"num_trips_attended" : 1 ,
681
690
"num_trips_led" : 0 ,
682
691
"num_discounts" : 0 ,
692
+
683
693
},
684
694
],
685
695
},
@@ -768,6 +778,7 @@ def test_matches_on_verified_emails_only(self) -> None:
768
778
"num_rentals" : 0 ,
769
779
"num_trips_attended" : 0 ,
770
780
"num_trips_led" : 0 ,
781
+ "mit_email" : None ,
771
782
},
772
783
# We did not find a matching trips account
773
784
{
@@ -777,6 +788,56 @@ def test_matches_on_verified_emails_only(self) -> None:
777
788
},
778
789
)
779
790
791
+ @responses .activate
792
+ def test_ignores_possibly_old_mit_edu (self ):
793
+ with freeze_time ("2019-02-22 12:25:00 EST" ):
794
+ cached = models .MembershipStats .load ()
795
+ cached .response = [
796
+ {
797
+ "id" : 37 ,
798
+ "affiliation" : "MIT alum (former student)" ,
799
+ "alternate_emails" : [
"[email protected] " ],
800
+
801
+ "num_rentals" : 3 ,
802
+ }
803
+ ]
804
+ cached .save ()
805
+
806
+ # Simulate an old MIT email they may no longer own!
807
+ factories .EmailAddressFactory .create (
808
+ user = self .participant .user ,
809
+
810
+ verified = True ,
811
+ primary = False ,
812
+ )
813
+ # MIT alum -- they *used* to own [email protected]
814
+ self .participant .affiliation = "ML"
815
+ self .participant .save ()
816
+
817
+ with mock .patch .object (tasks .update_member_stats , "delay" ):
818
+ response = self .client .get ("/stats/membership.json" ) # No cache_strategy
819
+
820
+ self .assertEqual (
821
+ response .json (),
822
+ {
823
+ # We used the cached information from the geardb
824
+ "retrieved_at" : "2019-02-22T12:25:00-05:00" ,
825
+ "members" : [
826
+ {
827
+ "email" : self .participant .email ,
828
+ "affiliation" : "MIT alum (former student)" ,
829
+ "num_rentals" : 3 ,
830
+ "is_leader" : True ,
831
+ "num_trips_attended" : 0 ,
832
+ "num_trips_led" : 0 ,
833
+ "num_discounts" : 0 ,
834
+ # We do *not* report the mit.edu email -- it may be old
835
+ "mit_email" : None ,
836
+ },
837
+ ],
838
+ },
839
+ )
840
+
780
841
@responses .activate
781
842
def test_trips_data_included (self ):
782
843
responses .get (
@@ -812,6 +873,15 @@ def test_trips_data_included(self):
812
873
verified = True ,
813
874
primary = False ,
814
875
)
876
+ # Reflect reality -- to be an MIT student, you *must* have a verified mit.edu
877
+ self .participant .affiliation = "MU"
878
+ self .participant .save ()
879
+ factories .EmailAddressFactory .create (
880
+ user = self .participant .user ,
881
+ verified = True ,
882
+ primary = False ,
883
+
884
+ )
815
885
bob = factories .
ParticipantFactory .
create (
email = "[email protected] " )
816
886
factories .EmailAddressFactory .create (
817
887
user = bob .
user ,
email = "[email protected] " ,
verified = True ,
primary = False
@@ -849,6 +919,7 @@ def test_trips_data_included(self):
849
919
"num_trips_attended" : 1 ,
850
920
"num_trips_led" : 2 ,
851
921
"num_discounts" : 0 ,
922
+ "mit_email" : None ,
852
923
},
853
924
{
854
925
"email" : self .participant .email ,
@@ -858,6 +929,7 @@ def test_trips_data_included(self):
858
929
"num_trips_attended" : 2 ,
859
930
"num_trips_led" : 1 ,
860
931
"num_discounts" : 1 ,
932
+
861
933
},
862
934
# We did not find a matching trips account
863
935
{
@@ -878,5 +950,6 @@ def test_trips_data_included(self):
878
950
# 1. Count trips per participant (separate to avoid double-counting)
879
951
# 2. Count discounts, trips led, per participant
880
952
# 3. Get all emails (lowercased, for mapping back to participant records)
881
- with self .assertNumQueries (3 ):
953
+ # 4. Get MIT email addresses
954
+ with self .assertNumQueries (4 ):
882
955
stats .with_trips_information ()
0 commit comments