mirror of https://github.com/stijndcl/didier
Add tests for courses, change study guide description
parent
c6958d22f3
commit
9819e82638
|
@ -70,7 +70,7 @@ class SchoolSlash(commands.Cog):
|
||||||
|
|
||||||
@slash_command(name="fiche", description="Zoek de studiefiche voor een vak.")
|
@slash_command(name="fiche", description="Zoek de studiefiche voor een vak.")
|
||||||
async def _study_guide_slash(self, ctx: ApplicationContext,
|
async def _study_guide_slash(self, ctx: ApplicationContext,
|
||||||
vak: Option(str, description="Naam van het vak. Afkortingen werken ook, maar worden niet ge-autocompletet.",
|
vak: Option(str, description="Naam van het vak. Afkortingen werken ook, maar worden niet geautocompletet.",
|
||||||
required=True, autocomplete=course_autocomplete)):
|
required=True, autocomplete=course_autocomplete)):
|
||||||
# Find code corresponding to the search query
|
# Find code corresponding to the search query
|
||||||
course = find_course_from_name(vak, courses)
|
course = find_course_from_name(vak, courses)
|
||||||
|
|
|
@ -3,6 +3,7 @@ from typing import Optional
|
||||||
|
|
||||||
import dacite
|
import dacite
|
||||||
import json
|
import json
|
||||||
|
from os import path
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
|
@ -16,7 +17,9 @@ class Course:
|
||||||
|
|
||||||
def load_courses() -> dict[str, Course]:
|
def load_courses() -> dict[str, Course]:
|
||||||
"""Create a list of all courses"""
|
"""Create a list of all courses"""
|
||||||
with open("files/courses.json", "r") as file:
|
# Allows testing
|
||||||
|
filepath = path.join(path.dirname(__file__), "..", "files", "courses.json")
|
||||||
|
with open(filepath, "r") as file:
|
||||||
data = json.load(file)
|
data = json.load(file)
|
||||||
|
|
||||||
courses = {}
|
courses = {}
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from data.courses import load_courses, find_course_from_name
|
||||||
|
|
||||||
|
|
||||||
|
class TestCourses(unittest.TestCase):
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
super().__init__(*args, **kwargs)
|
||||||
|
self.courses = load_courses()
|
||||||
|
|
||||||
|
def test_find_course(self):
|
||||||
|
self.assertIsNone(find_course_from_name("garbage", self.courses))
|
||||||
|
self.assertIsNone(find_course_from_name("garbage"))
|
||||||
|
|
||||||
|
# Find by name
|
||||||
|
webdev = find_course_from_name("Webdevelopment", self.courses)
|
||||||
|
self.assertIsNotNone(webdev)
|
||||||
|
self.assertEqual(webdev.code, "C003779")
|
||||||
|
|
||||||
|
# Find by abbreviation
|
||||||
|
infosec = find_course_from_name("infosec", self.courses)
|
||||||
|
self.assertIsNotNone(infosec)
|
||||||
|
self.assertEqual(infosec.code, "E019400")
|
||||||
|
|
||||||
|
# Case sensitive
|
||||||
|
not_found = find_course_from_name("ad3", self.courses, case_insensitive=False)
|
||||||
|
self.assertIsNone(not_found)
|
||||||
|
|
||||||
|
# Find by alt name
|
||||||
|
pcs = find_course_from_name("parallel computer systems", self.courses)
|
||||||
|
self.assertIsNotNone(pcs)
|
||||||
|
self.assertEqual(pcs.code, "E034140")
|
Loading…
Reference in New Issue