Exemplo n.º 1
0
    def create_course(self, courseid, init_content):
        """
        :param courseid: the course id of the course
        :param init_content: initial descriptor content
        :raise InvalidNameException or CourseAlreadyExistsException
        Create a new course folder and set initial descriptor content, folder can already exist
        """
        if not id_checker(courseid):
            raise InvalidNameException("Course with invalid name: " + courseid)

        course_directory = os.path.join(self._tasks_directory, courseid)
        if not os.path.exists(course_directory):
            os.mkdir(course_directory)

        base_file = os.path.join(course_directory, "course")
        if not os.path.isfile(base_file +
                              ".yaml") and not os.path.isfile(base_file +
                                                              ".json"):
            write_json_or_yaml(os.path.join(course_directory, "course.yaml"),
                               init_content)
        else:
            raise CourseAlreadyExistsException("Course with id " + courseid +
                                               " already exists.")

        get_course_logger(courseid).info("Course %s created in the factory.",
                                         courseid)
 def test_yaml_write(self):
     write_json_or_yaml(os.path.join(self.dir_path, "output.yaml"), {
         'key1': 'data1',
         'key2': {
             'key3': [1, 2]
         }
     })
     assert load_json_or_yaml(os.path.join(self.dir_path,
                                           "output.yaml")) == {
                                               'key1': 'data1',
                                               'key2': {
                                                   'key3': [1, 2]
                                               }
                                           }
Exemplo n.º 3
0
 def update_course_descriptor_content(self, courseid, content):
     """
     Updates the content of the dict that describes the course
     :param courseid: the course id of the course
     :param content: the new dict that replaces the old content
     :raise InvalidNameException, CourseNotFoundException
     """
     return write_json_or_yaml(self._get_course_descriptor_path(courseid), content)
Exemplo n.º 4
0
 def test_yaml_write(self):
     write_json_or_yaml(os.path.join(self.dir_path, "output.yaml"), {'key1': 'data1', 'key2': {'key3': [1, 2]}})
     assert load_json_or_yaml(os.path.join(self.dir_path, "output.yaml")) == {'key1': 'data1', 'key2': {'key3': [1, 2]}}