def test_rerun(self): """ Just testing the functionality the view handler adds over the tasks tested in test_clone_course """ add_organization({ 'name': 'Test Organization', 'short_name': self.source_course_key.org, 'description': 'Testing Organization Description', }) response = self.client.ajax_post( self.course_create_rerun_url, { 'source_course_key': six.text_type(self.source_course_key), 'org': self.source_course_key.org, 'course': self.source_course_key.course, 'run': 'copy', 'display_name': 'not the same old name', }) self.assertEqual(response.status_code, 200) data = parse_json(response) dest_course_key = CourseKey.from_string(data['destination_course_key']) self.assertEqual(dest_course_key.run, 'copy') source_course = self.store.get_course(self.source_course_key) dest_course = self.store.get_course(dest_course_key) self.assertEqual(dest_course.start, CourseFields.start.default) self.assertEqual(dest_course.end, source_course.end) self.assertEqual(dest_course.enrollment_start, None) self.assertEqual(dest_course.enrollment_end, None) course_orgs = get_course_organizations(dest_course_key) self.assertEqual(len(course_orgs), 1) self.assertEqual(course_orgs[0]['short_name'], self.source_course_key.org)
def setUp(self): super(TestOrganizationListing, self).setUp() self.staff = UserFactory(is_staff=True) self.client.login(username=self.staff.username, password='******') self.org_names_listing_url = reverse('organizations') self.org_short_names = ["alphaX", "betaX", "orgX"] for index, short_name in enumerate(self.org_short_names): add_organization(organization_data={ 'name': 'Test Organization %s' % index, 'short_name': short_name, 'description': 'Testing Organization %s Description' % index, })
def test_rerun(self, pacing_type, expected_self_paced_value, number): original_course_run = ToyCourseFactory() add_organization({ 'name': 'Test Organization', 'short_name': original_course_run.id.org, 'description': 'Testing Organization Description', }) start = datetime.datetime.now(pytz.UTC).replace(microsecond=0) end = start + datetime.timedelta(days=30) user = UserFactory() role = 'instructor' run = '3T2017' url = reverse('api:v1:course_run-rerun', kwargs={'pk': str(original_course_run.id)}) data = { 'run': run, 'schedule': { 'start': serialize_datetime(start), 'end': serialize_datetime(end), }, 'team': [{ 'user': user.username, 'role': role, }], 'pacing_type': pacing_type, } # If number is supplied, this should become the course number used in the course run key # If not, it should default to the original course run number that the rerun is based on. if number: data.update({'number': number}) response = self.client.post(url, data, format='json') assert response.status_code == 201 course_run_key = CourseKey.from_string(response.data['id']) course_run = modulestore().get_course(course_run_key) assert course_run.id.run == run assert course_run.self_paced is expected_self_paced_value if number: assert course_run.id.course == number assert course_run.id.course != original_course_run.id.course else: assert course_run.id.course == original_course_run.id.course self.assert_course_run_schedule(course_run, start, end) self.assert_access_role(course_run, user, role) self.assert_course_access_role_count(course_run, 1) course_orgs = get_course_organizations(course_run_key) self.assertEqual(len(course_orgs), 1) self.assertEqual(course_orgs[0]['short_name'], original_course_run.id.org)
def setUp(self): super(TestOrganizationListing, self).setUp() self.staff = UserFactory(is_staff=True) self.client.login(username=self.staff.username, password='******') self.org_names_listing_url = reverse('organizations') self.org_short_names = ["alphaX", "betaX", "orgX"] for index, short_name in enumerate(self.org_short_names): add_organization( organization_data={ 'name': u'Test Organization %s' % index, 'short_name': short_name, 'description': u'Testing Organization %s Description' % index, })
def test_rendering_course_organization_data(self): """ Test: organization data should render on certificate web view if course has organization. """ test_organization_data = { 'name': 'test organization', 'short_name': 'test_organization', 'description': 'Test Organization Description', 'active': True, 'logo': '/logo_test1.png/' } test_org = organizations_api.add_organization(organization_data=test_organization_data) organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id)) self._add_course_certificates(count=1, signatory_count=1, is_active=True) test_url = get_certificate_url( user_id=self.user.id, course_id=unicode(self.course.id) ) response = self.client.get(test_url) self.assertIn( 'a course of study offered by test_organization, an online learning initiative of test organization', response.content ) self.assertNotIn( 'a course of study offered by testorg', response.content ) self.assertIn( '<title>test_organization {} Certificate |'.format(self.course.number, ), response.content ) self.assertIn('logo_test1.png', response.content)
def test_enterprise_learner_context_with_multiple_organizations(self): """ Test: Track selection page should show the enterprise context message with multiple organization names if user belongs to the Enterprise. """ url = self._generate_enterprise_learner_context() # Creating organization for i in xrange(2): test_organization_data = { 'name': 'test organization ' + str(i), 'short_name': 'test_organization_' + str(i), 'description': 'Test Organization Description', 'active': True, 'logo': '/logo_test1.png/' } test_org = organizations_api.add_organization(organization_data=test_organization_data) organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id)) # User visits the track selection page directly without ever enrolling response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertContains( response, 'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and ' 'test organization 1, sponsored by TestShib. Please select your enrollment information below.'.format( username=self.user.username, course_name=self.course.display_name_with_default_escaped ) )
def setUp(self): super(TestOrganizationListing, self).setUp() self.staff = UserFactory(is_staff=True) self.client.login(username=self.staff.username, password='******') self.org_names_listing_url = reverse('organizations') self.org_short_names = ["alphaX", "betaX", "orgX"] for index, short_name in enumerate(self.org_short_names): add_organization( organization_data={ 'name': 'Test Organization %s' % index, 'short_name': short_name, 'description': 'Testing Organization %s Description' % index, }) # EDUNEXT: Organizations list must not be visible for users, reason why an empty array is set self.org_short_names = []
def test_get_organization_by_short_name_when_app_enabled(self): """ Tests get_organization_by_short_name api when app is enabled. """ response = organizations_helpers.add_organization(organization_data=self.organization) self.assertIsNotNone(response['id']) response = organizations_helpers.get_organization_by_short_name(self.organization['short_name']) self.assertIsNotNone(response['id']) # fetch non existing org response = organizations_helpers.get_organization_by_short_name('non_existing') self.assertIsNone(response)
def test_course_creation_with_org_in_system(self, store): """ Tests course creation workflow when course organization exist in system. """ add_organization({ 'name': 'Test Organization', 'short_name': 'orgX', 'description': 'Testing Organization Description', }) with modulestore().default_store(store): response = self.client.ajax_post(self.course_create_rerun_url, { 'org': 'orgX', 'number': 'CS101', 'display_name': 'Course with web certs enabled', 'run': '2015_T2' }) self.assertEqual(response.status_code, 200) data = parse_json(response) new_course_key = CourseKey.from_string(data['course_key']) course_orgs = get_course_organizations(new_course_key) self.assertEqual(len(course_orgs), 1) self.assertEqual(course_orgs[0]['short_name'], 'orgX')
def test_get_organization_by_short_name_when_app_enabled(self): """ Tests get_organization_by_short_name api when app is enabled. """ response = organizations_helpers.add_organization( organization_data=self.organization) self.assertIsNotNone(response['id']) response = organizations_helpers.get_organization_by_short_name( self.organization['short_name']) self.assertIsNotNone(response['id']) # fetch non existing org response = organizations_helpers.get_organization_by_short_name( 'non_existing') self.assertIsNone(response)
def test_enterprise_learner_context_with_multiple_organizations(self): """ Test: Track selection page should show the enterprise context message with multiple organization names if user belongs to the Enterprise. """ # Create the course modes for mode in ('audit', 'honor', 'verified'): CourseModeFactory.create(mode_slug=mode, course_id=self.course.id) self.mock_enterprise_learner_api() # Create a service user and log in. UserFactory.create( username='******', email="*****@*****.**", password="******", ) # Creating organization for i in xrange(2): test_organization_data = { 'name': 'test organization ' + str(i), 'short_name': 'test_organization_' + str(i), 'description': 'Test Organization Description', 'active': True, 'logo': '/logo_test1.png/' } test_org = organizations_api.add_organization( organization_data=test_organization_data) organizations_api.add_organization_course( organization_data=test_org, course_id=unicode(self.course.id)) # User visits the track selection page directly without ever enrolling url = reverse('course_modes_choose', args=[unicode(self.course.id)]) response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertContains( response, 'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and ' 'test organization 1, sponsored by TestShib. Please select your enrollment information below.' .format(username=self.user.username, course_name=self.course.display_name_with_default_escaped))
def test_enterprise_learner_context_with_multiple_organizations(self): """ Test: Track selection page should show the enterprise context message with multiple organization names if user belongs to the Enterprise. """ # Create the course modes for mode in ('audit', 'honor', 'verified'): CourseModeFactory.create(mode_slug=mode, course_id=self.course.id) self.mock_enterprise_learner_api() self.mock_course_discovery_api_for_catalog_contains( catalog_id=1, course_run_ids=[str(self.course.id)] ) # Creating organization for i in xrange(2): test_organization_data = { 'name': 'test organization ' + str(i), 'short_name': 'test_organization_' + str(i), 'description': 'Test Organization Description', 'active': True, 'logo': '/logo_test1.png/' } test_org = organizations_api.add_organization(organization_data=test_organization_data) organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id)) # User visits the track selection page directly without ever enrolling url = reverse('course_modes_choose', args=[unicode(self.course.id)]) response = self.client.get(url) self.assertEquals(response.status_code, 200) self.assertContains( response, 'Welcome, {username}! You are about to enroll in {course_name}, from test organization 0 and ' 'test organization 1, sponsored by TestShib. Please select your enrollment information below.'.format( username=self.user.username, course_name=self.course.display_name_with_default_escaped ) )
def test_rendering_maximum_data(self): """ Tests at least one data item from different context update methods to make sure every context update method is invoked while rendering certificate template. """ long_org_name = 'Long org name' short_org_name = 'short_org_name' test_organization_data = { 'name': long_org_name, 'short_name': short_org_name, 'description': 'Test Organization Description', 'active': True, 'logo': '/logo_test1.png' } test_org = organizations_api.add_organization(organization_data=test_organization_data) organizations_api.add_organization_course(organization_data=test_org, course_id=unicode(self.course.id)) self._add_course_certificates(count=1, signatory_count=1, is_active=True) BadgeAssertionFactory.create( user=self.user, course_id=self.course_id, ) self.course.cert_html_view_overrides = { "logo_src": "/static/certificates/images/course_override_logo.png" } self.course.save() self.store.update_item(self.course, self.user.id) test_url = get_certificate_url( user_id=self.user.id, course_id=unicode(self.course.id) ) response = self.client.get(test_url, HTTP_HOST=settings.MICROSITE_TEST_HOSTNAME) # Test an item from basic info self.assertIn( 'Terms of Service & Honor Code', response.content ) self.assertIn( 'Certificate ID Number', response.content ) # Test an item from html cert configuration self.assertIn( '<a class="logo" href="http://test_microsite.localhost">', response.content ) # Test an item from course info self.assertIn( 'course_title_0', response.content ) # Test an item from user info self.assertIn( "{fullname}, you earned a certificate!".format(fullname=self.user.profile.name), response.content ) # Test an item from social info self.assertIn( "Post on Facebook", response.content ) self.assertIn( "Share on Twitter", response.content ) # Test an item from certificate/org info self.assertIn( "a course of study offered by {partner_short_name}, " "an online learning initiative of " "{partner_long_name}.".format( partner_short_name=short_org_name, partner_long_name=long_org_name, platform_name='Test Microsite' ), response.content ) # Test item from badge info self.assertIn( "Add to Mozilla Backpack", response.content ) # Test item from microsite info self.assertIn( "http://www.testmicrosite.org/about-us", response.content ) # Test course overrides self.assertIn( "/static/certificates/images/course_override_logo.png", response.content )
def test_add_organization_returns_none_when_app_disabled(self): response = organizations_helpers.add_organization(organization_data=self.organization) self.assertIsNone(response)
def test_add_organization_returns_none_when_app_disabled(self): response = organizations_helpers.add_organization( organization_data=self.organization) self.assertIsNone(response)