@@ -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
},
@@ -712,6 +722,8 @@ def test_no_matching_participant(self):
712
722
self ._expect_members (
713
723
{
714
724
725
+ # We still report the MIT email from the geardb!
726
+
715
727
"affiliation" : "MIT undergrad" ,
716
728
"num_rentals" : 3 ,
717
729
}
@@ -761,6 +773,7 @@ def test_matches_on_verified_emails_only(self) -> None:
761
773
{
762
774
# We report their trips email as preferred!
763
775
776
+ "mit_email" : None ,
764
777
"affiliation" : "Non-MIT undergrad" ,
765
778
# Found a matching account!
766
779
"is_leader" : False ,
@@ -773,10 +786,61 @@ def test_matches_on_verified_emails_only(self) -> None:
773
786
{
774
787
"affiliation" : "MIT affiliate" ,
775
788
789
+ "mit_email" : None ,
776
790
"num_rentals" : 0 ,
777
791
},
778
792
)
779
793
794
+ @responses .activate
795
+ def test_ignores_possibly_old_mit_edu (self ):
796
+ with freeze_time ("2019-02-22 12:25:00 EST" ):
797
+ cached = models .MembershipStats .load ()
798
+ cached .response = [
799
+ {
800
+ "id" : 37 ,
801
+ "affiliation" : "MIT alum (former student)" ,
802
+ "alternate_emails" : [
"[email protected] " ],
803
+
804
+ "num_rentals" : 3 ,
805
+ }
806
+ ]
807
+ cached .save ()
808
+
809
+ # Simulate an old MIT email they may no longer own!
810
+ factories .EmailAddressFactory .create (
811
+ user = self .participant .user ,
812
+
813
+ verified = True ,
814
+ primary = False ,
815
+ )
816
+ # MIT alum -- they *used* to own [email protected]
817
+ self .participant .affiliation = "ML"
818
+ self .participant .save ()
819
+
820
+ with mock .patch .object (tasks .update_member_stats , "delay" ):
821
+ response = self .client .get ("/stats/membership.json" ) # No cache_strategy
822
+
823
+ self .assertEqual (
824
+ response .json (),
825
+ {
826
+ # We used the cached information from the geardb
827
+ "retrieved_at" : "2019-02-22T12:25:00-05:00" ,
828
+ "members" : [
829
+ {
830
+ "email" : self .participant .email ,
831
+ "affiliation" : "MIT alum (former student)" ,
832
+ "num_rentals" : 3 ,
833
+ "is_leader" : True ,
834
+ "num_trips_attended" : 0 ,
835
+ "num_trips_led" : 0 ,
836
+ "num_discounts" : 0 ,
837
+ # We do *not* report the mit.edu email -- it may be old
838
+ "mit_email" : None ,
839
+ },
840
+ ],
841
+ },
842
+ )
843
+
780
844
@responses .activate
781
845
def test_trips_data_included (self ):
782
846
responses .get (
@@ -812,6 +876,15 @@ def test_trips_data_included(self):
812
876
verified = True ,
813
877
primary = False ,
814
878
)
879
+ # Reflect reality -- to be an MIT student, you *must* have a verified mit.edu
880
+ self .participant .affiliation = "MU"
881
+ self .participant .save ()
882
+ factories .EmailAddressFactory .create (
883
+ user = self .participant .user ,
884
+ verified = True ,
885
+ primary = False ,
886
+
887
+ )
815
888
bob = factories .
ParticipantFactory .
create (
email = "[email protected] " )
816
889
factories .EmailAddressFactory .create (
817
890
user = bob .
user ,
email = "[email protected] " ,
verified = True ,
primary = False
@@ -843,6 +916,7 @@ def test_trips_data_included(self):
843
916
self ._expect_members (
844
917
{
845
918
"email" :
"[email protected] " ,
# Preferred email!
919
+ "mit_email" : None ,
846
920
"affiliation" : "Non-MIT undergrad" ,
847
921
"num_rentals" : 0 ,
848
922
"is_leader" : False , # Not presently a leader!
@@ -852,6 +926,7 @@ def test_trips_data_included(self):
852
926
},
853
927
{
854
928
"email" : self .participant .email ,
929
+
855
930
"affiliation" : "MIT undergrad" ,
856
931
"num_rentals" : 3 ,
857
932
"is_leader" : True ,
@@ -863,6 +938,7 @@ def test_trips_data_included(self):
863
938
{
864
939
"affiliation" : "MIT affiliate" ,
865
940
941
+ "mit_email" : None ,
866
942
"num_rentals" : 0 ,
867
943
},
868
944
)
@@ -878,5 +954,6 @@ def test_trips_data_included(self):
878
954
# 1. Count trips per participant (separate to avoid double-counting)
879
955
# 2. Count discounts, trips led, per participant
880
956
# 3. Get all emails (lowercased, for mapping back to participant records)
881
- with self .assertNumQueries (3 ):
957
+ # 4. Get MIT email addresses
958
+ with self .assertNumQueries (4 ):
882
959
stats .with_trips_information ()
0 commit comments