def test_add_lesson_at_the_end_of_unit(self): io.add_lesson_to_unit(self.unit_2_path, 'Python Lists', 'reading') # Postconditions self.assertDirectoryIsNotEmpty(self.unit_2_path) lesson_path = self.unit_2_path / 'lesson-2-python-lists' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'Python Lists') self.assertFileExists(readme_path)
def test_add_assignment_lesson_to_empty_unit(self): io.add_lesson_to_unit(self.unit_3_path, 'Python Lists', 'assignment') # Postconditions self.assertDirectoryIsNotEmpty(self.unit_3_path) lesson_path = self.unit_3_path / 'lesson-1-python-lists' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'Python Lists') self.assertFileExists(readme_path) with readme_path.open('r') as fp: self.assertEqual(fp.read(), "# Python Lists\n") # Dirs to create tests_path = lesson_path / 'tests' solutions_path = lesson_path / 'solutions' # Check dirs are created self.assertDirectoryExists(tests_path) self.assertDirectoryExists(solutions_path) # Files to create main_py_path = lesson_path / 'main.py' empty_test_path = tests_path / 'test_.py' empty_solution_path = solutions_path / 'solution_.py' # Check files self.assertFileExists(main_py_path) self.assertFileExists(empty_test_path) self.assertFileExists(empty_solution_path)
def test_add_lesson_in_between_other_unit(self): io.add_lesson_to_unit( self.unit_1_path, 'Python Lists', 'assignment', order=2) # Postconditions self.assertDirectoryIsNotEmpty(self.unit_1_path) lesson_path = self.unit_1_path / 'lesson-2-python-lists' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'Python Lists') self.assertFileExists(readme_path) # Dirs to create tests_path = lesson_path / 'tests' solutions_path = lesson_path / 'solutions' # Check dirs are created self.assertDirectoryExists(tests_path) self.assertDirectoryExists(solutions_path) # Files to create main_py_path = lesson_path / 'main.py' empty_test_path = tests_path / 'test_.py' empty_solution_path = solutions_path / 'solution_.py' # Check files self.assertFileExists(main_py_path) self.assertFileExists(empty_test_path) self.assertFileExists(empty_solution_path) # Previous lessons # Lesson 1 lesson_path = self.unit_1_path / 'lesson-1-python-intro' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'Python Intro') self.assertFileExists(readme_path) # Lesson 3 (previously 2) lesson_path = self.unit_1_path / 'lesson-3-interpreters' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'Interpreters') self.assertFileExists(readme_path) # Lesson 4 (previously 3) lesson_path = self.unit_1_path / 'lesson-4-history' dot_romtr_path = lesson_path / '.rmotr' readme_path = lesson_path / 'README.md' self.assertDirectoryExists(lesson_path) self.assertDirectoryIsNotEmpty(lesson_path) with dot_romtr_path.open('r') as fp: dot_rmotr_content = toml.loads(fp.read()) self.assertTrue('uuid' in dot_rmotr_content) self.assertEqual(dot_rmotr_content['name'], 'History') self.assertFileExists(readme_path)
def create_lesson(path_to_unit, name, type, order): io.add_lesson_to_unit(path_to_unit, name, type, order)