How to use falcon - 10 common examples

To help you get started, we’ve selected a few falcon examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CyberReboot / poseidon / poseidon / poseidonMonitor / NodeHistory / test_NodeHistory.py View on Github external
Test module for NodeHistory.py
Created on 28 June 2016
@author: dgrossman, lanhamt
"""
import logging

import falcon
import pytest

from poseidon.poseidonMonitor.NodeHistory.NodeHistory import Handle_Default
from poseidon.poseidonMonitor.NodeHistory.NodeHistory import NodeHistory
from poseidon.poseidonMonitor.NodeHistory.NodeHistory import nodehistory_interface

module_logger = logging.getLogger(__name__)

application = falcon.API()
application.add_route('/v1/history/{resource}',
                      nodehistory_interface.get_endpoint('Handle_Default'))


def test_node_hist_class():
    ''' test instantiate of NodeHistory '''
    nh = NodeHistory()
    nh.add_endpoint('Handle_Default', Handle_Default)
    nh.configure()
    nh.configure_endpoints()


def test_handle_default_class():
    ''' test handle_Default '''
    hd = Handle_Default()
    hd.owner = Handle_Default()
github openstack / zaqar / tests / unit / queues / transport / wsgi / test_claims.py View on Github external
body = self.simulate_get(self.messages_path, self.project_id,
                                 query_string='include_claimed=true',
                                 headers=headers)
        listed = json.loads(body[0])
        self.assertEqual(self.srmock.status, falcon.HTTP_200)
        self.assertEqual(len(listed['messages']), len(claimed))

        now = timeutils.utcnow() + datetime.timedelta(seconds=10)
        timeutils_utcnow = 'marconi.openstack.common.timeutils.utcnow'
        with mock.patch(timeutils_utcnow) as mock_utcnow:
            mock_utcnow.return_value = now
            body = self.simulate_get(claim_href, self.project_id)

        claim = json.loads(body[0])

        self.assertEqual(self.srmock.status, falcon.HTTP_200)
        self.assertEqual(self.srmock.headers_dict['Content-Location'],
                         claim_href)
        self.assertEqual(claim['ttl'], 100)
        ## NOTE(cpp-cabrera): verify that claim age is non-negative
        self.assertThat(claim['age'], matchers.GreaterThan(-1))

        # Try to delete the message without submitting a claim_id
        self.simulate_delete(message_href, self.project_id)
        self.assertEqual(self.srmock.status, falcon.HTTP_403)

        # Delete the message and its associated claim
        self.simulate_delete(message_href, self.project_id,
                             query_string=params)
        self.assertEqual(self.srmock.status, falcon.HTTP_204)

        # Try to get it from the wrong project
github openstack / freezer-api / tests / test_actions.py View on Github external
def test_on_get_return_correct_data(self):
        self.mock_db.get_action.return_value = get_fake_action_0()
        self.resource.on_get(self.mock_req, self.mock_req, fake_action_0['action_id'])
        result = self.mock_req.body
        self.assertEqual(result, get_fake_action_0())
        self.assertEqual(self.mock_req.status, falcon.HTTP_200)
github falconry / falcon / tests / test_middleware.py View on Github external
def test_http_status_raised_from_error_handler(self):
        mw = CaptureResponseMiddleware()
        app = falcon.App(middleware=mw)
        app.add_route('/', MiddlewareClassResource())
        client = testing.TestClient(app)

        def _http_error_handler(error, req, resp, params):
            raise falcon.HTTPStatus(falcon.HTTP_201)

        # NOTE(kgriffs): This will take precedence over the default
        # handler for facon.HTTPError.
        app.add_error_handler(falcon.HTTPError, _http_error_handler)

        response = client.simulate_request(path='/', method='POST')
        assert response.status == falcon.HTTP_201
        assert mw.resp.status == response.status
github openstack / freezer-api / tests / test_exceptions.py View on Github external
def test_DocumentNotFound(self):
        e = exceptions.DocumentNotFound(message='testing')
        self.assertRaises(falcon.HTTPError,
                          e.handle, self.ex, self.mock_req, self.mock_req, None)
github hugapi / hug / tests / test_redirect.py View on Github external
def test_not_found():
    with pytest.raises(falcon.HTTPNotFound) as redirect:
        hug.redirect.not_found()
    assert "404" in redirect.value.status
github falconry / falcon / tests / test_hello.py View on Github external
def client():
    return testing.TestClient(falcon.App())
github falconry / falcon / tests / test_utils.py View on Github external
def test_default_headers_with_override(self):
        app = falcon.App()
        resource = testing.SimpleTestResource()
        app.add_route('/', resource)

        override_before = 'something-something'
        override_after = 'something-something'[::-1]

        headers = {
            'Authorization': 'Bearer XYZ',
            'Accept': 'application/vnd.siren+json',
            'X-Override-Me': override_before,
        }

        client = testing.TestClient(app, headers=headers)
        client.simulate_get(headers={'X-Override-Me': override_after})

        assert resource.captured_req.auth == headers['Authorization']
        assert resource.captured_req.accept == headers['Accept']
        assert resource.captured_req.get_header('X-Override-Me') == override_after
github falconry / falcon / tests / test_headers.py View on Github external
def cors_client():
    app = falcon.App(cors_enable=True)
    return testing.TestClient(app)