2020-06-02 22:17:00 +00:00
|
|
|
from tests.base_test import BaseTest
|
2020-04-20 19:16:33 +00:00
|
|
|
|
2020-04-20 20:02:13 +00:00
|
|
|
from crc.api.common import ApiError
|
2020-04-20 19:16:33 +00:00
|
|
|
from crc.services.ldap_service import LdapService
|
|
|
|
|
|
|
|
|
|
|
|
class TestLdapService(BaseTest):
|
|
|
|
|
|
|
|
def setUp(self):
|
2020-06-04 18:59:36 +00:00
|
|
|
pass
|
2020-04-20 19:16:33 +00:00
|
|
|
|
|
|
|
def tearDown(self):
|
2020-04-21 00:28:12 +00:00
|
|
|
pass
|
2020-04-20 19:16:33 +00:00
|
|
|
|
|
|
|
def test_get_single_user(self):
|
2020-06-04 18:59:36 +00:00
|
|
|
user_info = LdapService.user_info("lb3dp")
|
2020-04-20 19:16:33 +00:00
|
|
|
self.assertIsNotNone(user_info)
|
2020-05-19 20:11:43 +00:00
|
|
|
self.assertEqual("lb3dp", user_info.uid)
|
2020-04-20 19:16:33 +00:00
|
|
|
self.assertEqual("Laura Barnes", user_info.display_name)
|
|
|
|
self.assertEqual("Laura", user_info.given_name)
|
2020-05-22 13:50:18 +00:00
|
|
|
self.assertEqual("lb3dp@virginia.edu", user_info.email_address)
|
2020-04-20 19:16:33 +00:00
|
|
|
self.assertEqual("+1 (434) 924-1723", user_info.telephone_number)
|
|
|
|
self.assertEqual("E0:Associate Professor of Systems and Information Engineering", user_info.title)
|
|
|
|
self.assertEqual("E0:EN-Eng Sys and Environment", user_info.department)
|
|
|
|
self.assertEqual("faculty", user_info.affiliation)
|
|
|
|
self.assertEqual("Staff", user_info.sponsor_type)
|
|
|
|
|
2020-04-20 20:02:13 +00:00
|
|
|
def test_find_missing_user(self):
|
|
|
|
try:
|
2020-06-04 18:59:36 +00:00
|
|
|
user_info = LdapService.user_info("nosuch")
|
2020-04-20 20:02:13 +00:00
|
|
|
self.assertFalse(True, "An API error should be raised.")
|
|
|
|
except ApiError as ae:
|
2020-07-17 22:59:25 +00:00
|
|
|
self.assertEqual("missing_ldap_record", ae.code)
|
2021-07-22 14:47:25 +00:00
|
|
|
|
|
|
|
def test_get_user_with_caps(self):
|
|
|
|
user_info = LdapService.user_info("LB3DP")
|
|
|
|
self.assertIsNotNone(user_info)
|
|
|
|
self.assertEqual("lb3dp", user_info.uid)
|