-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report MIT email for student members
We *require* students to provide a valid `@mit.edu` email address in order to pay dues as students -- this is valuable for identifying somebody's Kerberos even if they choose to have, say, a Gmail address as their preferred address.
- Loading branch information
Showing
3 changed files
with
122 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -659,6 +659,15 @@ def test_fetches_async_by_default(self): | |
verified=True, | ||
primary=False, | ||
) | ||
# Reflect reality -- to be an MIT student, you *must* have a verified mit.edu | ||
self.participant.affiliation = "MU" | ||
self.participant.save() | ||
factories.EmailAddressFactory.create( | ||
user=self.participant.user, | ||
verified=True, | ||
primary=False, | ||
email="[email protected]", | ||
) | ||
factories.SignUpFactory.create(participant=self.participant, on_trip=True) | ||
|
||
with mock.patch.object(tasks.update_member_stats, "delay") as update: | ||
|
@@ -680,6 +689,7 @@ def test_fetches_async_by_default(self): | |
"num_trips_attended": 1, | ||
"num_trips_led": 0, | ||
"num_discounts": 0, | ||
"mit_email": "[email protected]", | ||
}, | ||
], | ||
}, | ||
|
@@ -712,6 +722,8 @@ def test_no_matching_participant(self): | |
self._expect_members( | ||
{ | ||
"email": "[email protected]", | ||
# We still report the MIT email from the geardb! | ||
"mit_email": "[email protected]", | ||
"affiliation": "MIT undergrad", | ||
"num_rentals": 3, | ||
} | ||
|
@@ -761,6 +773,7 @@ def test_matches_on_verified_emails_only(self) -> None: | |
{ | ||
# We report their trips email as preferred! | ||
"email": "[email protected]", | ||
"mit_email": None, | ||
"affiliation": "Non-MIT undergrad", | ||
# Found a matching account! | ||
"is_leader": False, | ||
|
@@ -773,10 +786,61 @@ def test_matches_on_verified_emails_only(self) -> None: | |
{ | ||
"affiliation": "MIT affiliate", | ||
"email": "[email protected]", | ||
"mit_email": None, | ||
"num_rentals": 0, | ||
}, | ||
) | ||
|
||
@responses.activate | ||
def test_ignores_possibly_old_mit_edu(self): | ||
with freeze_time("2019-02-22 12:25:00 EST"): | ||
cached = models.MembershipStats.load() | ||
cached.response = [ | ||
{ | ||
"id": 37, | ||
"affiliation": "MIT alum (former student)", | ||
"alternate_emails": ["[email protected]"], | ||
"email": "[email protected]", | ||
"num_rentals": 3, | ||
} | ||
] | ||
cached.save() | ||
|
||
# Simulate an old MIT email they may no longer own! | ||
factories.EmailAddressFactory.create( | ||
user=self.participant.user, | ||
email="[email protected]", | ||
verified=True, | ||
primary=False, | ||
) | ||
# MIT alum -- they *used* to own [email protected] | ||
self.participant.affiliation = "ML" | ||
self.participant.save() | ||
|
||
with mock.patch.object(tasks.update_member_stats, "delay"): | ||
response = self.client.get("/stats/membership.json") # No cache_strategy | ||
|
||
self.assertEqual( | ||
response.json(), | ||
{ | ||
# We used the cached information from the geardb | ||
"retrieved_at": "2019-02-22T12:25:00-05:00", | ||
"members": [ | ||
{ | ||
"email": self.participant.email, | ||
"affiliation": "MIT alum (former student)", | ||
"num_rentals": 3, | ||
"is_leader": True, | ||
"num_trips_attended": 0, | ||
"num_trips_led": 0, | ||
"num_discounts": 0, | ||
# We do *not* report the mit.edu email -- it may be old | ||
"mit_email": None, | ||
}, | ||
], | ||
}, | ||
) | ||
|
||
@responses.activate | ||
def test_trips_data_included(self): | ||
responses.get( | ||
|
@@ -812,6 +876,15 @@ def test_trips_data_included(self): | |
verified=True, | ||
primary=False, | ||
) | ||
# Reflect reality -- to be an MIT student, you *must* have a verified mit.edu | ||
self.participant.affiliation = "MU" | ||
self.participant.save() | ||
factories.EmailAddressFactory.create( | ||
user=self.participant.user, | ||
verified=True, | ||
primary=False, | ||
email="[email protected]", | ||
) | ||
bob = factories.ParticipantFactory.create(email="[email protected]") | ||
factories.EmailAddressFactory.create( | ||
user=bob.user, email="[email protected]", verified=True, primary=False | ||
|
@@ -843,6 +916,7 @@ def test_trips_data_included(self): | |
self._expect_members( | ||
{ | ||
"email": "[email protected]", # Preferred email! | ||
"mit_email": None, | ||
"affiliation": "Non-MIT undergrad", | ||
"num_rentals": 0, | ||
"is_leader": False, # Not presently a leader! | ||
|
@@ -852,6 +926,7 @@ def test_trips_data_included(self): | |
}, | ||
{ | ||
"email": self.participant.email, | ||
"mit_email": "[email protected]", | ||
"affiliation": "MIT undergrad", | ||
"num_rentals": 3, | ||
"is_leader": True, | ||
|
@@ -863,6 +938,7 @@ def test_trips_data_included(self): | |
{ | ||
"affiliation": "MIT affiliate", | ||
"email": "[email protected]", | ||
"mit_email": None, | ||
"num_rentals": 0, | ||
}, | ||
) | ||
|
@@ -878,5 +954,6 @@ def test_trips_data_included(self): | |
# 1. Count trips per participant (separate to avoid double-counting) | ||
# 2. Count discounts, trips led, per participant | ||
# 3. Get all emails (lowercased, for mapping back to participant records) | ||
with self.assertNumQueries(3): | ||
# 4. Get MIT email addresses | ||
with self.assertNumQueries(4): | ||
stats.with_trips_information() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters