Python falcon.HTTP_OK Examples

The following are 26 code examples of falcon.HTTP_OK(). 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 , or try the search function .
Example #1
Source File: test_middleware.py    From falcon-multipart with MIT License 6 votes vote down vote up
def test_with_binary_file(client):
    here = os.path.dirname(os.path.realpath(__file__))
    filepath = os.path.join(here, 'image.jpg')
    image = open(filepath, 'rb')

    class Resource:

        def on_post(self, req, resp, **kwargs):
            resp.data = req.get_param('afile').file.read()
            resp.content_type = 'image/jpg'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': image})
    assert resp.status == falcon.HTTP_OK
    image.seek(0)
    assert resp.body == image.read() 
Example #2
Source File: test_multipart.py    From paperboy with Apache License 2.0 6 votes vote down vote up
def test_parse_non_ascii_filename_in_headers(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('afile').file.read() == b'name,code\nnom,2\n'
            assert req.get_param('afile').filename == 'Na%C3%AFve%20file.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    # Simulate browser sending non ascii filename.
    body = ('--boundary\r\nContent-Disposition: '
            'form-data; name="afile"; filename*=utf-8\'\'Na%C3%AFve%20file.txt'
            '\r\nContent-Type: text/csv\r\n\r\nname,code\nnom,2\n\r\n'
            '--boundary--\r\n')
    headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
    resp = client.post('/route', body=body, headers=headers)
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #3
Source File: test_multipart.py    From paperboy with Apache License 2.0 6 votes vote down vote up
def test_with_binary_file(client):
    here = os.path.dirname(os.path.realpath(__file__))
    filepath = os.path.join(here, 'image.jpg')
    image = open(filepath, 'rb')

    class Resource:

        def on_post(self, req, resp, **kwargs):
            resp.data = req.get_param('afile').file.read()
            resp.content_type = 'image/jpg'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': image})
    assert resp.status == falcon.HTTP_OK
    image.seek(0)
    assert resp.body == image.read() 
Example #4
Source File: test_multipart.py    From paperboy with Apache License 2.0 6 votes vote down vote up
def test_parse_form_as_params(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('simple') == 'ok'
            assert req.get_param('afile').file.read() == b'filecontent'
            assert req.get_param('afile').filename == 'afile.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #5
Source File: test_middleware.py    From falcon-multipart with MIT License 6 votes vote down vote up
def test_parse_non_ascii_filename_in_headers(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('afile').file.read() == b'name,code\nnom,2\n'
            assert req.get_param('afile').filename == 'Na%C3%AFve%20file.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    # Simulate browser sending non ascii filename.
    body = ('--boundary\r\nContent-Disposition: '
            'form-data; name="afile"; filename*=utf-8\'\'Na%C3%AFve%20file.txt'
            '\r\nContent-Type: text/csv\r\n\r\nname,code\nnom,2\n\r\n'
            '--boundary--\r\n')
    headers = {'Content-Type': 'multipart/form-data; boundary=boundary'}
    resp = client.post('/route', body=body, headers=headers)
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #6
Source File: test_middleware.py    From falcon-multipart with MIT License 6 votes vote down vote up
def test_parse_form_as_params(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param('simple') == 'ok'
            assert req.get_param('afile').file.read() == b'filecontent'
            assert req.get_param('afile').filename == 'afile.txt'
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'simple': 'ok'},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #7
Source File: test_multipart.py    From paperboy with Apache License 2.0 5 votes vote down vote up
def test_parse_multiple_values(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param_as_list('multi') == ['1', '2']
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'multi': ['1', '2']},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #8
Source File: test_healthchecks.py    From monasca-log-api with Apache License 2.0 5 votes vote down vote up
def test_should_report_healthy_if_kafka_healthy(self, kafka_check):
        kafka_check.healthcheck.return_value = healthcheck.CheckResult(True,
                                                                       'OK')
        self.resource._kafka_check = kafka_check

        res = self.simulate_request(path=ENDPOINT,
                                    headers={
                                        'Content-Type': 'application/json'
                                    },
                                    method='GET')
        self.assertEqual(falcon.HTTP_OK, res.status)

        res = res.json
        self.assertIn('kafka', res)
        self.assertEqual('OK', res.get('kafka')) 
Example #9
Source File: test_healthchecks.py    From monasca-api with Apache License 2.0 5 votes vote down vote up
def test_should_report_healthy_if_all_services_healthy(self, kafka_check,
                                                           alarms_db_check,
                                                           metrics_db_check,
                                                           _):
        kafka_check.health_check.return_value = base.CheckResult(True, 'OK')
        alarms_db_check.health_check.return_value = base.CheckResult(True,
                                                                     'OK')
        metrics_db_check.health_check.return_value = base.CheckResult(True,
                                                                      'OK')
        self.resources._kafka_check = kafka_check
        self.resources._alarm_db_check = alarms_db_check
        self.resources._metrics_db_check = metrics_db_check

        response = self.simulate_request(path=ENDPOINT,
                                         headers={
                                             'Content-Type': 'application/json'
                                         },
                                         method='GET')
        self.assertEqual(falcon.HTTP_OK, response.status)

        response = response.json
        self.assertIn('kafka', response)
        self.assertIn('alarms_database', response)
        self.assertIn('metrics_database', response)
        self.assertEqual('OK', response.get('kafka'))
        self.assertEqual('OK', response.get('alarms_database'))
        self.assertEqual('OK', response.get('metrics_database')) 
Example #10
Source File: test_api.py    From poseidon with Apache License 2.0 5 votes vote down vote up
def test_network_full(client, redis_my):
    setup_redis()
    response = client.simulate_get('/v1/network_full')
    assert len(response.json) == 1
    assert response.status == falcon.HTTP_OK
    verify_endpoints(response) 
Example #11
Source File: test_api.py    From poseidon with Apache License 2.0 5 votes vote down vote up
def test_network(client, redis_my):
    setup_redis()
    response = client.simulate_get('/v1/network')
    assert len(response.json) == 2
    assert response.status == falcon.HTTP_OK
    verify_endpoints(response) 
Example #12
Source File: test_user.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_edit_user(client, user):
    doc = {"last_name": "changed"}
    with patch.object(UserMapper, "get", return_value=user):
        result = client.simulate_put("/users/".format(user.id), json=doc)

        assert result.status == falcon.HTTP_OK
        assert result.json["last_name"] == doc["last_name"]
        assert result.json["updated_at"] is not None 
Example #13
Source File: test_user.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_get_user(client, user):
    with patch.object(UserMapper, "get", return_value=user):
        result = client.simulate_get("/users/{}".format(user.id))

        assert result.status == falcon.HTTP_OK
        assert result.json["id"] == user.id.hex
        assert result.json["first_name"] == user.first_name
        assert result.json["last_name"] == user.last_name
        assert result.json["email"] == user.email 
Example #14
Source File: test_users.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_get_users(client):
    with patch.object(UserMapper, "get_all", return_value=[user1(), user2()]):
        result = client.simulate_get("/users")

        assert result.status == falcon.HTTP_OK
        assert len(result.json["users"]) == 2 
Example #15
Source File: test_hello.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_get_returns_hello_name(client):
    doc = {"message": "Hello, Bob!"}
    result = client.simulate_get("/hello/bob")

    assert result.status == falcon.HTTP_OK
    assert result.json == doc 
Example #16
Source File: test_root.py    From falcon-boilerplate with MIT License 5 votes vote down vote up
def test_get_welcome_message(client):
    doc = {"message": "Hello, World!"}
    result = client.simulate_get("/")

    assert result.status == falcon.HTTP_OK
    assert result.json == doc 
Example #17
Source File: servings.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, resp):
        response = list_servings(req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'OK', 'data': response}) 
Example #18
Source File: test_middleware.py    From falcon-multipart with MIT License 5 votes vote down vote up
def test_parse_multiple_values(client):

    class Resource:

        def on_post(self, req, resp, **kwargs):
            assert req.get_param_as_list('multi') == ['1', '2']
            resp.body = 'parsed'
            resp.content_type = 'text/plain'

    application.add_route('/route', Resource())

    resp = client.post('/route', data={'multi': ['1', '2']},
                       files={'afile': ('filecontent', 'afile.txt')})
    assert resp.status == falcon.HTTP_OK
    assert resp.body == 'parsed' 
Example #19
Source File: test_endpoints.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def test_endpoints_patch(mocker, client, functionality, method_name, body, expected_message,
                         expected_status):
    method_mock = mocker.patch('management_api.endpoints.endpoints.' + method_name)
    method_mock.return_value = "test"

    result = client.simulate_request(method='PATCH', path=f'/tenants/default/endpoints/test/'
                                                          f'{functionality}',
                                     headers={}, json=body)
    assert expected_status == result.status
    assert expected_message in result.text
    if result.status == falcon.HTTP_OK:
        method_mock.assert_called_once() 
Example #20
Source File: test_endpoints.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def test_endpoints_delete(mocker, client):
    delete_endpoint_mock = mocker.patch('management_api.endpoints.endpoints.delete_endpoint')
    delete_endpoint_mock.return_value = "test"
    expected_status = falcon.HTTP_OK
    expected_message = {"status": "DELETED", "data": {"url": "test"}}
    body = {'endpointName': 'test'}

    result = client.simulate_request(method='DELETE', path='/tenants/default/endpoints', headers={},
                                     json=body)
    assert expected_status == result.status
    assert expected_message == json.loads(result.text)
    delete_endpoint_mock.assert_called_once() 
Example #21
Source File: test_endpoints.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def test_endpoints_post(mocker, client, body, expected_message, expected_status,
                        model_availability):
    create_endpoint_mock = mocker.patch('management_api.endpoints.endpoints.create_endpoint')
    create_endpoint_mock.return_value = "test"
    check_model_mock = mocker.patch('management_api.endpoints.endpoints.check_endpoint_model')
    check_model_mock.return_value = model_availability

    result = client.simulate_request(method='POST', path='/tenants/default/endpoints', headers={},
                                     json=body)
    assert expected_status == result.status
    assert expected_message in result.text
    if not model_availability:
        assert "test model is not available on the platform" in result.text
    if result.status == falcon.HTTP_OK:
        create_endpoint_mock.assert_called_once() 
Example #22
Source File: test_models.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def test_models_delete(mocker, client):
    delete_model_mock = mocker.patch('management_api.models.models.delete_model')
    delete_model_mock.return_value = 'test'
    body = {'modelName': 'test', 'modelVersion': 1}
    expected_status = falcon.HTTP_OK

    result = client.simulate_request(method='DELETE', path='/tenants/default/models',
                                     headers={},
                                     json=body)

    assert expected_status == result.status
    delete_model_mock.assert_called_once() 
Example #23
Source File: test_authenticate.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def test_token_post(mocker, client, body, expected_status):
    get_token_mock = mocker.patch('management_api.authenticate.authenticate.get_token')
    get_token_mock.return_value = "test"
    result = client.simulate_request(method='POST', json=body, path='/authenticate/token')
    assert expected_status == result.status
    if expected_status is falcon.HTTP_OK:
        get_token_mock.assert_called_once()
        assert 'token' in result.text 
Example #24
Source File: models.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def on_delete(self, req, resp, tenant_name):
        """Handles DELETE requests"""
        namespace = tenant_name
        body = req.media
        response = delete_model(body, namespace, req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'DELETED', 'data': {'model_path': response}}) 
Example #25
Source File: models.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, resp, tenant_name):
        namespace = tenant_name
        response = list_models(namespace, req.params['Authorization'])
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'OK', 'data': {'models': response}}) 
Example #26
Source File: servings.py    From inference-model-manager with Apache License 2.0 5 votes vote down vote up
def on_get(self, req, resp, serving_name):
        response = get_serving(req.params['Authorization'], serving_name)
        resp.status = falcon.HTTP_OK
        resp.body = json.dumps({'status': 'OK', 'data': response})