예제 #1
0
 def test_lesson_missing_title(self):
     dirpath = MockDir({
         "index.yaml":
         textwrap.dedent("""\
             introduction_html: <p>hi</p>
             lessons: []
             """).encode("utf-8")
     })
     with self.assertRaisesRegex(KeyError, "title"):
         Course.load_from_path(dirpath / "index.yaml")
예제 #2
0
 def test_lesson_missing_title(self):
     dirpath = MockDir({
         'index.yaml':
         textwrap.dedent('''\
             introduction_html: <p>hi</p>
             lessons: []
             ''').encode('utf-8')
     })
     with self.assertRaisesRegex(KeyError, 'title'):
         Course.load_from_path(dirpath / 'index.yaml')
예제 #3
0
 def test_lesson_file_not_found(self):
     dirpath = MockDir({
         "index.yaml":
         textwrap.dedent("""\
             title: Title
             introduction_html: <p>hi</p>
             lessons:
                 - lesson-x
             """).encode("utf-8")
     })
     with self.assertRaisesRegex(FileNotFoundError, "lesson-x.html"):
         Course.load_from_path(dirpath / "index.yaml")
예제 #4
0
 def test_lesson_file_not_found(self):
     dirpath = MockDir({
         'index.yaml':
         textwrap.dedent('''\
             title: Title
             introduction_html: <p>hi</p>
             lessons:
                 - lesson-x
             ''').encode('utf-8'),
     })
     with self.assertRaisesRegex(FileNotFoundError, 'lesson-x.html'):
         Course.load_from_path(dirpath / 'index.yaml')
예제 #5
0
 def test_happy_path(self):
     dirpath = MockDir({
         "en/a-course/index.yaml":
         textwrap.dedent("""\
             title: Title
             introduction_html: |-
                 <p>Hi</p>
                 <p>Bye</p>
             lessons:
                 - lesson-1
                 - lesson-2
             """).encode("utf-8"),
         "en/a-course/lesson-1.html":
         (b"<header><h1>L1</h1><p>HP1</p></header>"
          b"<footer><h2>F1</h2><p>foot</p></footer>"),
         "en/a-course/lesson-2.html":
         (b"<header><h1>L2</h1><p>HP2</p></header>"
          b"<footer><h2>F2</h2><p>foot</p></footer>"),
     })
     course = Course.load_from_path(dirpath / "en" / "a-course" /
                                    "index.yaml")
     self.assertEqual(
         course,
         Course(
             slug="a-course",
             title="Title",
             locale_id="en",
             introduction_html="<p>Hi</p>\n<p>Bye</p>",
             lessons={
                 "lesson-1":
                 Lesson(
                     course,
                     "lesson-1",
                     "en",
                     header=LessonHeader("L1", "<p>HP1</p>"),
                     footer=LessonFooter("F1", "<p>foot</p>"),
                 ),
                 "lesson-2":
                 Lesson(
                     course,
                     "lesson-2",
                     "en",
                     header=LessonHeader("L2", "<p>HP2</p>"),
                     footer=LessonFooter("F2", "<p>foot</p>"),
                 ),
             },
         ),
     )
예제 #6
0
def render_lesson_list(request):
    # Make a "fake" Course to encompass Lessons
    #
    # Do not build this Course using LessonLookup: LessonLookup contains
    # "hidden" lessons; AllLessons does not.
    course = Course(title='Lessons',
                    lessons=dict((l.slug, l) for l in AllLessons))
    return _render_course(request, course, '/lessons')
예제 #7
0
 def test_parse_header_relative_img_src_with_course(self):
     result = Lesson.parse(Course('a-course'), 'a-slug', """
         <header><h1>x</h1><p><img src="./foo.png"/></p></header>
         <footer><h2>z</h2></footer>
     """)
     self.assertEquals(
         result.header.html,
         '<p><img src="//static/courses/a-course/a-slug/foo.png"></p>'
     )
예제 #8
0
 def test_parse_header_lesson_files_url_with_course(self):
     result = Lesson.parse(
         Course('a-course'), 'a-slug', """
         <header><h1>x</h1><p><i>{{LESSON_FILES_URL}}/x.csv</i></p></header>
         <footer><h2>z</h2></footer>
     """)
     self.assertEquals(
         result.header.html,
         '<p><i>https://static/courses/a-course/a-slug/x.csv</i></p>')
예제 #9
0
 def test_happy_path(self):
     dirpath = MockDir({
         'index.yaml':
         textwrap.dedent('''\
             title: Title
             introduction_html: |-
                 <p>Hi</p>
                 <p>Bye</p>
             lessons:
                 - lesson-1
                 - lesson-2
             ''').encode('utf-8'),
         'lesson-1.html': (b'<header><h1>L1</h1><p>HP1</p></header>'
                           b'<footer><h2>F1</h2><p>foot</p></footer>'),
         'lesson-2.html': (b'<header><h1>L2</h1><p>HP2</p></header>'
                           b'<footer><h2>F2</h2><p>foot</p></footer>'),
     })
     assert dirpath.name == 'root'  # we define this in 'utils'
     course = Course.load_from_path(dirpath / 'index.yaml')
     self.assertEqual(
         course,
         Course(
             slug='root',
             title='Title',
             introduction_html='<p>Hi</p>\n<p>Bye</p>',
             lessons={
                 'lesson-1':
                 Lesson(course,
                        'lesson-1',
                        header=LessonHeader('L1', '<p>HP1</p>'),
                        footer=LessonFooter('F1', '<p>foot</p>')),
                 'lesson-2':
                 Lesson(course,
                        'lesson-2',
                        header=LessonHeader('L2', '<p>HP2</p>'),
                        footer=LessonFooter('F2', '<p>foot</p>')),
             },
         ))
예제 #10
0
 def test_parse_header_lesson_files_url_with_course(self):
     result = Lesson.parse(
         Course("a-course"),
         "a-slug",
         "en",
         """
         <header><h1>x</h1><p><i>{{LESSON_FILES_URL}}/x.csv</i></p></header>
         <footer><h2>z</h2></footer>
     """,
     )
     self.assertEquals(
         result.header.html,
         "<p><i>https://files/courses/en/a-course/a-slug/x.csv</i></p>",
     )
예제 #11
0
def render_lesson_list(request, locale_id):
    # Make a "fake" Course to encompass Lessons
    #
    # Do not build this Course using LessonLookup: LessonLookup contains
    # "hidden" lessons; AllLessonsByLocale does not.
    locale_id = locale_id or request.locale_id
    try:
        lessons = AllLessonsByLocale[locale_id]
    except KeyError:
        return redirect("/lessons/en")
    course = Course(
        title="Workbench basics",
        locale_id=locale_id,
        lessons={lesson.slug: lesson
                 for lesson in lessons},
    )
    return _render_course(request, course, "/lessons/%s" % locale_id)
예제 #12
0
 def test_lesson_missing_index(self):
     dirpath = MockDir({})
     with self.assertRaisesRegex(FileNotFoundError, "index.yaml"):
         Course.load_from_path(dirpath / "index.yaml")
예제 #13
0
 def test_lesson_invalid_yaml(self):
     dirpath = MockDir({"index.yaml": b"{"})
     with self.assertRaises(yaml.YAMLError):
         Course.load_from_path(dirpath / "index.yaml")
예제 #14
0
 def test_lesson_invalid_yaml(self):
     dirpath = MockDir({
         'index.yaml': b'{',
     })
     with self.assertRaises(yaml.YAMLError):
         Course.load_from_path(dirpath / 'index.yaml')