Skip to main content

Pytest `client` fixture for the Falcon Framework

Project description

Pytest client fixture for the Falcon Framework.

Build Status Coverage Status Python versions PyPi

Installation

pip install pytest-falcon-client

Before using it you must define api fixture that returns instance of your falcon.API

import pytest

from yout_application import create_api

@pytest.fixture
def api():
    return create_api()

Usage

def test_something(client):
    got = client.get('/your_url/42/')  # returns json of response and automatically check response status code
    assert got == {'awesome': 'response'}

    response = client.get('/your_url/100500/', as_response=True)  # returns testing response object and skip status code check
    assert response.status_code == 400
    assert response.json = 'Invalid id'

You can define your own client class to make global assertions or request preparation.

import pytest


@pytest.fixture
def ApiTestClientCls(ApiTestClientCls):

    class ApiTestClient(ApiTestClientCls):

        def response_assertions(self, response):
            # test cors headers globally
            assert response.headers[
                'Access-Control-Allow-Origin'] == 'falconframework.org'

        def prepare_request(self, method, expected, *args, **kwargs):
            # add `ORIGIN` header to every request
            kwargs['headers'] = {'Origin': 'falconframework.org'}
            return args, kwargs

    return ApiTestClient


def test_something_else(client):
    got = client.get('/some_url/100500/')
    assert got == {'awesome': 100500}

If you need default client, but ApiTestClientCls redefined globally, use default_client fixture

def test_something_else(default_client):
    got = default_client.get('/some_url/100500/')
    assert got == {'awesome': 100500}

Look at more examples in tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pytest-falcon-client-1.0.2.tar.gz (3.0 kB) Copy SHA256 hash SHA256 Source None

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page