aboutsummaryrefslogtreecommitdiffstats
path: root/test/moodle.py
blob: d795eba3cd661c29a0a1da868f2e77a1730e16f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import pytest

import pathlib
import configparser

from muddle import paths
from muddle import moodle

config_file = pathlib.Path(paths.default_config_file)
if not config_file.is_file():
    log.error(f"cannot read {config_file}")
    sys.exit(1)

config = configparser.ConfigParser()
config.read(config_file)


class TestMoodleInstance:
    server = moodle.MoodleInstance(config["server"]["url"], config["server"]["token"])

    def test_get_userid(self):
        assert self.server.get_userid() != None

    def test_get_enrolled_courses(self):
        assert type(next(self.server.get_enrolled_courses())) == moodle.Course


def test_moodle_api():
    server = moodle.MoodleInstance(config["server"]["url"], config["server"]["token"])

    for course in server.get_enrolled_courses():
        print(course.shortname)
        for section in course.get_sections(server.api):
            print(section.name)
            for module in section.get_modules():
                print(module.name)