A use case for test doubles

To see a possible use of mocks, we need to add a new component to our application that will be in charge of notifying the merge request of the status of the build. When a build is finished, this object will be called with the ID of the merge request and the status of the build, and it will update the status of the merge request with this information by sending an HTTP POST request to a particular fixed endpoint:

# mock_2.pyfrom datetime import datetimeimport requestsfrom constants import STATUS_ENDPOINTclass BuildStatus:    """The CI status of a pull request."""    @staticmethod    def build_date() -> str:        return datetime.utcnow().isoformat()    @classmethod    def notify(cls, merge_request_id, status):        build_status = { "id": ...

Get Clean Code in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.