Beispiel #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>'
         )
Beispiel #2
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>'), []))
Beispiel #3
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>'
         )
Beispiel #4
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>'
         )
Beispiel #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>', [])
         ]))
Beispiel #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'),
             ]),
         ]))
Beispiel #7
0
 def test_get(self):
     out = self.build_manager().get('slug-1')
     self.assertEquals(
         out,
         Lesson('slug-1', LessonHeader('Lesson', '<p>Contents</p>'), [
             LessonSection('Foo', '<p>bar</p>', [
                 LessonSectionStep('Step One', [], 'true'),
                 LessonSectionStep('Step Two', [], 'false'),
             ])
         ]))
Beispiel #8
0
 def test_all(self):
     out = self.build_manager().all()
     self.assertEquals(out, [
         Lesson(
             'slug-2',
             LessonHeader(
                 'Earlier Lesson (alphabetically)', '<p>Contents</p>'), [
                     LessonSection('Foo', '<p>bar</p>', [
                         LessonSectionStep('Step One', [], 'true'),
                         LessonSectionStep('Step Two', [], 'false'),
                     ])
                 ]),
         Lesson('slug-1', LessonHeader('Lesson', '<p>Contents</p>'), [
             LessonSection('Foo', '<p>bar</p>', [
                 LessonSectionStep('Step One', [], 'true'),
                 LessonSectionStep('Step Two', [], 'false'),
             ])
         ])
     ])
Beispiel #9
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>')
Beispiel #10
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>')