slub / ocrd_monitor

Web frontend for ocrd_manager
MIT License
2 stars 3 forks source link

Refactor to BrowserClient. Unify tests with spies and fakes #22

Closed SvenMarcus closed 1 year ago

SvenMarcus commented 1 year ago

I refactored the OcrdBrowsers to use the interface described in #14

classDiagram
    OcrdBrowser --> OcrdBrowserClient
    OcrdBrowserClient --> Channel

    class OcrdBrowser {
        +client(): BrowserClient
        +start()
        +stop()
    }

    class OcrdBrowserClient {
        +open_channel(): Channel
        +request(resource: str): Response
    }

    class Channel {
        +send_bytes(data: bytes)
        +receive_bytes(): bytes
    }

This refactoring provided enough encapsulation to allow me to refactor the tests for the workspace endpoint to work with both BrowserSpys (an in-memory test double) and BrowserFakes (an actual server running as a background process) without further modification. This might open the door to future tests with an actual broadway daemon in the background as an acceptance test. Whenever a test is running with a BrowserFake it is automatically marked as an integration test. Therefore, running the tests with not integration is significantly faster now and allows for faster iteration. For users of pdm, like myself, I have added extra script commands to pyproject.toml to either run only unit or both unit and integration tests.

Unit tests only: pdm run test Unit and integration tests: pdm run test-integration