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

Note: Only the first 2 of 3 launches are shown below as a preview.

launch_1

  • task_1 (25 points)
    • Create domain/models.py file for domain modeling.

    • Create a Movie class with name and customer_age class fields.

    • name field must be str type, customer_age field must be int type.

    • Remember to implement unit tests for the Movie class, use pytest for tests.

  • task_2 (30 points)
    • Create a function called movie_factory with name and customer_age arguments.

    • Function must be located in domain/models.py.

    • The name argument must be str 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 in domain/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 a movie argument which must be Movie type.

    • The function must return f"You are allowed to watch {movie.name}!"

    • Use age_limit_6plus decorator for validating buy_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 in domain/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 called buy_ticket_for_teens() with a movie argument which must be Movie type.

    • The function must return f"You are allowed to watch {movie.name}!"

    • Use age_limit_13plus decorator for validating buy_ticket_for_teens()

    • Remember to implement unit tests for the decorator, success, and fail cases, use pytest for tests.

Log in to launch project