ViceroyTestBase

Classin viceroyfastly-compute 0.1.3View source

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 pytest
from fastly_compute.testing import ViceroyTestBase
class TestMyService(ViceroyTestBase):
def test_my_endpoint(self):
response = self.get("/my-endpoint")
assert response.status_code == 200

Constants

REQUEST_TIMEOUT

Anyread-onlyView source

Default: 10

WASM_FILE

Anyread-onlyView source

Default: 'build/bottle-app.composed.wasm'

VICEROY_CONFIG

Anyread-onlyView source

Default: None

Methods

get

staticView source
get(path: str, **kwargs) -> requests.Response

Make a GET request to the viceroy server.

Parameters

path: str

URL path to request

**kwargs: Anyoptional

Additional arguments passed to requests.get()

Returns

requests.Response

The HTTP response

post

staticView source
post(path: str, **kwargs) -> requests.Response

Make a POST request to the viceroy server.

Parameters

path: str

URL path to request

**kwargs: Anyoptional

Additional arguments passed to requests.post()

Returns

requests.Response

The HTTP response

request

staticView source
request(method: str, path: str, **kwargs) -> requests.Response

Make 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

requests.Response

The HTTP response

server

staticView source
server() -> ViceroyServer

Access server properties.

Returns

set_up_backends

staticView source
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

staticView source
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