Exemple #1
0
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']
Exemple #2
0
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']
Exemple #3
0
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)