Skip to content

bovine.testing.features

bovine.testing.features

Helpers for BDD. To use the helpers that provide a session use an environment file such as

features/environment.py

after_scenario

after_scenario(context, scenario)

Closes the aiohttp.ClientSession if present

Source code in bovine/bovine/testing/features/__init__.py
def after_scenario(context, scenario):
    """Closes the [aiohttp.ClientSession][]  if present"""
    if context.session:
        asyncio.get_event_loop().run_until_complete(context.session.close())
        context.session = None

before_all

before_all(context)

Creates necessary variables to store stuff in

Source code in bovine/bovine/testing/features/__init__.py
def before_all(context):
    """Creates necessary variables to store stuff in"""
    context.session = None
    context.responses = {}

before_scenario

before_scenario(context, scenario)

Ensures an aiohttp.ClientSession is present

Source code in bovine/bovine/testing/features/__init__.py
def before_scenario(context, scenario):
    """Ensures an [aiohttp.ClientSession][] is present"""
    if context.session is None:
        asyncio.get_event_loop().run_until_complete(create_client_session(context))

    context.responses = {}

steps

check_type

check_type(context, activity_type)

Checks that the result stored in context.result has the type property given by activity_type.

Then The result has the type "Follow"
Source code in bovine/bovine/testing/features/steps.py
@then('The result has the type "{activity_type}"')
def check_type(context, activity_type):
    """
    Checks that the result stored in `context.result`
    has the `type` property given by `activity_type`.

    ```gherkin
    Then The result has the type "Follow"
    ```
    """
    assert context.result.get("type") == activity_type

validate_against_schema async

validate_against_schema(context, schema_url)

Checks that the result stored in context.result satisfies the schema retrieved from schema_url.

Then The result obeys the schema given by "https://domain.example/schema.json"
Source code in bovine/bovine/testing/features/steps.py
@then('The result obeys the schema given by "{schema_url}"')
@async_run_until_complete
async def validate_against_schema(context, schema_url):
    """
    Checks that the result stored in `context.result`
    satisfies the schema retrieved from `schema_url`.

    ```gherkin
    Then The result obeys the schema given by "https://domain.example/schema.json"
    ```
    """
    response = await context.session.get(
        schema_url, headers={"accept": "application/json"}
    )
    schema = json.loads(await response.text())

    jsonschema.validate(context.result, schema)