ViceroyTestBase
Base class for viceroy tests.
Provides common functionality for testing Fastly Compute services. Inherit from this class and use the viceroy_server fixture.
This assumes your WASM file is already built. Use your build system (e.g., Makefile) to ensure the WASM file is up to date before running tests.
import pytestfrom fastly_compute.testing import ViceroyTestBase
class TestMyService(ViceroyTestBase): def test_my_endpoint(self): response = self.get("/my-endpoint") assert response.status_code == 200Constants
Default: 10
Default: 'build/bottle-app.composed.wasm'
Default: None
Methods
get(path: str, **kwargs) -> requests.ResponseMake a GET request to the viceroy server.
Parameters
- path: str
URL path to request
- **kwargs: Anyoptional
Additional arguments passed to requests.get()
Returns
The HTTP response
post(path: str, **kwargs) -> requests.ResponseMake a POST request to the viceroy server.
Parameters
- path: str
URL path to request
- **kwargs: Anyoptional
Additional arguments passed to requests.post()
Returns
The HTTP response
request(method: str, path: str, **kwargs) -> requests.ResponseMake an HTTP request to the viceroy server.
Parameters
- method: str
HTTP method (GET, POST, PUT, DELETE, etc.)
- path: str
URL path to request
- **kwargs: Anyoptional
Additional arguments passed to requests.request()
Returns
The HTTP response
set_up_backends(backends: dict[str, str])Set up backends for testing.
Call this in setUpClass or as a class-level setup.
Parameters
- backends: dict[str, str]
Dict mapping backend names to URLs e.g., {"httpbin": "http://127.0.0.1:8080"}
viceroy_server()Start viceroy server for the duration of the test class.
This assumes the WASM file already exists. Use your build system to ensure it's built before running tests.
Returns
Server instance with process, base_url, and captured output