diff --git a/app/main.py b/app/main.py index a740cca7..ff1cc9a7 100644 --- a/app/main.py +++ b/app/main.py @@ -1,3 +1,31 @@ -class OnlineCourse: - # write your code here - pass +from __future__ import annotations + + +class OnlineClass: + def __init__( + self, + name: str, + description: str, + weeks: int + ) -> None: + self.name = name + self.description = description + self.weeks = weeks + + @classmethod + def from_dict( + cls, + course_dict: dict + ) -> OnlineClass: + return OnlineClass( + course_dict.get("name"), + course_dict.get("description"), + cls.days_to_weeks(course_dict.get("days")) + ) + + @staticmethod + def days_to_weeks(days: int) -> int: + if days % 7 != 0: + return int(days / 7) + 1 + + return int(days / 7) diff --git a/tests/test_main.py b/tests/test_main.py index 7535bf92..a030acf9 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -1,9 +1,9 @@ import pytest -from app.main import OnlineCourse +from app.main import OnlineClass -class OnlineClass(OnlineCourse): +class OnlineClass(OnlineClass): pass @@ -16,7 +16,7 @@ class OnlineClass(OnlineCourse): ], ) def test_constructor(name, description, weeks): - course = OnlineCourse(name=name, description=description, weeks=weeks) + course = OnlineClass(name=name, description=description, weeks=weeks) assert course.name == name, ( f"Course should have 'name' equal to {name} " f"when course is created with " @@ -52,7 +52,7 @@ def test_constructor(name, description, weeks): ], ) def test_days_to_weeks(days, weeks): - assert OnlineCourse.days_to_weeks(days) == weeks, ( + assert OnlineClass.days_to_weeks(days) == weeks, ( f"Staticmethod 'days_to_weeks' should return {weeks} " f"when 'days' is equal to {days}" ) @@ -94,7 +94,7 @@ def test_days_to_weeks(days, weeks): ], ) def test_from_dict_method(dictionary, name, description, weeks): - course = OnlineCourse.from_dict(dictionary) + course = OnlineClass.from_dict(dictionary) assert course.name == name, ( f"Course should have 'name' equal to {name} " f"when course is created with "