2021-11-09 16:05:04 +00:00
|
|
|
import json
|
|
|
|
|
2021-10-28 20:19:39 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
|
|
|
|
|
|
|
|
class TestLdapApi(BaseTest):
|
|
|
|
|
|
|
|
def test_get_ldap(self):
|
|
|
|
"""
|
2021-11-09 16:08:55 +00:00
|
|
|
Test to make sure that LDAP api returns a real user
|
2021-10-28 20:19:39 +00:00
|
|
|
"""
|
|
|
|
self.load_example_data()
|
2021-11-09 16:05:04 +00:00
|
|
|
rv = self.app.get('/v1.0/ldap?query=dhf',
|
2021-10-28 20:19:39 +00:00
|
|
|
follow_redirects=True,
|
|
|
|
content_type="application/json", headers=self.logged_in_headers())
|
|
|
|
self.assertTrue(rv.status_code == 200)
|
2021-11-09 16:05:04 +00:00
|
|
|
user_uid = "dhf8r"
|
|
|
|
data = json.loads(rv.data)
|
|
|
|
self.assertEqual(data[0]['uid'], user_uid)
|
|
|
|
self.assertEqual(data[0]['display_name'], 'Dan Funk')
|
|
|
|
self.assertEqual(data[0]['given_name'], 'Dan')
|
|
|
|
self.assertEqual(data[0]['affiliation'], 'faculty')
|
|
|
|
|
2021-11-09 16:08:55 +00:00
|
|
|
def test_not_in_ldap(self):
|
|
|
|
"""
|
|
|
|
Test to make sure the LDAP api doesn't return a nonexistent user
|
|
|
|
"""
|
|
|
|
self.load_example_data()
|
|
|
|
rv = self.app.get('/v1.0/ldap?query=atp',
|
|
|
|
follow_redirects=True,
|
|
|
|
content_type="application/json", headers=self.logged_in_headers())
|
|
|
|
# Should still successfully perform lookup
|
|
|
|
self.assertTrue(rv.status_code == 200)
|
|
|
|
data = json.loads(rv.data)
|
|
|
|
# Should not return any users
|
|
|
|
self.assertEqual(len(data), 0)
|
2021-11-09 16:05:04 +00:00
|
|
|
|
2021-10-28 20:19:39 +00:00
|
|
|
|