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

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

Merged
merged 4 commits into from
Apr 4, 2023

Conversation

SvenMarcus
Copy link
Collaborator

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
    }
Loading

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

@SvenMarcus SvenMarcus merged commit 72a60a0 into slub:main Apr 4, 2023
@SvenMarcus SvenMarcus deleted the feature/browser-client branch April 4, 2023 08:37
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.

1 participant