-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Report member affiliation using endpoint
We previously reached directly into the database to achieve this, but we should instead be invoking an API endpoint which does all the logic directly in the gear database!
- Loading branch information
Showing
3 changed files
with
90 additions
and
68 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 |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
from django.test import SimpleTestCase | ||
from freezegun import freeze_time | ||
|
||
from ws.tests import TestCase, factories | ||
from ws.utils import geardb | ||
|
||
|
||
|
@@ -102,6 +103,64 @@ def test_pagination_not_handled(self): | |
) | ||
|
||
|
||
class UpdateAffiliationTest(TestCase): | ||
def test_old_student_status(self): | ||
participant = factories.ParticipantFactory.create(affiliation='S') | ||
|
||
with mock.patch.object(requests, 'put') as fake_put: | ||
response = geardb.update_affiliation(participant) | ||
self.assertIsNone(response) | ||
fake_put.assert_not_called() | ||
|
||
@staticmethod | ||
def test_reports_affiliation(): | ||
"""We report affiliation for a simple user with just one email.""" | ||
participant = factories.ParticipantFactory.create( | ||
affiliation='NA', email='[email protected]' | ||
) | ||
|
||
with mock.patch.object(requests, 'put') as fake_put: | ||
geardb.update_affiliation(participant) | ||
fake_put.assert_called_once_with( | ||
'https://mitoc-gear.mit.edu/api-auth/v1/affiliation/', | ||
headers={'Authorization': mock.ANY, 'Content-Type': 'application/json'}, | ||
json={ | ||
'email': '[email protected]', | ||
'affiliation': 'NA', | ||
'other_verified_emails': [], | ||
}, | ||
) | ||
|
||
@staticmethod | ||
def test_reports_affiliation_with_other_emails(): | ||
"""We report all known verified emails.""" | ||
tim = factories.ParticipantFactory.create(affiliation='NA', email='[email protected]') | ||
|
||
factories.EmailFactory.create( | ||
user_id=tim.user_id, | ||
verified=False, | ||
primary=False, | ||
# Tim clearly doesn't own this email | ||
email='[email protected]', | ||
) | ||
for verified_email in ['[email protected]', '[email protected]']: | ||
factories.EmailFactory.create( | ||
user_id=tim.user_id, verified=True, primary=False, email=verified_email | ||
) | ||
|
||
with mock.patch.object(requests, 'put') as fake_put: | ||
geardb.update_affiliation(tim) | ||
fake_put.assert_called_once_with( | ||
'https://mitoc-gear.mit.edu/api-auth/v1/affiliation/', | ||
headers={'Authorization': mock.ANY, 'Content-Type': 'application/json'}, | ||
json={ | ||
'email': '[email protected]', | ||
'affiliation': 'NA', | ||
'other_verified_emails': ['[email protected]', '[email protected]'], | ||
}, | ||
) | ||
|
||
|
||
class NoUserTests(SimpleTestCase): | ||
"""Convenience methods neatly handle missing or anonymous users.""" | ||
|
||
|
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