Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proj 05 > Implement MovieRepository class for in-memory handle #4

Merged
merged 5 commits into from Apr 13, 2023

Conversation

dpcalfola
Copy link
Owner

Feat > Implement MovieRepository class for in-memory handle

5. Entities and CRUD abstraction class
6. Implement for in-memory handle
7.  Implement movie entity class specifically
8. Create unit tests for MemoryMovieRepository
9. Modify the MemoryMovieRepository to pass unit tests -> All unit test passed

    Create movie entity
    Create CRUD abstraction class

    < task >

        5. Entities and CRUD abstraction class

            5.1 Create movie entity
                - Path: /api/entities/movie.py
                - Definite field and its type

            5.2 Create CRUD abstraction class
                - Repository(abc.ABC)
                    - create_movie()
                    - get_by_id()
                    - get_by_title()
                    - update_movie()
                    - delete_movie()
                - RepositoryException(Exception)
    1. Refactory path
        /api/repository/abstractions.py -> /api/repository/movie/abstractions.py

    2. Rename for comprehensibility and fix error
        Path: /api/repository/movie/abstractions.py
            - Repository(abc.ABC)
                -> MovieRepository(abc.ABC)
            - def get_by_title(self, movie_title: str) -> typing.Optional[Movie]:
                -> def get_by_title(self, title: str) -> typing.List[Movie]:

    3. Implement MemoryMovieRepository(MovieRepository)
            - create_movie()
            - get_by_id()
            - get_by_title()
            - update_movie()
            - delete_movie()

    < Task >

    6. Implement for in-memory handle
    6.1 Path: /api/repository/movie/movie.py
    6.2 Implement class MemoryMovieRepository(MovieRepository)
        6.2.1 Declare dict for storage -> self._storage: dict = {}
        6.2.2 Implement each abstraction functions
            - create_movie()
            - get_by_id()
            - get_by_title()
            - update_movie()
            - delete_movie()
< Task >

7. Implement movie entity class specifically
    7.1 Path: /api/entities/movie.py
    7.2 Make constructor (__init__ method)
        7.2.1 About "*" as parameter
            -> It makes that
                all parameters can only be passed using their parameter name
        7.2.2 Checking - movie_id should be required
    7.3 Hide each property with underscore and make @Property functions
        7.3.1 Protected from modifying without setter method
            - Setter method example:
                    @field_name.setter
                    def field_name(self, new_value):
    7.4 Override __eq__ method
        -> Although they are different object (object reference address are not same)
            If all attribute are same each other,
            these two object consider same
    8. Create unit tests for MemoryMovieRepository
        8.1 Path:
            8.1.1 Test code:
                api/repository/movie/test/test_movie.py
            8.1.2 Task cases module:
                api/repository/movie/test/testcases_of_test_movie.py
            8.1.3 Target module:
                api/repository/movie/movie.py

        8.2 Creating test-cases module
            - For unit tests, pytest and the pytest.mark.parametrize() decorator are used
            - In this situation,
                the decorator requires test and expected data as parameters,
                making the decorator code too long and less readable
            - Therefore, all test cases are separated and inserted into the test case module
            - In the test code, the decorator parametrize() loads test case data
                from testcases_of_test_movie.py as a list

        8.3 test_code() list
            def test_creat_movie():
            def test_get_by_id():
            def test_get_by_title():
            def test_update_movie():
            def test_update_movie_fail():
            def test_delete_movie():

        8.4 Code description
            8.4.1 Goals
                - Unit tests for the `MemoryMovieRepository` class in the `api.repository.movie.movie` module
                - The tests cover creating, retrieving, updating, and deleting movies from the repository,
                - Use `pytest` and `parametrize` to run multiple test cases with different inputs and expected results
            8.4.2 Implementation
                - The tests are implemented in the `test_movie.py` module
                - And use the `TestCases` class in the `testcases_of_test_movie.py` module
                    to generate the test data
                - Custom exception class `RepositoryException` in the `api.repository.abstractions` module,
                    which is used to test for expected errors when updating movies in the repository
    9. Modify the MemoryMovieRepository to pass unit tests

        9.1 Path:
            api/repository/movie/movie.py

        9.2 Major modifications:
            9.2.1 Change parameter name from 'id' to 'movie_id'
            9.2.2 Add a return value to every method as either a Movie object or a List[Movie]
            9.2.3 Update the 'setattr()' method inside the 'update_movie()' method:
                    - Change from 'setattr(movie, key, value)' to 'setattr(movie, f"_{key}", value)'
                    - Access 'Movie' entity fields directly since they do not have and need setters
                    - If verification logic is required, setters will be created

        9.3 All tests pass successfully on local development environment

Chore >

    - Write some documents about develop task
    - Upgrade pytest pip package version to 7.3.0
        Collected in 'requirements.test.txt'
@dpcalfola dpcalfola merged commit 00ba010 into main Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant