Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "falcon in functional component" in Python

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'falcon' in functional components in Python. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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()
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
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)
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
def test_DocumentNotFound(self):
        e = exceptions.DocumentNotFound(message='testing')
        self.assertRaises(falcon.HTTPError,
                          e.handle, self.ex, self.mock_req, self.mock_req, None)
def test_not_found():
    with pytest.raises(falcon.HTTPNotFound) as redirect:
        hug.redirect.not_found()
    assert "404" in redirect.value.status
def client():
    return testing.TestClient(falcon.App())
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
def cors_client():
    app = falcon.App(cors_enable=True)
    return testing.TestClient(app)

Is your System Free of Underlying Vulnerabilities?
Find Out Now