def test_nested_leaves(self): """ Test that nested leaves are not imported. """ template = """ <course org="DevOps" course="0.001" url_name="2015_Summer" semester="2015_Summer"> <chapter> <sequential> <vertical> <{tag}><{tag}></{tag}></{tag}> </vertical> </sequential> </chapter> </course> """ for tag in ("html", "problem", "discussion", "video"): repo = create_repo( "{tag}_repo".format(tag=tag), "...", self.user.id) xml = etree.fromstring(template.format(tag=tag)) bundle = XBundle( keep_urls=True, keep_studio_urls=True, preserve_url_name=True ) bundle.set_course(xml) import_course(bundle, repo.id, self.user.id, "") self.assertEqual( LearningResource.objects.filter( learning_resource_type__name=tag ).count(), 1 )
def test_parent_preview_link(self): """ Test that if url_name is blank we import the parent's url_name when viewing the preview link. """ xml = """ <course org="DevOps" course="0.001" url_name="2015_Summer" semester="2015_Summer"> <chapter> <sequential> <vertical> <html></html> </vertical> </sequential> </chapter> </course> """ repo = create_repo("html_repo", "...", self.user.id) xml = etree.fromstring(xml) bundle = XBundle( keep_urls=True, keep_studio_urls=True, preserve_url_name=True ) bundle.set_course(xml) import_course(bundle, repo.id, self.user.id, "") html_resources = LearningResource.objects.filter( learning_resource_type__name="html" ) self.assertEqual(html_resources.count(), 1) html_resource = html_resources.first() self.assertEqual( get_preview_url(html_resource), "{base}courses/{org}/{course}/{run}/jump_to_id/{url_path}".format( base=settings.LORE_PREVIEW_BASE_URL, org=html_resource.course.org, course=html_resource.course.course_number, run=html_resource.course.run, url_path="2015_Summer" ) )