How to use the falcon.Response function in falcon

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 att-comdev / shipyard / tests / unit / control / common.py View on Github external
def create_resp():
    '''creates a falcon response'''
    resp = falcon.Response()
    return resp
github softlayer / jumpgate / tests / jumpgate-tests / compute / test_volumes.py View on Github external
def test_on_delete_fail_detach_exception(self):
        client, env = get_client_env()
        vg_clientMock = client['Virtual_Guest']
        deiMock = vg_clientMock.detachDiskImage
        deiMock.side_effect = (SoftLayer.SoftLayerAPIError(404,
                                                           'Detach Error',
                                                           None))
        vdi_clientMock = client['Virtual_Disk_Image']
        vdi_clientMock.getObject.return_value = {'blockDevices':
                                                 [{'guestId': INSTANCE_ID}]}
        req = falcon.Request(env)
        resp = falcon.Response()
        instance = volumes.OSVolumeAttachmentV2()
        instance.on_delete(req, resp, TENANT_ID, INSTANCE_ID, VOLUME_ID)
        vg_clientMock.detachDiskImage.assert_called_with(VOLUME_ID,
                                                         id=INSTANCE_ID)
        self.assertEquals(resp.body, {'volumeFault':
                                      {'message': 'Detach Error',
                                       'code': '500'}})
github softlayer / jumpgate / tests / jumpgate-tests / compute / test_volumes.py View on Github external
def test_on_post_fail_disk_already_attach_another_guest(self):
        body_str = ('{"volumeAttachment": '
                    '{"device": null, "volumeId": "3887490"}}')
        client, env = get_client_env(body=body_str)
        vg_clientMock = client['Virtual_Guest']
        vdi_clientMock = client['Virtual_Disk_Image']
        vdi_clientMock.getObject.return_value = {'blockDevices':
                                                 [{'guestId': 1234567}]}
        req = falcon.Request(env)
        resp = falcon.Response()
        instance = volumes.OSVolumeAttachmentsV2()
        instance.on_post(req, resp, TENANT_ID, INSTANCE_ID)
        self.assertEquals(resp.body, {'volumeFault':
                                      {'message':
                                       'The requested disk image is already'
                                       ' attached to another guest.',
                                       'code': '400'}})
github falconry / falcon / tests / test_slots.py View on Github external
def test_slots_response(self):
        resp = Response()

        try:
            resp.doesnt = 'exist'
        except AttributeError:
            pytest.fail('Unable to add additional variables dynamically')
github softlayer / jumpgate / tests / jumpgate-tests / compute / test_servers.py View on Github external
'blockDeviceTemplateGroup':
                    {'publicFlag': 0,
                     'name': 'ajiang-jumpgate-sandbox-v1',
                     'userRecordId': 201260,
                     'createDate': '2014-05-10T20:36:51-06:00',
                     'statusId': 1,
                     'globalIdentifier':
                     '9b013d4e-27ce-4673-9607-ef863a88e3a8',
                     'parentId': '', 'transactionId': '', 'id': 141214,
                     'accountId': 333582},
                    'maxMemory': 2048,
                    'accountId': 333582}

        get_instance_mock.return_value = instance
        self.req = falcon.Request(self.env)
        self.resp = falcon.Response()
        instanceSV.on_get(self.req, self.resp, tenant_id, server_id)
github projectatomic / commissaire-mvp / test / test_authenticator_httpbasicauth.py View on Github external
"""
        Verify authenticate succeeds when cn matches, fails when it doesn't
        """
        self.expect_forbidden(data=self.cert, cn="other-cn")

        auth = httpauthclientcert.HTTPClientCertAuth(cn="system:master-proxy")
        req = falcon.Request(create_environ())
        req.env[SSL_CLIENT_VERIFY] = self.cert
        resp = falcon.Response()
        self.assertEqual(None, auth.authenticate(req, resp))

        # With no cn any is valid
        auth = httpauthclientcert.HTTPClientCertAuth()
        req = falcon.Request(create_environ())
        req.env[SSL_CLIENT_VERIFY] = self.cert
        resp = falcon.Response()
        self.assertEqual(None, auth.authenticate(req, resp))
github softlayer / jumpgate / tests / jumpgate-tests / network / test_subnet.py View on Github external
def test_on_get_response_subnetv2_invalid_id(self):
        """Test invalid id"""
        client, env = get_client_env()
        req = falcon.Request(env)
        resp = falcon.Response()

        subnets.SubnetV2().on_get(req, resp, 'BAD_ID')
        self.assertEquals(resp.status, 400)
github softlayer / jumpgate / tests / jumpgate-tests / network / test_network.py View on Github external
def test_on_get_response_networkv2_private(self):
        """Test working path of NetworkV2()"""

        client, env = get_client_env(query_string='name=123321')
        net_vlan = client['Network_Vlan']
        net_vlan.getObject.return_value = {'id': 11,
                                           'name': 'Public Network',
                                           'subnets': [{'id': 1},
                                                       {'id': 3},
                                                       {'id': 5}],
                                           'vlanNumber': 999,
                                           'networkSpace': 'PRIVATE'}
        req = falcon.Request(env)
        resp = falcon.Response()

        networks.NetworkV2().on_get(req, resp, 11)

        self.check_response_body(resp.body['network'])
        self.assertEqual(resp.status, 200)
        self.assertEqual(resp.body['network']['provider:physical_network'],
                         True)
github softlayer / jumpgate / tests / jumpgate-tests / compute / test_servers.py View on Github external
"maxCpu": 1, "metricPollDate": "",
             "createDate": "2014-06-23T14:44:27-05:00",
             "hostname": "testserver",
             "startCpus": 1,
             "lastPowerStateId": "",
             "lastVerifiedDate": "",
             "statusId": 1001,
             "globalIdentifier": "8bfd7c70-5ee4-4581-a2c1-6ae8986fc97a",
             "dedicatedAccountHostOnlyFlag": False,
             "modifyDate": '',
             "accountId": str(333582),
             "id": 5139276,
             "fullyQualifiedDomainName": "testserver2.jumpgate.com"}
        client, env = get_client_env(body=self.body_string)
        req = falcon.Request(env)
        resp = falcon.Response()
        self.instance.on_post(req, resp, 'tenant_id')
        self.assertEqual(resp.status, 202)
        self.assertEqual(resp.body['server']['id'], str(5139276))