Esempio n. 1
0
 def test_parse_invalid_step_highlight_json(self):
     with self.assertRaisesMessage(LessonParseError,
                                   'data-highlight contains invalid JSON'):
         Lesson.parse(
             'a-slug',
             '<header><h1>Lesson</h1><p>Contents</p></header><section><h2>Foo</h2><p>bar</p><ol class="steps"><li data-highlight=\'[{"type":"Foo"]\' data-test="true">1</li></ol></section>'
         )
Esempio n. 2
0
 def test_parse_no_section_title(self):
     with self.assertRaisesMessage(
             LessonParseError,
             'Lesson <section> needs a non-empty <h2> title'):
         Lesson.parse(
             'a-slug',
             '<header><h1>x</h1><p>y</p></header><section><ol class="steps"><li data-test="true">foo</li></ol></section>'
         )
Esempio n. 3
0
 def test_parse_missing_step_highlight_done(self):
     with self.assertRaisesMessage(
             LessonParseError,
             'missing data-test attribute, which must be JavaScript'):
         Lesson.parse(
             'a-slug',
             '<header><h1>Lesson</h1><p>Contents</p></header><section><h2>Foo</h2><p>bar</p><ol class="steps"><li data-highlight="[]">1</li></ol></section>'
         )
Esempio n. 4
0
 def test_parse_header_in_html_body(self):
     out = Lesson.parse(
         'a-slug',
         '<html><body><header><h1>Lesson</h1><p>p1</p><p>p2</p></header></body></html>'
     )
     self.assertEquals(
         out,
         Lesson('a-slug', LessonHeader('Lesson', '<p>p1</p><p>p2</p>'), []))
Esempio n. 5
0
 def test_parse_no_section_steps(self):
     out = Lesson.parse(
         'a-slug',
         '<header><h1>x</h1><p>y</p></header><section><h2>title</h2><ol class="not-steps"><li>foo</li></ol></section>'
     )
     self.assertEquals(
         out,
         Lesson('a-slug', LessonHeader('x', '<p>y</p>'), [
             LessonSection('title',
                           '<ol class="not-steps"><li>foo</li></ol>', [])
         ]))
Esempio n. 6
0
 def test_parse_step(self):
     out = Lesson.parse(
         'a-slug',
         '<header><h1>Lesson</h1><p>Contents</p></header><section><h2>Foo</h2><p>bar</p><ol class="steps"><li data-highlight=\'[{"type":"Foo"}]\' data-test="true">1</li></ol></section>'
     )
     self.assertEquals(
         out,
         Lesson('a-slug', LessonHeader('Lesson', '<p>Contents</p>'), [
             LessonSection('Foo', '<p>bar</p>', [
                 LessonSectionStep('1', [{
                     'type': 'Foo'
                 }], 'true'),
             ]),
         ]))
Esempio n. 7
0
 def test_parse_no_header_title(self):
     with self.assertRaisesMessage(
             LessonParseError,
             'Lesson <header> needs a non-empty <h1> title'):
         Lesson.parse('a-slug', '<header><p>Contents</p></header>')
Esempio n. 8
0
 def test_parse_no_header(self):
     with self.assertRaisesMessage(
             LessonParseError, 'Lesson HTML needs a top-level <header>'):
         Lesson.parse('a-slug', '<h1>Foo</h1><p>body</p>')