Write some tests, fix imports

pull/84/head
Stijn De Clercq 2021-08-08 20:26:53 +02:00
parent 85f29e7afa
commit 445ca84834
2 changed files with 25 additions and 4 deletions

View File

@ -1,9 +1,8 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
import dacite
from discord import Colour, Embed
from dacite import from_dict from dacite import from_dict
from dataclasses import dataclass, field from dataclasses import dataclass, field
from datetime import datetime, timedelta from datetime import datetime, timedelta
from discord import Colour, Embed
from enums.platform import Platform, get_platform from enums.platform import Platform, get_platform
from functions.timeFormatters import fromArray, intToWeekday, timeFromInt from functions.timeFormatters import fromArray, intToWeekday, timeFromInt
import json import json
@ -109,7 +108,7 @@ class Timeslot:
end_time = slot_dict["time"]["end"] end_time = slot_dict["time"]["end"]
# Location can be none if a class is online-only # Location can be none if a class is online-only
location = dacite.from_dict(Location, slot_dict["location"]) if "location" in slot_dict else None location = from_dict(Location, slot_dict["location"]) if "location" in slot_dict else None
# Find platform & link if this class is online # Find platform & link if this class is online
online_platform: Platform = get_platform(slot_dict.get("online", None)) online_platform: Platform = get_platform(slot_dict.get("online", None))

View File

@ -1,5 +1,27 @@
import pytz
from data import schedule
from datetime import datetime
import unittest import unittest
class TestSchedule(unittest.TestCase): class TestSchedule(unittest.TestCase):
pass def test_holiday_has_passed(self):
tz = pytz.timezone("Europe/Brussels")
before = datetime(2020, 8, 8, tzinfo=tz)
during = datetime(2021, 6, 2, tzinfo=tz)
after = datetime(2021, 8, 8, tzinfo=tz)
holiday = schedule.Holiday([1, 6, 2021], [2, 7, 2021])
self.assertFalse(holiday.has_passed(before))
self.assertFalse(holiday.has_passed(during))
self.assertTrue(holiday.has_passed(after))
def test_course_str(self):
course = schedule.Course("Test")
self.assertEqual(str(course), "Test")
def test_location_str(self):
location = schedule.Location("C", "B", "R")
self.assertEqual(str(location), "C B R")