Python falcon.testing.TestClient() Examples

The following are 30 code examples of falcon.testing.TestClient(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module falcon.testing , or try the search function .
Example #1
Source File: test_validators.py    From falcon-boilerplate with MIT License 6 votes vote down vote up
def test_both_schemas_validation_failure():
    with pytest.raises(HTTPError) as excinfo:
        Resource().both_validated(GoodData(), BadData())

    assert excinfo.value.title == falcon.HTTP_INTERNAL_SERVER_ERROR
    assert excinfo.value.description == "Response data failed validation"

    with pytest.raises(HTTPError) as excinfo:
        Resource().both_validated(BadData(), GoodData())

    msg = "Request data failed validation: data must contain ['message'] properties"
    assert excinfo.value.title == falcon.HTTP_BAD_REQUEST
    assert excinfo.value.description == msg

    client = testing.TestClient(falcon.API())
    client.app.add_route("/test", Resource())
    result = client.simulate_put("/test", json=BadData.media)
    assert result.status_code == 400 
Example #2
Source File: base.py    From armada with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(BaseControllerTest, self).setUp()
        # Override the default configuration file lookup with references to
        # the sample configuration files to avoid oslo.conf errors when
        # creating the server below.
        current_dir = os.path.dirname(os.path.realpath(__file__))
        sample_conf_dir = os.path.join(current_dir, os.pardir, os.pardir,
                                       os.pardir, os.pardir, 'etc', 'armada')
        sample_conf_files = ['api-paste.ini', 'armada.conf.sample']
        with mock.patch.object(
                armada.conf, '_get_config_files') as mock_get_config_files:
            mock_get_config_files.return_value = [
                os.path.join(sample_conf_dir, x) for x in sample_conf_files
            ]
            self.app = falcon_testing.TestClient(
                server.create(enable_middleware=False))
        self.policy = self.useFixture(fixtures.RealPolicyFixture()) 
Example #3
Source File: base.py    From armada with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(BaseControllerTest, self).setUp()
        # Override the default configuration file lookup with references to
        # the sample configuration files to avoid oslo.conf errors when
        # creating the server below.
        current_dir = os.path.dirname(os.path.realpath(__file__))
        sample_conf_dir = os.path.join(
            current_dir, os.pardir, os.pardir, os.pardir, os.pardir, 'etc',
            'armada')
        sample_conf_files = ['api-paste.ini', 'armada.conf.sample']
        with mock.patch.object(armada.conf,
                               '_get_config_files') as mock_get_config_files:
            mock_get_config_files.return_value = [
                os.path.join(sample_conf_dir, x) for x in sample_conf_files
            ]
            self.app = falcon_testing.TestClient(
                server.create(enable_middleware=False))
        self.policy = self.useFixture(fixtures.RealPolicyFixture()) 
Example #4
Source File: test_versions.py    From promenade with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(promenade.start_promenade(disable='keystone')) 
Example #5
Source File: test_update_labels.py    From promenade with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(promenade.start_promenade(disable='keystone')) 
Example #6
Source File: test_health_api.py    From promenade with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(promenade.start_promenade(disable='keystone')) 
Example #7
Source File: client.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def client():
    configure()
    return testing.TestClient(create_app()) 
Example #8
Source File: test_validators.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_both_schemas_validation_success():
    req_data = GoodData()
    resp_data = GoodData()

    result = Resource().both_validated(req_data, resp_data)

    assert result[0] is req_data
    assert result[1] is resp_data

    client = testing.TestClient(falcon.API())
    client.app.add_route("/test", Resource())
    result = client.simulate_put("/test", json=GoodData.media)
    assert result.json == resp_data.media 
Example #9
Source File: test_ncontrol.py    From vent with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(api) 
Example #10
Source File: test_api_builddata.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator):
        """Create a test harness for the the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #11
Source File: test_bootaction_context.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator, mock_get_build_data):
        """Create a test harness for the the Falcon API framework."""
        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #12
Source File: test_api_bootaction_status.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, yaml_ingester, yaml_orchestrator):
        """Create a test harness for the the Falcon API framework."""
        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=yaml_ingester,
                orchestrator=yaml_orchestrator)) 
Example #13
Source File: test_api_tasks.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator):
        """Create a test harness for the the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #14
Source File: test_api_bootaction.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, yaml_ingester, yaml_orchestrator,
                   mock_get_build_data):
        """Create a test harness for the the Falcon API framework."""
        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=yaml_ingester,
                orchestrator=yaml_orchestrator)) 
Example #15
Source File: test_api_nodes_unit.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator, mock_get_build_data):
        """Create a test harness for the the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #16
Source File: test_api_validation.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator, mock_get_build_data):
        """Create a test harness for the the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #17
Source File: test_api.py    From poseidon with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(api) 
Example #18
Source File: conftest.py    From shipyard with Apache License 2.0 5 votes vote down vote up
def api_client():
    """Testing client for the Shipyard API"""
    cur_dir = os.path.dirname(__file__)
    filename = os.path.join(cur_dir, 'test.conf')
    return testing.TestClient(
        start_shipyard(default_config_files=[filename])
    ) 
Example #19
Source File: test_validatedesign.py    From promenade with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(promenade.start_promenade(disable='keystone')) 
Example #20
Source File: test_api_builddata.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator):
        """Create a test harness for the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #21
Source File: test_falcon_middlewares.py    From openapi-core with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def client(self, app):
        return TestClient(app) 
Example #22
Source File: conftest.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def client_with_auth():
    return testing.TestClient(create_app()) 
Example #23
Source File: conftest.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def client():
    with mock.patch('management_api.main.AuthMiddleware') as middleware:
        middleware.return_value = AuthMiddlewareMock()
        return testing.TestClient(create_app()) 
Example #24
Source File: conftest.py    From falcon-auth with MIT License 5 votes vote down vote up
def client(app):
    return testing.TestClient(app) 
Example #25
Source File: conftest.py    From model_server with Apache License 2.0 5 votes vote down vote up
def client(get_fake_model):
    rest_api = create_rest_api(models={"test": get_fake_model})
    return testing.TestClient(rest_api) 
Example #26
Source File: test_plugin_falcon.py    From spectree with Apache License 2.0 5 votes vote down vote up
def client():
    return testing.TestClient(app) 
Example #27
Source File: test_cli.py    From certidude with MIT License 5 votes vote down vote up
def client():
    from certidude.api import certidude_app
    from falcon import testing
    app = certidude_app()
    return testing.TestClient(app) 
Example #28
Source File: test_api_validation.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator, mock_get_build_data):
        """Create a test harness for the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #29
Source File: test_api_nodes_unit.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, deckhand_ingester,
                   deckhand_orchestrator, mock_get_build_data):
        """Create a test harness for the Falcon API framework."""
        policy.policy_engine = policy.DrydockPolicy()
        policy.policy_engine.register_policy()

        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=deckhand_ingester,
                orchestrator=deckhand_orchestrator)) 
Example #30
Source File: test_api_bootaction.py    From drydock with Apache License 2.0 5 votes vote down vote up
def falcontest(self, drydock_state, yaml_ingester, yaml_orchestrator,
                   mock_get_build_data):
        """Create a test harness for the Falcon API framework."""
        return testing.TestClient(
            start_api(
                state_manager=drydock_state,
                ingester=yaml_ingester,
                orchestrator=yaml_orchestrator))