def setUp(self): self.enterprise_customer = EnterpriseCustomerFactory(name="GriffCo") self.config = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=self.enterprise_customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', active=False, ) super(TestSAPSuccessFactorsEnterpriseCustomerConfiguration, self).setUp()
def setUp(self): super(TestSAPSuccessFactorsAPIClient, self).setUp() self.oauth_api_path = "learning/oauth-api/rest/v1/token" self.completion_status_api_path = "learning/odatav4/public/admin/ocn/v1/current-user/item/learning-event" self.course_api_path = "learning/odatav4/public/admin/ocn/v1/OcnCourses" self.url_base = "http://test.successfactors.com/" self.client_id = "client_id" self.client_secret = "client_secret" self.company_id = "company_id" self.user_id = "user_id" self.user_type = "user" self.expires_in = 1800 self.access_token = "access_token" SAPSuccessFactorsGlobalConfiguration.objects.create( completion_status_api_path=self.completion_status_api_path, course_api_path=self.course_api_path, oauth_api_path=self.oauth_api_path) self.expected_token_response_body = { "expires_in": self.expires_in, "access_token": self.access_token } self.enterprise_config = SAPSuccessFactorsEnterpriseCustomerConfiguration( key=self.client_id, sapsf_base_url=self.url_base, sapsf_company_id=self.company_id, sapsf_user_id=self.user_id, secret=self.client_secret)
def setUp(self): self.api_user = UserFactory(username='******') self.user = UserFactory() self.course_id = COURSE_ID self.enterprise_customer = EnterpriseCustomerFactory() self.identity_provider = FakerFactory.create().slug() EnterpriseCustomerIdentityProviderFactory( provider_id=self.identity_provider, enterprise_customer=self.enterprise_customer) self.enterprise_customer_user = EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=self.enterprise_customer, ) self.enrollment = EnterpriseCourseEnrollmentFactory( enterprise_customer_user=self.enterprise_customer_user, course_id=self.course_id, consent_granted=True, ) self.integrated_channel = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=self.enterprise_customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', ) super(TestTransmitLearnerData, self).setUp()
def setUp(self): self.user = UserFactory(username='******') self.course_id = 'course-v1:edX+DemoX+DemoCourse' self.enterprise_customer = EnterpriseCustomerFactory() self.enterprise_customer_user = EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=self.enterprise_customer, ) config = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=self.enterprise_customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', active=True, ) self.exporter = config.get_learner_data_exporter('dummy-user') assert isinstance(self.exporter, BaseLearnerExporter) super(TestBaseLearnerExporter, self).setUp()
def setUp(self): super(TestSuccessFactorsLearnerDataTransmitter, self).setUp() SAPSuccessFactorsGlobalConfiguration.objects.create( completion_status_api_path="", course_api_path="", oauth_api_path="") self.enterprise_config = SAPSuccessFactorsEnterpriseCustomerConfiguration( key="client_id", sapsf_base_url="http://test.successfactors.com/", sapsf_company_id="company_id", sapsf_user_id="user_id", secret="client_secret")
def setUp(self): """ Set up test environment. """ super(TestSAPSuccessFactorsUtils, self).setUp() faker = FakerFactory.create() self.user = UserFactory() self.uuid = faker.uuid4() # pylint: disable=no-member self.customer = EnterpriseCustomerFactory(uuid=self.uuid) self.enterprise_configuration = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=self.customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', )
def setUp(self): super(TestSuccessFactorsCourseTransmitter, self).setUp() SAPSuccessFactorsGlobalConfiguration.objects.create( completion_status_api_path="", course_api_path="", oauth_api_path="") enterprise_customer = EnterpriseCustomerFactory( name='Starfleet Academy', ) self.enterprise_config = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=enterprise_customer, key="client_id", sapsf_base_url="http://test.successfactors.com/", sapsf_company_id="company_id", sapsf_user_id="user_id", secret="client_secret") self.payload = [{'course1': 'test1'}, {'course2': 'test2'}]
def setUp(self): super(TestSAPSuccessFactorsAPIClient, self).setUp() self.oauth_api_path = "learning/oauth-api/rest/v1/token" self.completion_status_api_path = "learning/odatav4/public/admin/ocn/v1/current-user/item/learning-event" self.course_api_path = "learning/odatav4/public/admin/ocn/v1/OcnCourses" self.url_base = "http://test.successfactors.com/" self.client_id = "client_id" self.client_secret = "client_secret" self.company_id = "company_id" self.user_id = "user_id" self.user_type = "user" self.expires_in = 1800 self.access_token = "access_token" self.content_payload = { "ocnCourses": [ { "courseID": "TED1", "providerID": "TED", "status": "ACTIVE", "title": [ { "locale": "English", "value": "Can a computer write poetry?" } ] } ] } SAPSuccessFactorsGlobalConfiguration.objects.create( completion_status_api_path=self.completion_status_api_path, course_api_path=self.course_api_path, oauth_api_path=self.oauth_api_path ) self.expected_token_response_body = {"expires_in": self.expires_in, "access_token": self.access_token} self.enterprise_config = SAPSuccessFactorsEnterpriseCustomerConfiguration( key=self.client_id, sapsf_base_url=self.url_base, sapsf_company_id=self.company_id, sapsf_user_id=self.user_id, secret=self.client_secret )
class TestSAPSuccessFactorsEnterpriseCustomerConfiguration(unittest.TestCase): """ Tests of the SAPSuccessFactorsEnterpriseCustomerConfiguration model. """ def setUp(self): self.enterprise_customer = EnterpriseCustomerFactory(name="GriffCo") self.config = SAPSuccessFactorsEnterpriseCustomerConfiguration( enterprise_customer=self.enterprise_customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', active=False, ) super(TestSAPSuccessFactorsEnterpriseCustomerConfiguration, self).setUp() @ddt.data( str, repr ) def test_string_conversion(self, method): """ Test ``SAPSuccessFactorsEnterpriseCustomerConfiguration`` conversion to string """ expected_to_str = "<SAPSuccessFactorsEnterpriseCustomerConfiguration for Enterprise {}>".format( self.enterprise_customer.name ) assert expected_to_str == method(self.config) def test_channel_code(self): assert self.config.channel_code() == 'SAP' @mock.patch('integrated_channels.sap_success_factors.transmitters.SAPSuccessFactorsAPIClient') @mock.patch( 'integrated_channels.sap_success_factors.transmitters.learner_data.SuccessFactorsLearnerDataTransmitter') @mock.patch('integrated_channels.integrated_channel.learner_data.CertificatesApiClient') @mock.patch('integrated_channels.integrated_channel.learner_data.CourseApiClient') @mock.patch('enterprise.lms_api.JwtBuilder', mock.Mock()) def test_transmit_learner_data(self, mock_course_api, mock_certificate, mock_transmitter, mock_sap_client): user = UserFactory() course_id = 'course-v1:edX+DemoX+DemoCourse' enterprise_customer_user = EnterpriseCustomerUserFactory( user_id=user.id, enterprise_customer=self.enterprise_customer, ) enrollment = EnterpriseCourseEnrollmentFactory( enterprise_customer_user=enterprise_customer_user, course_id=course_id, consent_granted=True, ) # Mock instructor-paced course details mock_course_api.return_value.get_course_details.return_value = dict( pacing='instructor' ) # Return a mock certificate certificate = dict( user=user, course_id=course_id, grade="A-", is_passing=True, created_date='2017-01-02T03:04:05:00Z' ) mock_certificate.return_value.get_course_certificate.return_value = certificate transmission_audit = LearnerDataTransmissionAudit( enterprise_course_enrollment_id=enrollment.id, sapsf_user_id=None, course_id=enrollment.course_id, course_completed=True, completed_timestamp=1483326245000, grade='A-', ) mock_sap_client.get_oauth_access_token.return_value = "token", datetime.datetime.utcnow() mock_transmitter_instance = mock_transmitter.return_value mock_transmitter.transmit.return_value = transmission_audit # Ensure an inactive config doesn't transmit anything. self.config.transmit_learner_data('dummy-user') assert not mock_transmitter_instance.transmit.called # Test that an active config transmits the expected data record self.config.active = True self.config.transmit_learner_data('dummy-user') assert mock_transmitter_instance.transmit.called_with(transmission_audit)