2020-08-14 01:09:52 +00:00
|
|
|
from flask import g
|
|
|
|
|
2020-07-20 03:53:18 +00:00
|
|
|
from tests.base_test import BaseTest
|
|
|
|
|
2020-08-14 01:09:52 +00:00
|
|
|
from crc import db
|
2020-08-17 19:45:37 +00:00
|
|
|
from crc.services.workflow_service import WorkflowService
|
2020-08-14 01:09:52 +00:00
|
|
|
from crc.models.user import UserModel
|
2020-07-20 03:53:18 +00:00
|
|
|
from crc.services.workflow_processor import WorkflowProcessor
|
2020-07-30 17:35:20 +00:00
|
|
|
from crc.scripts.ldap import Ldap
|
|
|
|
from crc.api.common import ApiError
|
2020-07-20 03:53:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
class TestLdapLookupScript(BaseTest):
|
|
|
|
|
|
|
|
def test_get_existing_user_details(self):
|
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
|
|
|
|
2020-07-30 17:35:20 +00:00
|
|
|
script = Ldap()
|
|
|
|
user_details = script.do_task(task, workflow.study_id, workflow.id, "dhf8r")
|
2020-07-22 02:53:24 +00:00
|
|
|
|
2020-07-30 17:35:20 +00:00
|
|
|
self.assertEqual(user_details['display_name'], 'Dan Funk')
|
|
|
|
self.assertEqual(user_details['given_name'], 'Dan')
|
|
|
|
self.assertEqual(user_details['email_address'], 'dhf8r@virginia.edu')
|
|
|
|
self.assertEqual(user_details['telephone_number'], '+1 (434) 924-1723')
|
|
|
|
self.assertEqual(user_details['title'], 'E42:He\'s a hoopy frood')
|
|
|
|
self.assertEqual(user_details['department'], 'E0:EN-Eng Study of Parallel Universes')
|
|
|
|
self.assertEqual(user_details['affiliation'], 'faculty')
|
|
|
|
self.assertEqual(user_details['sponsor_type'], 'Staff')
|
|
|
|
self.assertEqual(user_details['uid'], 'dhf8r')
|
|
|
|
self.assertEqual(user_details['proper_name'], 'Dan Funk - (dhf8r)')
|
2020-07-20 03:53:18 +00:00
|
|
|
|
|
|
|
def test_get_invalid_user_details(self):
|
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
|
|
|
|
|
|
|
task.data = {
|
|
|
|
'PIComputingID': 'rec3z'
|
|
|
|
}
|
|
|
|
|
2020-07-30 17:35:20 +00:00
|
|
|
script = Ldap()
|
2021-07-22 14:47:25 +00:00
|
|
|
user_details = script.do_task(task, workflow.study_id, workflow.id, "PIComputingID")
|
|
|
|
self.assertEqual({}, user_details)
|
2020-07-22 02:53:24 +00:00
|
|
|
|
2020-08-14 01:09:52 +00:00
|
|
|
def test_get_current_user_details(self):
|
|
|
|
self.load_example_data()
|
|
|
|
self.create_reference_document()
|
|
|
|
workflow = self.create_workflow('empty_workflow')
|
|
|
|
processor = WorkflowProcessor(workflow)
|
|
|
|
task = processor.next_task()
|
|
|
|
|
|
|
|
script = Ldap()
|
|
|
|
g.user = db.session.query(UserModel).filter(UserModel.uid=='dhf8r').first()
|
|
|
|
user_details = script.do_task(task, workflow.study_id, workflow.id)
|
|
|
|
self.assertEqual(user_details['display_name'], 'Dan Funk')
|
|
|
|
|
|
|
|
|
2020-07-22 02:53:24 +00:00
|
|
|
|
|
|
|
def test_bpmn_task_receives_user_details(self):
|
2020-08-17 19:45:37 +00:00
|
|
|
workflow = self.create_workflow('ldap_script')
|
2020-07-22 02:53:24 +00:00
|
|
|
|
|
|
|
task_data = {
|
|
|
|
'Supervisor': 'dhf8r',
|
|
|
|
'Investigator': 'lb3dp'
|
|
|
|
}
|
|
|
|
task = self.get_workflow_api(workflow).next_task
|
|
|
|
|
|
|
|
self.complete_form(workflow, task, task_data)
|
|
|
|
|
|
|
|
task = self.get_workflow_api(workflow).next_task
|
|
|
|
|
2020-07-23 13:41:29 +00:00
|
|
|
self.assertEqual(task.data['Supervisor']['display_name'], 'Dan Funk')
|
|
|
|
self.assertEqual(task.data['Supervisor']['given_name'], 'Dan')
|
|
|
|
self.assertEqual(task.data['Supervisor']['email_address'], 'dhf8r@virginia.edu')
|
|
|
|
self.assertEqual(task.data['Supervisor']['telephone_number'], '+1 (434) 924-1723')
|
|
|
|
self.assertEqual(task.data['Supervisor']['title'], 'E42:He\'s a hoopy frood')
|
|
|
|
self.assertEqual(task.data['Supervisor']['department'], 'E0:EN-Eng Study of Parallel Universes')
|
|
|
|
self.assertEqual(task.data['Supervisor']['affiliation'], 'faculty')
|
|
|
|
self.assertEqual(task.data['Supervisor']['sponsor_type'], 'Staff')
|
|
|
|
self.assertEqual(task.data['Supervisor']['uid'], 'dhf8r')
|
2020-07-22 02:53:24 +00:00
|
|
|
self.assertEqual(task.data['Supervisor']['proper_name'], 'Dan Funk - (dhf8r)')
|
2020-08-17 19:45:37 +00:00
|
|
|
|
|
|
|
def test_ldap_validation(self):
|
|
|
|
workflow = self.create_workflow('ldap_script')
|
|
|
|
# This should not raise an error.
|
|
|
|
WorkflowService.test_spec('ldap_script', required_only=False)
|