aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNao Pross <np@0hm.ch>2021-02-12 01:31:01 +0100
committerNao Pross <np@0hm.ch>2021-02-12 01:31:01 +0100
commita9007a546964009dc2979a96b75d02291e4130b5 (patch)
tree89fb47beb98ed998364ad62244dc150091614ebd
parentPartially refractor muddle.moodle and add test (diff)
downloadMuddle-a9007a546964009dc2979a96b75d02291e4130b5.tar.gz
Muddle-a9007a546964009dc2979a96b75d02291e4130b5.zip
Continue refractor of muddle.moodle
Diffstat (limited to '')
-rw-r--r--muddle/moodle.py30
-rw-r--r--test/moodle.py21
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)