Overview
Project details
The easy project to understand decorator implementation in Python.
Tracks: Python
185
number of points you will earn
3
launches to complete the project
5
tasks to complete the project
This project is part of the following tracks:
Learning outcomes
- Get adapted to the EpicLaunchX learning style.
- Understand the flow actions at EpicLaunchX.
- Explore PR and code best practices, and earn your first points.
- Learn more about GitHub and master the conventional commit style.
- Use Makefile extensively, explore code formatting, linting style, etc.
- Learn Decorators.
- Use Decorators for validation logic.
Project Launches & Tasks
launch_1
-
task_1 (25 points)
-
Create
domain/models.py
file for domain modeling. -
Create a
Movie
class withname
andcustomer_age
class fields. -
name
field must bestr
type,customer_age
field must beint
type. -
Remember to implement unit tests for the Movie class, use pytest for tests.
-
-
task_2 (30 points)
-
Create a function called
movie_factory
withname
andcustomer_age
arguments. -
Function must be located in
domain/models.py
. -
The
name
argument must bestr
type,customer_age
argument must be int type. -
Factory should return the type as a
Movie
class object. -
Do not forget to implement unit tests for the
movie_factory
function, use pytest for tests.
-
launch_2
-
task_3 (45 points)
-
Create a decorator called
age_limit_6plus
, the argument of the decorator is a Callable, as usual decorators. -
Remember that the
Movie
model is located indomain/models.py
and is already ready from the previous task, no need to implement it again. -
The decorator must be located in
utils/decorator.py
. -
The decorator must check
movie.customer_age
with their proper conditions. -
The return type of decorator must be
Callable
from typing. Read more: Annotating callables -
If
customer_age
doesn’t satisfy the condition, the return can be “Sorry, you are not old enough to watch {movie.name}!”. If it does, the return can be “You are allowed to watch {movie.name}!”. -
Create
service/tickets.py
where you need to put your service logic. -
Create a function called
buy_ticket_for_children()
with amovie
argument which must beMovie
type. -
The function must return
f"You are allowed to watch {movie.name}!"
-
Use
age_limit_6plus
decorator for validatingbuy_ticket_for_children()
-
Remember to implement unit tests for the decorator, success, and fail cases, use pytest for tests.
-
-
task_4 (35 points)
-
Create a decorator called
age_limit_13plus
the argument of the decorator is a Callable, as usual decorators. -
Remember that the
Movie
model is located indomain/models.py
and is already ready from the previous task, no need to implement it again. -
The decorator must be located in
utils/decorator.py
. -
The decorator must check
movie.customer_age
with their proper conditions. -
The return type of decorator must be
Callable
from typing. Read more: Annotating callables -
If
customer_age
doesn’t satisfy the condition, the return can be “Sorry, you are not old enough to watch {movie.name}!”. If it does, the return can be “You are allowed to watch {movie.name}!”. -
In
service/tickets.py
, create a function calledbuy_ticket_for_teens()
with amovie
argument which must beMovie
type. -
The function must return
f"You are allowed to watch {movie.name}!"
-
Use
age_limit_13plus
decorator for validatingbuy_ticket_for_teens()
-
Remember to implement unit tests for the decorator, success, and fail cases, use pytest for tests.
-