From a9007a546964009dc2979a96b75d02291e4130b5 Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Fri, 12 Feb 2021 01:31:01 +0100 Subject: Continue refractor of muddle.moodle --- muddle/moodle.py | 30 +++++++++++++++++++++--------- test/moodle.py | 21 ++++++++++++++++----- 2 files changed, 37 insertions(+), 14 deletions(-) diff --git a/muddle/moodle.py b/muddle/moodle.py index a9209d7..8146fd4 100644 --- a/muddle/moodle.py +++ b/muddle/moodle.py @@ -104,10 +104,10 @@ class Course(SchemaObj): def get_sections(self, api): req = api.core_course_get_contents(courseid=self.id) - for sec in req.json(): + for s in req.json(): # rest api response does not contain course id - sec["course"] = self.id - yield Section._fromdict(sec) + s["course"] = self.id + yield Section._fromdict(s) @dataclasses.dataclass @@ -122,8 +122,13 @@ class Section(SchemaObj): name: str summary: str visible: bool + modules: List + def get_modules(self): + for m in self.modules: + yield Module._fromdict(m) + @dataclasses.dataclass class Module(SchemaObj): @@ -132,16 +137,23 @@ class Module(SchemaObj): https://www.examulator.com/er/output/tables/course_modules.html """ id: int - course: int - module: int - section: int + name: str + + +@dataclasses.dataclass +class File(SchemaObj): + filename: str + fileurl: str @dataclasses.dataclass class Folder(SchemaObj): - """ - Resource type that holds files - """ + pass + + +@dataclasses.dataclass +class ExternalLink(SchemaObj): + pass class ApiHelper: diff --git a/test/moodle.py b/test/moodle.py index 3669ef8..d795eba 100644 --- a/test/moodle.py +++ b/test/moodle.py @@ -16,10 +16,21 @@ config.read(config_file) class TestMoodleInstance: - server = moodle.MoodleInstance(config["server"]["url"], config["server"]["token"]) + server = moodle.MoodleInstance(config["server"]["url"], config["server"]["token"]) - def test_get_userid(self): - assert self.server.get_userid() != None + 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_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) -- cgit v1.2.1