def __init__( self, course: Optional[Course]=None, name: Optional[str]=None, id: Optional[int]=None ) -> None: if course is None: self.course = Course() else: self.course = course self.cachename = 'group' if name is None and id is None: cachable.CachableEntity.__init__(self, self.cachename) listed.ListedEntity.__init__(self) else: entities = self.course.list_groups() listed.ListedEntity.__init__(self, entities, name, id) assert isinstance(self.json['id'], int) assert isinstance(self.json['name'], str) self.id = self.json['id'] self.displayname = self.json['name']
def _get_section_or_create( init_course: Course, name: str ) -> int: for section in init_course.list_sections(): if section['name'] == name: return section['id'] return init_course.create_section(name)['id']
def gcat_id( init_course: Course, gcat_name: str ) -> int: gcat_id = _get_gcat_or_create(init_course, gcat_name) for group in init_course.list_groups(gcat_id): init_course.delete_group(group['id']) return gcat_id
def _get_gcat_or_create( init_course: Course, name: str ) -> int: for gcat in init_course.list_group_categories(): if gcat['name'] == name: return gcat['id'] return init_course.create_group_category(name)['id']
def test_create_section(name: str, course: Course) -> None: # Try and add the given section. section = course.create_section(name) assert is_valid_section(section) assert section['name'] == name # Try and delete the section created above. deleted_section = course.delete_section(section['id']) assert is_valid_section(deleted_section) assert deleted_section['id'] == section['id']
def test_create_group_category(name: str, course: Course) -> None: # Try and add the given group category. gcat = course.create_group_category(name) assert is_valid_group_category(gcat) assert gcat['name'] == name # Try and delete the group category created above. deleted_gcat = course.delete_group_category(gcat['id']) assert is_valid_group_category(deleted_gcat) assert deleted_gcat['id'] == gcat['id']
class Group(listed.ListedEntity, cachable.CachableEntity): course = None # type: Course id = None # type: int displayname = None # type: str def __init__( self, course: Optional[Course]=None, name: Optional[str]=None, id: Optional[int]=None ) -> None: if course is None: self.course = Course() else: self.course = course self.cachename = 'group' if name is None and id is None: cachable.CachableEntity.__init__(self, self.cachename) listed.ListedEntity.__init__(self) else: entities = self.course.list_groups() listed.ListedEntity.__init__(self, entities, name, id) assert isinstance(self.json['id'], int) assert isinstance(self.json['name'], str) self.id = self.json['id'] self.displayname = self.json['name'] def web_url(self) -> str: return self.canvas.web_url('courses/{}/'.format(self.id))
def test_create_sections(names: List[str], course: Course) -> None: # Try and add the given number of sections. sections = [] for name in names: section = course.create_section(name) sections.append(section) sids = [s['id'] for s in sections] snames = [s['name'] for s in sections] assert sorted(snames) == sorted(names) # Clean-up: Delete the sections created above. deleted_ids = [] for sid in sids: del_section = course.delete_section(sid) deleted_ids.append(del_section['id']) assert sorted(deleted_ids) == sorted(sids)
def test_create_group_categories(names: List[str], course: Course) -> None: # Try and add the given number of group categories. gcats = [] for name in names: gcat = course.create_group_category(name) gcats.append(gcat) gcat_ids = [gcat['id'] for gcat in gcats] gcat_names = [gcat['name'] for gcat in gcats] assert sorted(gcat_names) == sorted(names) # Clean-up: Delete the group categories added above. del_gcat_ids = [] for gcat_id in gcat_ids: del_gcat = course.delete_group_category(gcat_id) del_gcat_ids.append(del_gcat['id']) assert sorted(del_gcat_ids) == sorted(gcat_ids)
class GroupCategory(listed.ListedEntity, cachable.CachableEntity): course = None # type: Course id = None # type: int displayname = None # type: str def __init__(self, course: Optional[Course] = None, name: Optional[str] = None, id: Optional[int] = None) -> None: if course is None: self.course = Course() else: self.course = course self.cachename = 'gcat' if name is None and id is None: cachable.CachableEntity.__init__(self, self.cachename) listed.ListedEntity.__init__(self) else: entities = self.course.list_group_categories() listed.ListedEntity.__init__(self, entities, name, id) assert isinstance(self.json['id'], int) assert isinstance(self.json['name'], str) self.id = self.json['id'] self.displayname = self.json['name'] def web_url(self) -> str: return self.course.canvas.web_url('courses/{}/groups#tab-{}'.format( self.course.id, self.id)) def list_groups(self) -> Any: return self.course.list_groups(self.id) def create_group(self, name: str) -> Any: return self.course.create_group(self.id, name) def delete_group(self, group_id: int) -> Any: return self.course.delete_group(group_id)
def test_enroll_user( # noqa: F811 course: Course, section_id: int, user_id: int) -> None: return course.section_enroll(section_id, user_id)
def test_enroll_user( course: Course, # noqa: F811 section_id: int, # noqa: F811 user_id: int) -> None: # noqa: F811 return course.section_enroll(section_id, user_id)
def init_course(canvas: Canvas, course_name: str) -> Course: _create_course_if_missing(canvas, course_name) return Course(canvas=canvas, name=course_name)