def test_update_course_ddt(self, course, provider_id, global_context, expected_course): """ Test update_course method of EnterpriseCatalogCoursesReadOnlySerializer. Verify that update_course for EnterpriseCatalogCoursesReadOnlySerializer returns successfully without errors. """ enterprise_customer_id = 'd2fb4cb0-b538-4934-1926-684d48ff5865' ecu = factories.EnterpriseCustomerUserFactory( enterprise_customer__uuid=enterprise_customer_id, user_id=self.user.id, ) factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=ecu.enterprise_customer, provider_id=provider_id, ) with mock.patch('enterprise.utils.reverse', return_value='course_modes/choose/'): updated_course = self.serializer.update_course( course, 1, ecu.enterprise_customer, global_context) # Make sure global context passed in to update_course is added to the course. for key, value in six.iteritems(global_context): assert key in updated_course assert updated_course[key] == value assert expected_course == updated_course
def setUp(self): self.user = factories.UserFactory(username='******', id=1) self.course_id = 'course-v1:edX+DemoX+DemoCourse' self.course_key = 'edX+DemoX' self.enterprise_customer = factories.EnterpriseCustomerFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=self.enterprise_customer, ) self.data_sharing_consent = factories.DataSharingConsentFactory( username=self.user.username, course_id=self.course_id, enterprise_customer=self.enterprise_customer, granted=True, ) self.config = factories.SAPSuccessFactorsEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, sapsf_base_url='enterprise.successfactors.com', key='key', secret='secret', active=True, ) self.idp = factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=self.enterprise_customer ) tpa_client_mock = mock.patch('enterprise.models.ThirdPartyAuthApiClient') self.tpa_client = tpa_client_mock.start().return_value # Default remote ID self.tpa_client.get_remote_id.return_value = 'fake-remote-id' self.addCleanup(tpa_client_mock.stop) self.exporter = self.config.get_learner_data_exporter('dummy-user') assert isinstance(self.exporter, LearnerExporter) super(TestLearnerExporter, self).setUp()
def setUp(self): self.user = factories.UserFactory(username='******', id=1, email='*****@*****.**') self.course_id = 'course-v1:edX+DemoX+DemoCourse' self.enterprise_customer = factories.EnterpriseCustomerFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=self.enterprise_customer, ) self.data_sharing_consent = factories.DataSharingConsentFactory( username=self.user.username, course_id=self.course_id, enterprise_customer=self.enterprise_customer, granted=True, ) self.config = factories.DegreedEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, active=True, ) self.idp = factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=self.enterprise_customer) tpa_client_mock = mock.patch( 'enterprise.models.ThirdPartyAuthApiClient') self.tpa_client = tpa_client_mock.start() self.tpa_client.return_value.get_remote_id.return_value = 'fake-remote-id' self.addCleanup(tpa_client_mock.stop) super(TestDegreedLearnerExporter, self).setUp()
def _setup_enterprise_enrollment(self, user, course_id, course_key): """ Create enterprise enrollment for user in given course """ enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=user.id, enterprise_customer=self.enterprise_customer, ) factories.DataSharingConsentFactory( username=user.username, course_id=course_id, enterprise_customer=self.enterprise_customer, granted=True, ) enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( enterprise_customer_user=enterprise_customer_user, course_id=course_id, ) factories.CornerstoneLearnerDataTransmissionAuditFactory( user_id=user.id, session_token=self.session_token, callback_url=self.callback_url, subdomain=self.subdomain, course_id=course_key, user_guid=self.user_guid) return enterprise_course_enrollment
def setUp(self): super(TestLearnerInfoSerializer, self).setUp() self.user = factories.UserFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( user_id=self.user.id) # pylint: disable=invalid-name self.enterprise_customer_identity_provider = factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=self.enterprise_customer_user. enterprise_customer) self.expected_data = { 'enterprise_sso_uid': TEST_ENTERPRISE_SSO_UID, 'lms_user_id': self.user.id, 'enterprise_user_id': self.enterprise_customer_user.id, 'user_username': self.user.username, 'user_account_creation_date': self.user.date_joined.strftime("%Y-%m-%dT%H:%M:%SZ"), 'user_country_code': 'PK', 'user_email': self.user.email }
def test_enterprise_catalog_courses(self, url, provider_id, enterprise_customer, mocked_catalog_courses, expected): """ Make sure enterprise catalog view returns correct data. Arguments: mocked_catalog_courses: This is used to mock catalog courses returned by catalog api. expected: This is the expected catalog courses from enterprise api. """ # Populate database ecu = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer__uuid=enterprise_customer, ) factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=ecu.enterprise_customer, provider_id=provider_id, ) with mock.patch('enterprise.api.v1.views.CourseCatalogApiClient' ) as mock_catalog_api_client: mock_catalog_api_client.return_value = mock.Mock( get_paginated_catalog_courses=mock.Mock( return_value=mocked_catalog_courses), ) response = self.client.get(url) response = self.load_json(response.content) assert response == expected
def setUp(self): super(TestUserFilterBackend, self).setUp() self.enterprise_customer = factories.EnterpriseCustomerFactory( uuid=FAKE_UUIDS[0]) self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer, user_id=self.user.id, )
def test_get_learner_data_record_not_exist(self): """ If learner data is not already exist, nothing is returned. """ exporter = CornerstoneLearnerExporter('fake-user', self.config) enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( enterprise_customer_user=factories.EnterpriseCustomerUserFactory( user_id=self.other_user.id, enterprise_customer=self.enterprise_customer, ), course_id=self.course_id, ) assert exporter.get_learner_data_records(enterprise_course_enrollment) is None
def test_has_explicit_access(self, permission, feature_role, get_current_request_mock): get_current_request_mock.return_value = self.get_request_with_jwt_cookie( ) feature_role_object, __ = EnterpriseFeatureRole.objects.get_or_create( name=feature_role) enterprise_customer = factories.EnterpriseCustomerFactory( uuid=TEST_UUID) factories.EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=enterprise_customer) EnterpriseFeatureUserRoleAssignment.objects.create( user=self.user, role=feature_role_object) assert self.user.has_perm(permission, TEST_UUID)
def setUp(self): super().setUp() self.user.is_superuser = True self.user.save() self.enterprise_customer = factories.EnterpriseCustomerFactory( uuid=FAKE_UUIDS[0]) self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer, user_id=self.user.id, ) self.enterprise_customer_conf = factories.BlackboardEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, )
def setUp(self): super().setUp() self.set_jwt_cookie(self.client, [(ENTERPRISE_ADMIN_ROLE, ENTERPRISE_ID)]) self.client.force_authenticate(user=self.user) self.enterprise_customer = factories.EnterpriseCustomerFactory(uuid=ENTERPRISE_ID) self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer, user_id=self.user.id, ) self.moodle_config = factories.MoodleEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer )
def setUp(self): """ Perform operations common for all tests. Populate data base for api testing. """ super(TestEnterpriseAPIThrottling, self).setUp() user = factories.UserFactory() enterprise_customer = factories.EnterpriseCustomerFactory() factories.EnterpriseCustomerUserFactory( enterprise_customer=enterprise_customer, user_id=user.id) self.url = settings.TEST_SERVER + reverse('enterprise-customer-list')
def setUp(self): """ Perform operations common for all tests. Populate data base for api testing. """ super(TestEnterpriseCustomerUserFilterBackend, self).setUp() self.test_user = factories.UserFactory(username=self.username, email=self.email, is_active=True) enterprise_customer = factories.EnterpriseCustomerFactory() factories.EnterpriseCustomerUserFactory( enterprise_customer=enterprise_customer, user_id=self.test_user.id) self.url = settings.TEST_SERVER + reverse('enterprise-learner-list')
def setUp(self): super().setUp() self.global_config = factories.SAPSuccessFactorsGlobalConfigurationFactory( ) self.enterprise_customer = factories.EnterpriseCustomerFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer) self.enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( id=5, enterprise_customer_user=self.enterprise_customer_user) self.enterprise_config = factories.SAPSuccessFactorsEnterpriseCustomerConfigurationFactory( enterprise_customer=self.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.payloads = [ SapSuccessFactorsLearnerDataTransmissionAudit( enterprise_course_enrollment_id=self. enterprise_course_enrollment.id, sapsf_user_id='sap_user', course_id='course-v1:edX+DemoX+DemoCourse', course_completed=True, completed_timestamp=1486855998, instructor_name='Professor Professorson', grade='Passing even more', error_message='', ) ] self.exporter = lambda payloads=self.payloads: mock.MagicMock( export=mock.MagicMock(return_value=iter(payloads))) # Mocks get_oauth_access_token_mock = mock.patch( 'integrated_channels.sap_success_factors.client.SAPSuccessFactorsAPIClient.get_oauth_access_token' ) self.get_oauth_access_token_mock = get_oauth_access_token_mock.start() self.get_oauth_access_token_mock.return_value = "token", datetime.datetime.utcnow( ) self.addCleanup(get_oauth_access_token_mock.stop) create_course_completion_mock = mock.patch( 'integrated_channels.sap_success_factors.client.SAPSuccessFactorsAPIClient.create_course_completion' ) self.create_course_completion_mock = create_course_completion_mock.start( ) self.addCleanup(create_course_completion_mock.stop)
def setUp(self): super().setUp() self.enterprise_customer = factories.EnterpriseCustomerFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer, ) self.enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( id=5, enterprise_customer_user=self.enterprise_customer_user, ) self.enterprise_config = factories.MoodleEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, moodle_base_url='foobar', service_short_name='shortname', category_id=1, username='******', password='******', token='token', ) self.payload = MoodleLearnerDataTransmissionAudit( moodle_user_email=self.enterprise_customer.contact_email, enterprise_course_enrollment_id=self.enterprise_course_enrollment. id, course_id='course-v1:edX+DemoX+DemoCourse', course_completed=True, completed_timestamp=1486855998, total_hours=1.0, grade=.9, ) self.exporter = lambda payloads=self.payload: mock.MagicMock( export=mock.MagicMock(return_value=iter(payloads))) # Mocks create_course_completion_mock = mock.patch( 'integrated_channels.moodle.client.MoodleAPIClient.create_course_completion' ) self.create_course_completion_mock = create_course_completion_mock.start( ) self.addCleanup(create_course_completion_mock.stop) self.create_course_completion_mock = create_course_completion_mock.start( ) self.addCleanup(create_course_completion_mock.stop)
def setUp(self): super(TestBlackboardLearnerDataTransmitter, self).setUp() self.enterprise_customer = factories.EnterpriseCustomerFactory() self.enterprise_customer_user = factories.EnterpriseCustomerUserFactory( enterprise_customer=self.enterprise_customer, ) self.enterprise_course_enrollment = factories.EnterpriseCourseEnrollmentFactory( id=5, enterprise_customer_user=self.enterprise_customer_user, ) self.enterprise_config = factories.BlackboardEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, blackboard_base_url='foobar', client_id='client_id', client_secret='client_secret', refresh_token='token', ) self.payload = BlackboardLearnerDataTransmissionAudit( blackboard_user_email=self.enterprise_customer.contact_email, enterprise_course_enrollment_id=self.enterprise_course_enrollment. id, course_id='course-v1:edX+DemoX+DemoCourse', course_completed=True, completed_timestamp=1486855998, total_hours=1.0, grade=.9, ) self.exporter = lambda payloads=self.payload: mock.MagicMock( export=mock.MagicMock(return_value=iter(payloads))) # Mocks create_course_completion_mock = mock.patch( 'integrated_channels.blackboard.client.BlackboardAPIClient.create_course_completion' ) self.create_course_completion_mock = create_course_completion_mock.start( ) self.addCleanup(create_course_completion_mock.stop) self.create_course_completion_mock = create_course_completion_mock.start( ) self.addCleanup(create_course_completion_mock.stop)
def test_filter(self, is_staff, is_linked_to_enterprise, has_access): self.user.is_staff = is_staff self.user.save() if is_linked_to_enterprise: factories.EnterpriseCustomerUserFactory( user_id=self.user.id, enterprise_customer=self.enterprise_customer, ) response = self.client.get(self.url) response = self.load_json(response.content) if has_access: enterprise_customer_response = response['results'][0] for key, value in self.enterprise_customer_data.items(): assert enterprise_customer_response[key] == value else: assert response == { 'count': 0, 'next': None, 'previous': None, 'results': [] }
def test_learner_data_multiple_courses( self, pacing, grade, mock_course_catalog_api, mock_course_api, mock_grades_api, mock_certificate_api, mock_enrollment_api ): mock_course_catalog_api.return_value.get_course_id.return_value = self.course_key enrollment1 = factories.EnterpriseCourseEnrollmentFactory( enterprise_customer_user=self.enterprise_customer_user, course_id=self.course_id, ) course_id2 = 'course-v1:edX+DemoX+DemoCourse2' enrollment2 = factories.EnterpriseCourseEnrollmentFactory( enterprise_customer_user=self.enterprise_customer_user, course_id=course_id2, ) factories.DataSharingConsentFactory( username=self.enterprise_customer_user.username, course_id=course_id2, enterprise_customer=self.enterprise_customer, granted=True ) enrollment3 = factories.EnterpriseCourseEnrollmentFactory( enterprise_customer_user=factories.EnterpriseCustomerUserFactory( user_id=factories.UserFactory(username='******', id=2).id, enterprise_customer=self.enterprise_customer, ), course_id=self.course_id, ) factories.DataSharingConsentFactory( username='******', course_id=self.course_id, enterprise_customer=self.enterprise_customer, granted=True ) def get_course_details(course_id): """ Mock course details - set course_id to match input """ return dict( pacing=pacing, course_id=course_id ) mock_course_api.return_value.get_course_details.side_effect = get_course_details def get_course_certificate(course_id, username): """ Mock certificate data - return depending on course_id """ if '2' in course_id: return dict( username=username, is_passing=True, grade=grade, ) raise HttpNotFoundError mock_certificate_api.return_value.get_course_certificate.side_effect = get_course_certificate def get_course_grade(course_id, username): """ Mock grades data - set passed depending on course_id """ return dict( passed='2' in course_id, course_key=course_id, username=username, ) mock_grades_api.return_value.get_course_grade.side_effect = get_course_grade # Mock enrollment data mock_enrollment_api.return_value.get_course_enrollment.return_value = dict( mode="verified" ) # Collect the learner data, with time set to NOW with freeze_time(self.NOW): learner_data = list(self.exporter.export()) assert len(learner_data) == 6 assert learner_data[0].course_id == self.course_key assert learner_data[1].course_id == self.course_id for report1 in learner_data[0:1]: assert report1.enterprise_course_enrollment_id == enrollment1.id assert not report1.course_completed assert report1.completed_timestamp is None assert report1.grade == LearnerExporter.GRADE_INCOMPLETE assert learner_data[2].course_id == self.course_key assert learner_data[3].course_id == self.course_id for report2 in learner_data[2:3]: assert report2.enterprise_course_enrollment_id == enrollment3.id assert not report2.course_completed assert report2.completed_timestamp is None assert report2.grade == LearnerExporter.GRADE_INCOMPLETE assert learner_data[4].course_id == self.course_key assert learner_data[5].course_id == course_id2 for report3 in learner_data[4:5]: assert report3.enterprise_course_enrollment_id == enrollment2.id # assert report3.course_id == course_id2 assert report3.course_completed assert report3.completed_timestamp == self.NOW_TIMESTAMP assert report3.grade == grade
def setUp(self): """ Perform operations common for all tests. Populate data base for api testing. """ super(TestEnterpriseCatalogCoursesSerializer, self).setUp() faker = FakerFactory.create() self.provider_id = faker.slug() self.user = factories.UserFactory() self.ecu = factories.EnterpriseCustomerUserFactory( user_id=self.user.id, ) factories.EnterpriseCustomerIdentityProviderFactory( enterprise_customer=self.ecu.enterprise_customer, provider_id=self.provider_id, ) # Create and authenticate a request self.request = APIRequestFactory().get(reverse('catalogs-list')) self.request.user = self.user # instance is none as models for this serializer do not exist in enterprise. self.instance = None self.data = { 'count': 1, 'next': None, 'previous': None, 'results': [{ 'owners': [{ 'description': None, 'tags': [], 'name': '', 'homepage_url': None, 'key': 'edX', 'certificate_logo_image_url': None, 'marketing_url': None, 'logo_image_url': None, 'uuid': 'aa4aaad0-2ff0-44ce-95e5-1121d02f3b27' }], 'uuid': 'd2fb4cb0-b538-4934-ba60-684d48ff5865', 'title': 'edX Demonstration Course', 'prerequisites': [], 'image': None, 'expected_learning_items': [], 'sponsors': [], 'modified': '2017-03-03T07:34:19.322916Z', 'full_description': None, 'subjects': [], 'video': None, 'key': 'edX+DemoX', 'short_description': None, 'marketing_url': 'http://testserver/course/course-v1:edX+DemoX+1T2017/', 'level_type': None, 'course_runs': [{ 'key': 'course-v1:edX+DemoX+1T2017', 'uuid': '57432370-0a6e-4d95-90fe-77b4fe64de2b', 'title': 'edX Demonstration Course', 'image': { 'width': None, 'src': 'http://testserver/image/promoted/screen_shot_2016-12-27_at_9.30.00_am.png', 'description': None, 'height': None }, 'short_description': 'edX Demonstration Course', 'marketing_url': 'http://testserver/course/course-edx-d103?utm_medium=affiliate_partner', 'start': '2016-12-28T05:00:00Z', 'end': '2018-12-28T00:00:00Z', 'enrollment_start': None, 'enrollment_end': None, 'pacing_type': 'instructor_paced', 'type': 'audit', 'course': 'edx+D103', 'full_description': 'edx demo course', 'announcement': None, 'video': None, 'seats': [{ 'type': 'audit', 'price': '0.00', 'currency': 'USD', 'upgrade_deadline': None, 'credit_provider': None, 'credit_hours': None, 'sku': '2ADB190' }], 'content_language': 'en-us', 'transcript_languages': [], 'instructors': [], 'staff': [], 'min_effort': None, 'max_effort': None, 'modified': '2017-03-08T05:46:52.682549Z', 'level_type': 'Introductory', 'availability': 'Current', 'mobile_available': False, 'hidden': False, 'reporting_type': 'mooc' }] }] } self.validated_data = self.data self.serializer = EnterpriseCatalogCoursesReadOnlySerializer(self.data)
def setUp(self): super(TestEnterpriseCustomerUserFilterBackend, self).setUp() enterprise_customer = factories.EnterpriseCustomerFactory() factories.EnterpriseCustomerUserFactory( enterprise_customer=enterprise_customer, user_id=self.user.id) self.url = settings.TEST_SERVER + reverse('enterprise-learner-list')
def setUp(self): self.api_user = factories.UserFactory(username='******', id=1) self.user1 = factories.UserFactory(id=2, email='*****@*****.**') self.user2 = factories.UserFactory(id=3, email='*****@*****.**') self.course_id = COURSE_ID self.enterprise_customer = factories.EnterpriseCustomerFactory( name='Spaghetti Enterprise') self.identity_provider = FakerFactory.create().slug() # pylint: disable=no-member factories.EnterpriseCustomerIdentityProviderFactory( provider_id=self.identity_provider, enterprise_customer=self.enterprise_customer, ) self.enterprise_customer_user1 = factories.EnterpriseCustomerUserFactory( user_id=self.user1.id, enterprise_customer=self.enterprise_customer, ) self.enterprise_customer_user2 = factories.EnterpriseCustomerUserFactory( user_id=self.user2.id, enterprise_customer=self.enterprise_customer, ) self.enrollment = factories.EnterpriseCourseEnrollmentFactory( id=2, enterprise_customer_user=self.enterprise_customer_user1, course_id=self.course_id, ) self.enrollment = factories.EnterpriseCourseEnrollmentFactory( id=3, enterprise_customer_user=self.enterprise_customer_user2, course_id=self.course_id, ) self.consent1 = factories.DataSharingConsentFactory( username=self.user1.username, course_id=self.course_id, enterprise_customer=self.enterprise_customer, ) self.consent2 = factories.DataSharingConsentFactory( username=self.user2.username, course_id=self.course_id, enterprise_customer=self.enterprise_customer, ) self.degreed = factories.DegreedEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, key='key', secret='secret', degreed_company_id='Degreed Company', active=True, ) self.degreed_global_configuration = factories.DegreedGlobalConfigurationFactory( degreed_base_url='https://www.degreed.com/', oauth_api_path='oauth/token', ) self.sapsf = factories.SAPSuccessFactorsEnterpriseCustomerConfigurationFactory( enterprise_customer=self.enterprise_customer, sapsf_base_url='http://enterprise.successfactors.com/', key='key', secret='secret', active=True, ) self.sapsf_global_configuration = factories.SAPSuccessFactorsGlobalConfigurationFactory( ) super(TestTransmitLearnerData, self).setUp()